MCPcopy
hub / github.com/prometheus/prometheus / metricMetadata

Method metricMetadata

web/api/v1/api.go:1465–1536  ·  view source on GitHub ↗
(r *http.Request)

Source from the content-addressed store, hash-verified

1463}
1464
1465func (api *API) metricMetadata(r *http.Request) apiFuncResult {
1466 metrics := map[string]map[metadata.Metadata]struct{}{}
1467
1468 limit := -1
1469 if s := r.FormValue("limit"); s != "" {
1470 var err error
1471 if limit, err = strconv.Atoi(s); err != nil {
1472 return apiFuncResult{nil, &apiError{errorBadData, errors.New("limit must be a number")}, nil, nil}
1473 }
1474 }
1475 limitPerMetric := -1
1476 if s := r.FormValue("limit_per_metric"); s != "" {
1477 var err error
1478 if limitPerMetric, err = strconv.Atoi(s); err != nil {
1479 return apiFuncResult{nil, &apiError{errorBadData, errors.New("limit_per_metric must be a number")}, nil, nil}
1480 }
1481 }
1482
1483 metric := r.FormValue("metric")
1484 for _, tt := range api.targetRetriever(r.Context()).TargetsActive() {
1485 for _, t := range tt {
1486 if metric == "" {
1487 for _, mm := range t.ListMetadata() {
1488 m := metadata.Metadata{Type: mm.Type, Help: mm.Help, Unit: mm.Unit}
1489 ms, ok := metrics[mm.MetricFamily]
1490
1491 if limitPerMetric > 0 && len(ms) >= limitPerMetric {
1492 continue
1493 }
1494
1495 if !ok {
1496 ms = map[metadata.Metadata]struct{}{}
1497 metrics[mm.MetricFamily] = ms
1498 }
1499 ms[m] = struct{}{}
1500 }
1501 continue
1502 }
1503
1504 if md, ok := t.GetMetadata(metric); ok {
1505 m := metadata.Metadata{Type: md.Type, Help: md.Help, Unit: md.Unit}
1506 ms, ok := metrics[md.MetricFamily]
1507
1508 if limitPerMetric > 0 && len(ms) >= limitPerMetric {
1509 continue
1510 }
1511
1512 if !ok {
1513 ms = map[metadata.Metadata]struct{}{}
1514 metrics[md.MetricFamily] = ms
1515 }
1516 ms[m] = struct{}{}
1517 }
1518 }
1519 }
1520
1521 // Put the elements from the pseudo-set into a slice for marshaling.
1522 res := map[string][]metadata.Metadata{}

Callers

nothing calls this directly

Calls 4

TargetsActiveMethod · 0.65
ListMetadataMethod · 0.65
GetMetadataMethod · 0.65
ContextMethod · 0.45

Tested by

no test coverage detected