Skip to content

Commit

Permalink
return label name/value list
Browse files Browse the repository at this point in the history
  • Loading branch information
mtanda committed Jun 13, 2018
1 parent 7d18733 commit a9af985
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,28 @@ func runQuery(indexer *Indexer, archiver *Archiver, q *prompb.Query, lookbackDel
matchers = append(matchers, m)
}
q.Matchers = matchers

// return label name/value list for query editor
if namespace == "" {
level.Debug(logger).Log("msg", "namespace is required")
m, err := fromLabelMatchers(q.Matchers)
if err != nil {
return result.slice()
}
matchedLabelsList, err := indexer.getMatchedLables(m, q.StartTimestampMs, q.EndTimestampMs)
if err != nil {
return result.slice()
}
for i, matchedLabels := range matchedLabelsList {
ts := &prompb.TimeSeries{}
for _, label := range matchedLabels {
ts.Labels = append(ts.Labels, &prompb.Label{Name: label.Name, Value: label.Value})
}
ts.Labels = append(ts.Labels, &prompb.Label{Name: "job", Value: originalJobLabel})
t := time.Unix(int64(q.EndTimestampMs/1000), int64(q.EndTimestampMs%1000*1000))
ts.Samples = append(ts.Samples, &prompb.Sample{Value: 0, Timestamp: t.Unix() * 1000})
result[string(i)] = ts
}
//level.Debug(logger).Log("msg", "namespace is required")
return result.slice()
}

Expand Down

0 comments on commit a9af985

Please sign in to comment.