Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions google/export/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,22 @@ func TestExporter_wrapMetadata(t *testing.T) {
Help: "useful help",
},
wantOK: true,
}, {
desc: "info metadata is returned as is",
mf: func(string) (MetricMetadata, bool) {
return MetricMetadata{
Metric: "some_info_metric",
Type: model.MetricTypeInfo,
Help: "info help",
}, true
},
metric: "some_info_metric",
want: MetricMetadata{
Metric: "some_info_metric",
Type: model.MetricTypeInfo,
Help: "info help",
},
wantOK: true,
}, {
desc: "not found metadata defaults to untyped",
mf: func(string) (MetricMetadata, bool) {
Expand Down
8 changes: 8 additions & 0 deletions google/export/series_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ func (c *seriesCache) populate(ref storage.SeriesRef, entry *seriesCacheEntry, e
metric_pb.MetricDescriptor_DOUBLE,
)

case model.MetricTypeInfo:
protos.gauge = newSeries(
c.getMetricType(metricName, gcmMetricSuffixGauge, gcmMetricSuffixNone),
metadata.Help,
metric_pb.MetricDescriptor_GAUGE,
metric_pb.MetricDescriptor_DOUBLE,
)

case model.MetricTypeUnknown:
protos.gauge = newSeries(
c.getMetricType(metricName, gcmMetricSuffixUnknown, gcmMetricSuffixNone),
Expand Down
62 changes: 62 additions & 0 deletions google/export/series_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,75 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/storage"
"github.com/prometheus/prometheus/tsdb/record"
metric_pb "google.golang.org/genproto/googleapis/api/metric"
monitoredres_pb "google.golang.org/genproto/googleapis/api/monitoredres"
"google.golang.org/protobuf/testing/protocmp"
)

func TestSeriesCache_populate_Info(t *testing.T) {
cache := newSeriesCache(nil, nil, MetricTypePrefix)

// Mock getLabelsByRef to return labels for our info metric.
ref := storage.SeriesRef(1)
metricName := "test_info"
lset := labels.FromStrings("__name__", metricName, "job", "test_job", "instance", "test_instance", "version", "1.2.3")
cache.getLabelsByRef = func(r storage.SeriesRef) labels.Labels {
if r == ref {
return lset
}
return labels.EmptyLabels()
}

// Prepare entry.
entry := &seriesCacheEntry{}

// Metadata function returning Info type.
mdFunc := func(m string) (MetricMetadata, bool) {
if m == metricName {
return MetricMetadata{
Metric: metricName,
Type: model.MetricTypeInfo,
Help: "info help",
}, true
}
return MetricMetadata{}, false
}

// Populate cache. Provide required external labels (project_id, location).
externalLabels := labels.FromStrings("project_id", "my-project", "location", "us-central1")
err := cache.populate(ref, entry, externalLabels, mdFunc)
if err != nil {
t.Fatalf("populate failed: %v", err)
}

if entry.protos.gauge.proto == nil {
t.Fatal("expected gauge proto to be populated for Info metric")
}
if entry.protos.cumulative.proto != nil {
t.Error("expected cumulative proto to be nil for Info metric")
}

p := entry.protos.gauge.proto

if p.MetricKind != metric_pb.MetricDescriptor_GAUGE {
t.Errorf("expected MetricKind GAUGE, got %v", p.MetricKind)
}
if p.ValueType != metric_pb.MetricDescriptor_DOUBLE {
t.Errorf("expected ValueType DOUBLE, got %v", p.ValueType)
}
expectedType := "prometheus.googleapis.com/test_info/gauge"
if p.Metric.Type != expectedType {
t.Errorf("expected Metric Type %q, got %q", expectedType, p.Metric.Type)
}
if p.Description != "info help" {
t.Errorf("expected Description 'info help', got %q", p.Description)
}
}

func TestExtractResource(t *testing.T) {
cases := []struct {
doc string
Expand Down
41 changes: 41 additions & 0 deletions google/export/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,47 @@ func TestSampleBuilder(t *testing.T) {
}},
},
},
}, {
doc: "convert info metric",
metadata: testMetadataFunc(metricMetadataMap{
"metric1_info": {Type: model.MetricTypeInfo, Help: "metric1_info help text"},
}),
series: seriesMap{
123: labels.FromStrings("job", "job1", "instance", "instance1", "__name__", "metric1_info", "version", "1.2.3"),
},
samples: [][]record.RefSample{
{{Ref: 123, T: 3000, V: 1}},
},
wantSeries: []*monitoring_pb.TimeSeries{
{
Resource: &monitoredres_pb.MonitoredResource{
Type: "prometheus_target",
Labels: map[string]string{
"project_id": "example-project",
"location": "europe",
"cluster": "foo-cluster",
"namespace": "",
"job": "job1",
"instance": "instance1",
},
},
Metric: &metric_pb.Metric{
Type: "prometheus.googleapis.com/metric1_info/gauge",
Labels: map[string]string{"version": "1.2.3"},
},
Description: "metric1_info help text",
MetricKind: metric_pb.MetricDescriptor_GAUGE,
ValueType: metric_pb.MetricDescriptor_DOUBLE,
Points: []*monitoring_pb.Point{{
Interval: &monitoring_pb.TimeInterval{
EndTime: &timestamp_pb.Timestamp{Seconds: 3},
},
Value: &monitoring_pb.TypedValue{
Value: &monitoring_pb.TypedValue_DoubleValue{DoubleValue: 1},
},
}},
},
},
}, {
doc: "convert untyped",
metadata: testMetadataFunc(metricMetadataMap{
Expand Down