MCPcopy
hub / github.com/prometheus/prometheus / labelNames

Method labelNames

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

Source from the content-addressed store, hash-verified

773}
774
775func (api *API) labelNames(r *http.Request) apiFuncResult {
776 limit, err := parseLimitParam(r.FormValue("limit"))
777 if err != nil {
778 return invalidParamError(err, "limit")
779 }
780
781 start, err := parseTimeParam(r, "start", MinTime)
782 if err != nil {
783 return invalidParamError(err, "start")
784 }
785 end, err := parseTimeParam(r, "end", MaxTime)
786 if err != nil {
787 return invalidParamError(err, "end")
788 }
789
790 matcherSets, err := api.parseMatchersParam(r.Form["match[]"])
791 if err != nil {
792 return apiFuncResult{nil, &apiError{errorBadData, err}, nil, nil}
793 }
794
795 hints := &storage.LabelHints{
796 Limit: toHintLimit(limit),
797 }
798
799 q, err := api.Queryable.Querier(timestamp.FromTime(start), timestamp.FromTime(end))
800 if err != nil {
801 return apiFuncResult{nil, returnAPIError(err), nil, nil}
802 }
803 defer q.Close()
804
805 var (
806 names []string
807 warnings annotations.Annotations
808 )
809 if len(matcherSets) > 1 {
810 labelNamesSet := make(map[string]struct{})
811
812 for _, matchers := range matcherSets {
813 vals, callWarnings, err := q.LabelNames(r.Context(), hints, matchers...)
814 if err != nil {
815 return apiFuncResult{nil, returnAPIError(err), warnings, nil}
816 }
817
818 warnings.Merge(callWarnings)
819 for _, val := range vals {
820 labelNamesSet[val] = struct{}{}
821 }
822 }
823
824 // Convert the map to an array.
825 names = make([]string, 0, len(labelNamesSet))
826 for key := range labelNamesSet {
827 names = append(names, key)
828 }
829 slices.Sort(names)
830 } else {
831 var matchers []*labels.Matcher
832 if len(matcherSets) == 1 {

Callers

nothing calls this directly

Calls 14

parseMatchersParamMethod · 0.95
FromTimeFunction · 0.92
parseLimitParamFunction · 0.85
invalidParamErrorFunction · 0.85
parseTimeParamFunction · 0.85
toHintLimitFunction · 0.85
returnAPIErrorFunction · 0.85
QuerierMethod · 0.65
CloseMethod · 0.65
LabelNamesMethod · 0.65
MergeMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected