mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Change GetAllMetricNames() to GetAllValuesForLabel().
This commit is contained in:
parent
42bdf921d1
commit
dd67ab115b
|
@ -52,7 +52,7 @@ type MetricPersistence interface {
|
||||||
|
|
||||||
ForEachSample(IteratorsForFingerprintBuilder) (err error)
|
ForEachSample(IteratorsForFingerprintBuilder) (err error)
|
||||||
|
|
||||||
GetAllMetricNames() ([]string, error)
|
GetAllValuesForLabel(model.LabelName) (model.LabelValues, error)
|
||||||
|
|
||||||
// Requests the storage stack to build a materialized View of the values
|
// Requests the storage stack to build a materialized View of the values
|
||||||
// contained therein.
|
// contained therein.
|
||||||
|
|
|
@ -1236,35 +1236,40 @@ func (d *MetricKeyDecoder) DecodeValue(in interface{}) (out interface{}, err err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetricNamesFilter struct{}
|
type LabelNameFilter struct {
|
||||||
|
labelName model.LabelName
|
||||||
|
}
|
||||||
|
|
||||||
func (f *MetricNamesFilter) Filter(key, value interface{}) (filterResult storage.FilterResult) {
|
func (f *LabelNameFilter) Filter(key, value interface{}) (filterResult storage.FilterResult) {
|
||||||
unmarshaled, ok := key.(*dto.LabelPair)
|
unmarshaled, ok := key.(*dto.LabelPair)
|
||||||
if ok && *unmarshaled.Name == "name" {
|
if ok && model.LabelName(*unmarshaled.Name) == f.labelName {
|
||||||
return storage.ACCEPT
|
return storage.ACCEPT
|
||||||
}
|
}
|
||||||
return storage.SKIP
|
return storage.SKIP
|
||||||
}
|
}
|
||||||
|
|
||||||
type CollectMetricNamesOp struct {
|
type CollectLabelValuesOp struct {
|
||||||
metricNames []string
|
labelValues []model.LabelValue
|
||||||
}
|
}
|
||||||
|
|
||||||
func (op *CollectMetricNamesOp) Operate(key, value interface{}) (err *storage.OperatorError) {
|
func (op *CollectLabelValuesOp) Operate(key, value interface{}) (err *storage.OperatorError) {
|
||||||
unmarshaled := key.(*dto.LabelPair)
|
unmarshaled := key.(*dto.LabelPair)
|
||||||
op.metricNames = append(op.metricNames, *unmarshaled.Value)
|
op.labelValues = append(op.labelValues, model.LabelValue(*unmarshaled.Value))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *LevelDBMetricPersistence) GetAllMetricNames() (metricNames []string, err error) {
|
func (l *LevelDBMetricPersistence) GetAllValuesForLabel(labelName model.LabelName) (values model.LabelValues, err error) {
|
||||||
metricNamesOp := &CollectMetricNamesOp{}
|
filter := &LabelNameFilter{
|
||||||
|
labelName: labelName,
|
||||||
|
}
|
||||||
|
labelValuesOp := &CollectLabelValuesOp{}
|
||||||
|
|
||||||
_, err = l.labelSetToFingerprints.ForEach(&MetricKeyDecoder{}, &MetricNamesFilter{}, metricNamesOp)
|
_, err = l.labelSetToFingerprints.ForEach(&MetricKeyDecoder{}, filter, labelValuesOp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
metricNames = metricNamesOp.metricNames
|
values = labelValuesOp.labelValues
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -348,19 +348,17 @@ func (s memorySeriesStorage) Close() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s memorySeriesStorage) GetAllMetricNames() (metrics []string, err error) {
|
func (s memorySeriesStorage) GetAllValuesForLabel(labelName model.LabelName) (values model.LabelValues, err error) {
|
||||||
metricSet := map[string]bool{}
|
valueSet := map[model.LabelValue]bool{}
|
||||||
for _, series := range s.fingerprintToSeries {
|
for _, series := range s.fingerprintToSeries {
|
||||||
if metricName, ok := series.metric["name"]; !ok {
|
if value, ok := series.metric[labelName]; ok {
|
||||||
err = fmt.Errorf("Found timeseries without metric name label: %v", series.metric)
|
valueSet[value] = true
|
||||||
} else {
|
|
||||||
metricSet[string(metricName)] = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for metricName := range metricSet {
|
for value := range valueSet {
|
||||||
metrics = append(metrics, metricName)
|
values = append(values, value)
|
||||||
}
|
}
|
||||||
sort.Strings(metrics)
|
sort.Sort(values)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ type Storage interface {
|
||||||
Close()
|
Close()
|
||||||
|
|
||||||
// MetricPersistence proxy methods.
|
// MetricPersistence proxy methods.
|
||||||
GetAllMetricNames() ([]string, error)
|
GetAllValuesForLabel(model.LabelName) (model.LabelValues, error)
|
||||||
GetFingerprintsForLabelSet(model.LabelSet) (model.Fingerprints, error)
|
GetFingerprintsForLabelSet(model.LabelSet) (model.Fingerprints, error)
|
||||||
GetMetricForFingerprint(model.Fingerprint) (m *model.Metric, err error)
|
GetMetricForFingerprint(model.Fingerprint) (m *model.Metric, err error)
|
||||||
}
|
}
|
||||||
|
@ -518,24 +518,24 @@ func (t *tieredStorage) loadChunkAroundTime(iterator leveldb.Iterator, frontier
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tieredStorage) GetAllMetricNames() (metrics []string, err error) {
|
func (t *tieredStorage) GetAllValuesForLabel(labelName model.LabelName) (values model.LabelValues, err error) {
|
||||||
diskMetrics, err := t.diskStorage.GetAllMetricNames()
|
diskValues, err := t.diskStorage.GetAllValuesForLabel(labelName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
memoryMetrics, err := t.memoryArena.GetAllMetricNames()
|
memoryValues, err := t.memoryArena.GetAllValuesForLabel(labelName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
metricSet := map[string]bool{}
|
valueSet := map[model.LabelValue]bool{}
|
||||||
for _, metricName := range append(diskMetrics, memoryMetrics...) {
|
for _, value := range append(diskValues, memoryValues...) {
|
||||||
metricSet[metricName] = true
|
valueSet[value] = true
|
||||||
}
|
}
|
||||||
for metricName := range metricSet {
|
for value := range valueSet {
|
||||||
metrics = append(metrics, metricName)
|
values = append(values, value)
|
||||||
}
|
}
|
||||||
sort.Strings(metrics)
|
sort.Sort(values)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,7 +431,7 @@ func BenchmarkMakeView(b *testing.B) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAllMetricNames(t *testing.T) {
|
func TestGetAllValuesForLabel(t *testing.T) {
|
||||||
type in struct {
|
type in struct {
|
||||||
metricName string
|
metricName string
|
||||||
appendToMemory bool
|
appendToMemory bool
|
||||||
|
@ -510,7 +510,7 @@ func TestGetAllMetricNames(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
metricNames, err := tiered.GetAllMetricNames()
|
metricNames, err := tiered.GetAllValuesForLabel("name")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("%d. Error getting metric names: %s", i, err)
|
t.Fatalf("%d. Error getting metric names: %s", i, err)
|
||||||
}
|
}
|
||||||
|
@ -519,7 +519,7 @@ func TestGetAllMetricNames(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for j, expected := range scenario.out {
|
for j, expected := range scenario.out {
|
||||||
if expected != metricNames[j] {
|
if expected != string(metricNames[j]) {
|
||||||
t.Fatalf("%d.%d. Expected metric %s, got %s", i, j, expected, metricNames[j])
|
t.Fatalf("%d.%d. Expected metric %s, got %s", i, j, expected, metricNames[j])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ func (serv MetricsService) QueryRange(expr string, end int64, duration int64, st
|
||||||
}
|
}
|
||||||
|
|
||||||
func (serv MetricsService) Metrics() string {
|
func (serv MetricsService) Metrics() string {
|
||||||
metricNames, err := serv.appState.Storage.GetAllMetricNames()
|
metricNames, err := serv.appState.Storage.GetAllValuesForLabel("name")
|
||||||
rb := serv.ResponseBuilder()
|
rb := serv.ResponseBuilder()
|
||||||
rb.SetContentType(gorest.Application_Json)
|
rb.SetContentType(gorest.Application_Json)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -94,7 +94,7 @@ func (serv MetricsService) Metrics() string {
|
||||||
rb.SetResponseCode(http.StatusInternalServerError)
|
rb.SetResponseCode(http.StatusInternalServerError)
|
||||||
return err.Error()
|
return err.Error()
|
||||||
}
|
}
|
||||||
sort.Strings(metricNames)
|
sort.Sort(metricNames)
|
||||||
resultBytes, err := json.Marshal(metricNames)
|
resultBytes, err := json.Marshal(metricNames)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error marshalling metric names: %v", err)
|
log.Printf("Error marshalling metric names: %v", err)
|
||||||
|
|
Loading…
Reference in a new issue