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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ can be used as a reference for setup:

The matrix below lists the versions of Prometheus Server and other dependencies that have been qualified to work with releases of `stackdriver-prometheus-sidecar`.

| sidecar version | prometheus version |
| --- | --- |
| 0.2.x | 2.4.3 |
| sidecar version | **Prometheus 2.4.3** | **Prometheus 2.5.x** |
|------------|------------------|-------------------|
| **0.2.x** | ✓ | - |
| **master** | ✓ | ✓ |

## Source Code Headers

Expand Down
7 changes: 5 additions & 2 deletions cmd/stackdriver-prometheus-sidecar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,11 @@ func parseConfigFile(filename string) (map[string]string, []scrape.MetricMetadat
var staticMetadata []scrape.MetricMetadata
for _, sm := range fc.StaticMetadata {
switch sm.Type {
case textparse.MetricTypeCounter, textparse.MetricTypeGauge,
textparse.MetricTypeHistogram, textparse.MetricTypeSummary, textparse.MetricTypeUntyped:
case metadata.MetricTypeUntyped:
// Convert "untyped" to the "unknown" type used internally as of Prometheus 2.5.
sm.Type = textparse.MetricTypeUnknown
case textparse.MetricTypeCounter, textparse.MetricTypeGauge, textparse.MetricTypeHistogram,
textparse.MetricTypeSummary, textparse.MetricTypeUnknown:
default:
return nil, nil, errors.Errorf("invalid metric type %q", sm.Type)
}
Expand Down
12 changes: 12 additions & 0 deletions metadata/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type Cache struct {
// the target metadata endpoint.
const DefaultEndpointPath = "/api/v1/targets/metadata"

// The old metric type value for textparse.MetricTypeUnknown that is used in
// Prometheus 2.4 and earlier.
const MetricTypeUntyped = "untyped"

// NewCache returns a new cache that gets populated by the metadata endpoint
// at the given URL.
// It uses the default endpoint path if no specific path is provided.
Expand Down Expand Up @@ -176,6 +180,10 @@ func (c *Cache) fetchMetric(ctx context.Context, job, instance, metric string) (
}
d := apiResp.Data[0]

// Convert legacy "untyped" type used before Prometheus 2.5.
if d.Type == MetricTypeUntyped {
d.Type = textparse.MetricTypeUnknown
}
return &metadataEntry{
MetricMetadata: scrape.MetricMetadata{
Metric: metric,
Expand Down Expand Up @@ -212,6 +220,10 @@ func (c *Cache) fetchBatch(ctx context.Context, job, instance string) (map[strin
result := make(map[string]*metadataEntry, len(apiResp.Data)+len(internalMetrics))

for _, md := range apiResp.Data {
// Convert legacy "untyped" type used before Prometheus 2.5.
if md.Type == MetricTypeUntyped {
md.Type = textparse.MetricTypeUnknown
}
result[md.Metric] = &metadataEntry{
MetricMetadata: scrape.MetricMetadata{
Metric: md.Metric,
Expand Down
19 changes: 18 additions & 1 deletion metadata/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func TestCache_Get(t *testing.T) {
{Metric: "metric2", Type: textparse.MetricTypeGauge, Help: "help_metric2"},
{Metric: "metric3", Type: textparse.MetricTypeHistogram, Help: "help_metric3"},
{Metric: "metric4", Type: textparse.MetricTypeSummary, Help: "help_metric4"},
{Metric: "metric5", Type: textparse.MetricTypeUntyped, Help: "help_metric5"},
{Metric: "metric5", Type: textparse.MetricTypeUnknown, Help: "help_metric5"},
{Metric: "metric6", Type: MetricTypeUntyped, Help: "help_metric6"},
}
var handler func(qMetric, qMatch string) *apiResponse

Expand Down Expand Up @@ -129,6 +130,22 @@ func TestCache_Get(t *testing.T) {
}
expect(metrics[4], md)

// Test "untyped" metric type from Prometheus 2.4.
handler = func(qMetric, qMatch string) *apiResponse {
if qMetric != "metric6" {
t.Fatalf("unexpected metric %q in request", qMetric)
}
if qMatch != `{job="prometheus",instance="localhost:9090"}` {
t.Fatalf("unexpected matcher %q in request", qMatch)
}
return &apiResponse{Status: "success", Data: metrics[5:6]}
}
md, err = c.Get(ctx, "prometheus", "localhost:9090", "metric6")
if err != nil {
t.Fatal(err)
}
expect(apiMetadata{Metric: "metric6", Type: textparse.MetricTypeUnknown, Help: "help_metric6"}, md)

// The scrape layer's metrics should not fire off requests.
md, err = c.Get(ctx, "prometheus", "localhost:9090", "up")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion retrieval/series_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ func (c *seriesCache) refresh(ctx context.Context, ref uint64) error {
case textparse.MetricTypeCounter:
ts.MetricKind = metric_pb.MetricDescriptor_CUMULATIVE
ts.ValueType = metric_pb.MetricDescriptor_DOUBLE
case textparse.MetricTypeGauge, textparse.MetricTypeUntyped:
case textparse.MetricTypeGauge, textparse.MetricTypeUnknown:
ts.MetricKind = metric_pb.MetricDescriptor_GAUGE
ts.ValueType = metric_pb.MetricDescriptor_DOUBLE
case textparse.MetricTypeSummary:
Expand Down
2 changes: 1 addition & 1 deletion retrieval/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (b *sampleBuilder) next(ctx context.Context, samples []tsdb.RefSample) (*mo
point.Interval.StartTime = getTimestamp(resetTimestamp)
point.Value = &monitoring_pb.TypedValue{&monitoring_pb.TypedValue_DoubleValue{v}}

case textparse.MetricTypeGauge, textparse.MetricTypeUntyped:
case textparse.MetricTypeGauge, textparse.MetricTypeUnknown:
point.Value = &monitoring_pb.TypedValue{&monitoring_pb.TypedValue_DoubleValue{sample.V}}

case textparse.MetricTypeSummary:
Expand Down
2 changes: 1 addition & 1 deletion retrieval/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestSampleBuilder(t *testing.T) {
metadata: metadataMap{
"job1/instance1/metric1": &scrape.MetricMetadata{Type: textparse.MetricTypeGauge, Metric: "metric1"},
"job1/instance1/metric2": &scrape.MetricMetadata{Type: textparse.MetricTypeCounter, Metric: "metric2"},
"job1/instance1/labelnum_ok": &scrape.MetricMetadata{Type: textparse.MetricTypeUntyped, Metric: "labelnum_ok"},
"job1/instance1/labelnum_ok": &scrape.MetricMetadata{Type: textparse.MetricTypeUnknown, Metric: "labelnum_ok"},
"job1/instance1/labelnum_bad": &scrape.MetricMetadata{Type: textparse.MetricTypeGauge, Metric: "labelnum_bad"},
},
input: []tsdb.RefSample{
Expand Down
Binary file not shown.
91 changes: 91 additions & 0 deletions vendor/github.com/prometheus/prometheus/pkg/textparse/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading