Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[prometheusreceiver] keep instance and job label #1

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 2 additions & 0 deletions receiver/prometheusreceiver/internal/metricsbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,11 @@ func isUsefulLabel(mType metricspb.MetricDescriptor_Type, labelKey string) bool
switch labelKey {
case model.MetricNameLabel:
case model.InstanceLabel:
result = true
case model.SchemeLabel:
case model.MetricsPathLabel:
case model.JobLabel:
result = true
case model.BucketLabel:
result = mType != metricspb.MetricDescriptor_GAUGE_DISTRIBUTION &&
mType != metricspb.MetricDescriptor_CUMULATIVE_DISTRIBUTION
Expand Down
4 changes: 2 additions & 2 deletions receiver/prometheusreceiver/internal/metricsbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,10 +1184,10 @@ func Test_isUsefulLabel(t *testing.T) {
want bool
}{
{"metricName", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.MetricNameLabel}, false},
{"instance", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.InstanceLabel}, false},
{"instance", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.InstanceLabel}, true},
{"scheme", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.SchemeLabel}, false},
{"metricPath", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.MetricsPathLabel}, false},
{"job", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.JobLabel}, false},
{"job", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.JobLabel}, true},
{"bucket", args{metricspb.MetricDescriptor_GAUGE_DOUBLE, model.BucketLabel}, true},
{"bucketForGaugeDistribution", args{metricspb.MetricDescriptor_GAUGE_DISTRIBUTION, model.BucketLabel}, false},
{"bucketForCumulativeDistribution", args{metricspb.MetricDescriptor_CUMULATIVE_DISTRIBUTION, model.BucketLabel}, false},
Expand Down
113 changes: 104 additions & 9 deletions receiver/prometheusreceiver/metrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,21 @@ func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
t.Errorf("want 1, but got %v\n", l)
}

instance := fmt.Sprintf("%s:%s", m1.Node.Identifier.HostName, m1.Resource.Labels["port"])
// only gauge value is returned from the first scrape
wantG1 := &metricspb.Metric{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Value: &metricspb.Point_DoubleValue{DoubleValue: 19.0}},
},
Expand All @@ -289,9 +295,15 @@ func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE},
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Timestamp: ts2, Value: &metricspb.Point_DoubleValue{DoubleValue: 18.0}},
},
Expand All @@ -303,13 +315,15 @@ func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "http_requests_total",
Description: "The total number of HTTP requests.",
Type: metricspb.MetricDescriptor_CUMULATIVE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "method"}},
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "instance"}, {Key: "job"}, {Key: "method"}},
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: "200", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -320,6 +334,8 @@ func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: "400", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -332,12 +348,17 @@ func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "http_request_duration_seconds",
Type: metricspb.MetricDescriptor_CUMULATIVE_DISTRIBUTION,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
Description: "A histogram of the request duration.",
Unit: "s",
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{
Timestamp: ts2,
Expand Down Expand Up @@ -368,12 +389,17 @@ func verifyTarget1(t *testing.T, td *testData, mds []internaldata.MetricsData) {
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "rpc_duration_seconds",
Type: metricspb.MetricDescriptor_SUMMARY,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
Description: "A summary of the RPC duration in seconds.",
Unit: "s",
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{
Timestamp: ts2,
Expand Down Expand Up @@ -482,15 +508,22 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
t.Errorf("want 1, but got %v\n", l)
}

instance := fmt.Sprintf("%s:%s", m1.Node.Identifier.HostName, m1.Resource.Labels["port"])

// only gauge value is returned from the first scrape
wantG1 := &metricspb.Metric{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "go_threads",
Description: "Number of OS threads created",
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Value: &metricspb.Point_DoubleValue{DoubleValue: 18.0}},
},
Expand All @@ -516,9 +549,14 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Timestamp: ts2, Value: &metricspb.Point_DoubleValue{DoubleValue: 16.0}},
},
Expand All @@ -530,13 +568,15 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "http_requests_total",
Description: "The total number of HTTP requests.",
Type: metricspb.MetricDescriptor_CUMULATIVE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "method"}},
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "instance"}, {Key: "job"}, {Key: "method"}},
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: "200", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -547,6 +587,8 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: "400", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -573,9 +615,14 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Timestamp: ts3, Value: &metricspb.Point_DoubleValue{DoubleValue: 16.0}},
},
Expand All @@ -587,13 +634,15 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "http_requests_total",
Description: "The total number of HTTP requests.",
Type: metricspb.MetricDescriptor_CUMULATIVE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "method"}},
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "instance"}, {Key: "job"}, {Key: "method"}},
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: "200", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -604,6 +653,8 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: "400", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -614,6 +665,8 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
StartTimestamp: ts2,
LabelValues: []*metricspb.LabelValue{
{Value: "500", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -639,9 +692,14 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Timestamp: ts4, Value: &metricspb.Point_DoubleValue{DoubleValue: 16.0}},
},
Expand All @@ -666,9 +724,14 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Timestamp: ts5, Value: &metricspb.Point_DoubleValue{DoubleValue: 16.0}},
},
Expand All @@ -680,13 +743,15 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "http_requests_total",
Description: "The total number of HTTP requests.",
Type: metricspb.MetricDescriptor_CUMULATIVE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "method"}},
LabelKeys: []*metricspb.LabelKey{{Key: "code"}, {Key: "instance"}, {Key: "job"}, {Key: "method"}},
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts4,
LabelValues: []*metricspb.LabelValue{
{Value: "200", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -697,6 +762,8 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
StartTimestamp: ts4,
LabelValues: []*metricspb.LabelValue{
{Value: "400", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand All @@ -707,6 +774,8 @@ func verifyTarget2(t *testing.T, td *testData, mds []internaldata.MetricsData) {
StartTimestamp: ts4,
LabelValues: []*metricspb.LabelValue{
{Value: "500", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
{Value: "post", HasValue: true},
},
Points: []*metricspb.Point{
Expand Down Expand Up @@ -800,14 +869,22 @@ func verifyTarget3(t *testing.T, td *testData, mds []internaldata.MetricsData) {
t.Errorf("want 1, but got %v\n", l)
}

instance := fmt.Sprintf("%s:%s", m1.Node.Identifier.HostName, m1.Resource.Labels["port"])

// only gauge value is returned from the first scrape
wantG1 := &metricspb.Metric{
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE},
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Value: &metricspb.Point_DoubleValue{DoubleValue: 18.0}},
},
Expand All @@ -833,9 +910,14 @@ func verifyTarget3(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Name: "go_threads",
Description: "Number of OS threads created",
Type: metricspb.MetricDescriptor_GAUGE_DOUBLE,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{Timestamp: ts2, Value: &metricspb.Point_DoubleValue{DoubleValue: 16.0}},
},
Expand All @@ -848,10 +930,15 @@ func verifyTarget3(t *testing.T, td *testData, mds []internaldata.MetricsData) {
Description: "A histogram of the request duration.",
Unit: "s",
Type: metricspb.MetricDescriptor_CUMULATIVE_DISTRIBUTION,
LabelKeys: []*metricspb.LabelKey{{Key: "instance"}, {Key: "job"}},
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{
Timestamp: ts2,
Expand Down Expand Up @@ -883,14 +970,18 @@ func verifyTarget3(t *testing.T, td *testData, mds []internaldata.MetricsData) {
MetricDescriptor: &metricspb.MetricDescriptor{
Name: "rpc_duration_seconds",
Type: metricspb.MetricDescriptor_SUMMARY,
LabelKeys: []*metricspb.LabelKey{{Key: "foo"}},
LabelKeys: []*metricspb.LabelKey{{Key: "foo"}, {Key: "instance"}, {Key: "job"}},
Description: "A summary of the RPC duration in seconds.",
Unit: "s",
},
Timeseries: []*metricspb.TimeSeries{
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{{Value: "bar", HasValue: true}},
LabelValues: []*metricspb.LabelValue{
{Value: "bar", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{
Timestamp: ts2,
Expand Down Expand Up @@ -929,7 +1020,11 @@ func verifyTarget3(t *testing.T, td *testData, mds []internaldata.MetricsData) {
},
{
StartTimestamp: ts1,
LabelValues: []*metricspb.LabelValue{{Value: "no_quantile", HasValue: true}},
LabelValues: []*metricspb.LabelValue{
{Value: "no_quantile", HasValue: true},
{Value: instance, HasValue: true},
{Value: td.name, HasValue: true},
},
Points: []*metricspb.Point{
{
Timestamp: ts2,
Expand Down