From 617c56f55a14b7f6ed4f0f4402c1e18aaf3b396c Mon Sep 17 00:00:00 2001 From: fcddk <50894443+fcddk@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:30:30 +0800 Subject: [PATCH 1/5] add endponits labels metadata add endponits labels metadata Signed-off-by: root --- discovery/kubernetes/endpoints.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index f905ae92cc..183c729ab9 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -199,6 +199,8 @@ func endpointsSourceFromNamespaceAndName(namespace, name string) string { } const ( + endpointsLabelPrefix = metaLabelPrefix + "endpoints_label_" + endpointsLabelPresentPrefix = metaLabelPrefix + "endpoints_labelpresent_" endpointsNameLabel = metaLabelPrefix + "endpoints_name" endpointNodeName = metaLabelPrefix + "endpoint_node_name" endpointHostname = metaLabelPrefix + "endpoint_hostname" @@ -218,6 +220,12 @@ func (e *Endpoints) buildEndpoints(eps *apiv1.Endpoints) *targetgroup.Group { endpointsNameLabel: lv(eps.Name), } e.addServiceLabels(eps.Namespace, eps.Name, tg) + //add endponits labels metadata + for k, v := range eps.Labels { + ln := strutil.SanitizeLabelName(k) + tg.Labels[model.LabelName(endpointsLabelPrefix+ln)] = lv(v) + tg.Labels[model.LabelName(endpointsLabelPresentPrefix+ln)] = presentValue + } type podEntry struct { pod *apiv1.Pod From b270a1d6bf13162e952e2912032a1090ae92bef1 Mon Sep 17 00:00:00 2001 From: fcddk <50894443+fcddk@users.noreply.github.com> Date: Wed, 16 Dec 2020 16:25:25 +0800 Subject: [PATCH 2/5] import strutil package import strutil package Signed-off-by: root --- discovery/kubernetes/endpoints.go | 1 + 1 file changed, 1 insertion(+) diff --git a/discovery/kubernetes/endpoints.go b/discovery/kubernetes/endpoints.go index 183c729ab9..c60bf3543b 100644 --- a/discovery/kubernetes/endpoints.go +++ b/discovery/kubernetes/endpoints.go @@ -15,6 +15,7 @@ package kubernetes import ( "context" + "github.com/prometheus/prometheus/util/strutil" "net" "strconv" From 62bc755733ecd3b3bf9bc279a92c8e4c8f476d1c Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Wed, 30 Dec 2020 17:47:04 +0100 Subject: [PATCH 3/5] mixin: Scope grafana config In its current form this configuration clashes in one of the most widely used configurations (kube-prometheus). This patch scopes the configuration to prevent this. Signed-off-by: Frederic Branczyk --- documentation/prometheus-mixin/config.libsonnet | 2 +- documentation/prometheus-mixin/dashboards.libsonnet | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/documentation/prometheus-mixin/config.libsonnet b/documentation/prometheus-mixin/config.libsonnet index 85a2048e01..6b96a31429 100644 --- a/documentation/prometheus-mixin/config.libsonnet +++ b/documentation/prometheus-mixin/config.libsonnet @@ -38,7 +38,7 @@ // Example: @'http://test-alertmanager\..*' nonNotifyingAlertmanagerRegEx: @'', - grafana: { + grafanaPrometheus: { prefix: 'Prometheus / ', tags: ['prometheus-mixin'], // The default refresh time for all dashboards, default to 60s diff --git a/documentation/prometheus-mixin/dashboards.libsonnet b/documentation/prometheus-mixin/dashboards.libsonnet index e5f7cc5c06..c1336cd183 100644 --- a/documentation/prometheus-mixin/dashboards.libsonnet +++ b/documentation/prometheus-mixin/dashboards.libsonnet @@ -11,7 +11,7 @@ local template = grafana.template; grafanaDashboards+:: { 'prometheus.json': g.dashboard( - '%(prefix)sOverview' % $._config.grafana + '%(prefix)sOverview' % $._config.grafanaPrometheus ) .addMultiTemplate('job', 'prometheus_build_info', 'job') .addMultiTemplate('instance', 'prometheus_build_info', 'instance') @@ -99,8 +99,8 @@ local template = grafana.template; g.stack, ) ) + { - tags: $._config.grafana.tags, - refresh: $._config.grafana.refresh, + tags: $._config.grafanaPrometheus.tags, + refresh: $._config.grafanaPrometheus.refresh, }, // Remote write specific dashboard. 'prometheus-remote-write.json': @@ -293,7 +293,7 @@ local template = grafana.template; )); dashboard.new( - title='%(prefix)sRemote Write' % $._config.grafana, + title='%(prefix)sRemote Write' % $._config.grafanaPrometheus, editable=true ) .addTemplate( @@ -380,8 +380,8 @@ local template = grafana.template; .addPanel(retriedSamples) .addPanel(enqueueRetries) ) + { - tags: $._config.grafana.tags, - refresh: $._config.grafana.refresh, + tags: $._config.grafanaPrometheus.tags, + refresh: $._config.grafanaPrometheus.refresh, }, }, } From 063154eab720d8c3d495bd78312c0df090d0bf23 Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar <15064823+codesome@users.noreply.github.com> Date: Mon, 4 Jan 2021 14:33:36 +0530 Subject: [PATCH 4/5] Automate part of TestMaxQuerySamples (#8314) Signed-off-by: Ganesh Vernekar --- promql/engine_test.go | 226 ++++++++++-------------------------------- 1 file changed, 50 insertions(+), 176 deletions(-) diff --git a/promql/engine_test.go b/promql/engine_test.go index fff591afd2..c4c4aff906 100644 --- a/promql/engine_test.go +++ b/promql/engine_test.go @@ -555,10 +555,11 @@ load 10s err = test.Run() require.NoError(t, err) + // These test cases should be touching the limit exactly (hence no exceeding). + // Exceeding the limit will be tested by doing -1 to the MaxSamples. cases := []struct { Query string MaxSamples int - Result Result Start time.Time End time.Time Interval time.Duration @@ -567,209 +568,82 @@ load 10s { Query: "1", MaxSamples: 1, - Result: Result{ - nil, - Scalar{V: 1, T: 1000}, - nil}, - Start: time.Unix(1, 0), - }, - { - Query: "1", - MaxSamples: 0, - Result: Result{ - ErrTooManySamples(env), - nil, - nil, - }, - Start: time.Unix(1, 0), - }, - { - Query: "metric", - MaxSamples: 0, - Result: Result{ - ErrTooManySamples(env), - nil, - nil, - }, - Start: time.Unix(1, 0), - }, - { + Start: time.Unix(1, 0), + }, { Query: "metric", MaxSamples: 1, - Result: Result{ - nil, - Vector{ - Sample{Point: Point{V: 1, T: 1000}, - Metric: labels.FromStrings("__name__", "metric")}, - }, - nil, - }, - Start: time.Unix(1, 0), - }, - { + Start: time.Unix(1, 0), + }, { Query: "metric[20s]", MaxSamples: 2, - Result: Result{ - nil, - Matrix{Series{ - Points: []Point{{V: 1, T: 0}, {V: 2, T: 10000}}, - Metric: labels.FromStrings("__name__", "metric")}, - }, - nil, - }, - Start: time.Unix(10, 0), - }, - { + Start: time.Unix(10, 0), + }, { Query: "rate(metric[20s])", MaxSamples: 3, - Result: Result{ - nil, - Vector{ - Sample{ - Point: Point{V: 0.1, T: 10000}, - Metric: labels.Labels{}, - }, - }, - nil, - }, - Start: time.Unix(10, 0), - }, - { + Start: time.Unix(10, 0), + }, { Query: "metric[20s:5s]", MaxSamples: 3, - Result: Result{ - nil, - Matrix{Series{ - Points: []Point{{V: 1, T: 0}, {V: 1, T: 5000}, {V: 2, T: 10000}}, - Metric: labels.FromStrings("__name__", "metric")}, - }, - nil, - }, - Start: time.Unix(10, 0), - }, - { - Query: "metric[20s]", - MaxSamples: 0, - Result: Result{ - ErrTooManySamples(env), - nil, - nil, - }, - Start: time.Unix(10, 0), + Start: time.Unix(10, 0), }, // Range queries. { Query: "1", MaxSamples: 3, - Result: Result{ - nil, - Matrix{Series{ - Points: []Point{{V: 1, T: 0}, {V: 1, T: 1000}, {V: 1, T: 2000}}, - Metric: labels.FromStrings()}, - }, - nil, - }, - Start: time.Unix(0, 0), - End: time.Unix(2, 0), - Interval: time.Second, - }, - { + Start: time.Unix(0, 0), + End: time.Unix(2, 0), + Interval: time.Second, + }, { Query: "1", - MaxSamples: 0, - Result: Result{ - ErrTooManySamples(env), - nil, - nil, - }, - Start: time.Unix(0, 0), - End: time.Unix(2, 0), - Interval: time.Second, - }, - { + MaxSamples: 3, + Start: time.Unix(0, 0), + End: time.Unix(2, 0), + Interval: time.Second, + }, { Query: "metric", MaxSamples: 3, - Result: Result{ - nil, - Matrix{Series{ - Points: []Point{{V: 1, T: 0}, {V: 1, T: 1000}, {V: 1, T: 2000}}, - Metric: labels.FromStrings("__name__", "metric")}, - }, - nil, - }, - Start: time.Unix(0, 0), - End: time.Unix(2, 0), - Interval: time.Second, - }, - { - Query: "metric", - MaxSamples: 2, - Result: Result{ - ErrTooManySamples(env), - nil, - nil, - }, - Start: time.Unix(0, 0), - End: time.Unix(2, 0), - Interval: time.Second, - }, - { + Start: time.Unix(0, 0), + End: time.Unix(2, 0), + Interval: time.Second, + }, { Query: "metric", MaxSamples: 3, - Result: Result{ - nil, - Matrix{Series{ - Points: []Point{{V: 1, T: 0}, {V: 1, T: 5000}, {V: 2, T: 10000}}, - Metric: labels.FromStrings("__name__", "metric")}, - }, - nil, - }, - Start: time.Unix(0, 0), - End: time.Unix(10, 0), - Interval: 5 * time.Second, - }, - { - Query: "metric", - MaxSamples: 2, - Result: Result{ - ErrTooManySamples(env), - nil, - nil, - }, - Start: time.Unix(0, 0), - End: time.Unix(10, 0), - Interval: 5 * time.Second, - }, - { + Start: time.Unix(0, 0), + End: time.Unix(10, 0), + Interval: 5 * time.Second, + }, { Query: "rate(bigmetric[1s])", MaxSamples: 1, - Result: Result{ - nil, - Matrix{}, - nil, - }, - Start: time.Unix(0, 0), - End: time.Unix(10, 0), - Interval: 5 * time.Second, + Start: time.Unix(0, 0), + End: time.Unix(10, 0), + Interval: 5 * time.Second, }, } engine := test.QueryEngine() for _, c := range cases { - var err error - var qry Query + t.Run(c.Query, func(t *testing.T) { + var err error + var qry Query - engine.maxSamplesPerQuery = c.MaxSamples + engine.maxSamplesPerQuery = c.MaxSamples - if c.Interval == 0 { - qry, err = engine.NewInstantQuery(test.Queryable(), c.Query, c.Start) - } else { - qry, err = engine.NewRangeQuery(test.Queryable(), c.Query, c.Start, c.End, c.Interval) - } - require.NoError(t, err) + if c.Interval == 0 { + qry, err = engine.NewInstantQuery(test.Queryable(), c.Query, c.Start) + } else { + qry, err = engine.NewRangeQuery(test.Queryable(), c.Query, c.Start, c.End, c.Interval) + } + require.NoError(t, err) - res := qry.Exec(test.Context()) - require.Equal(t, c.Result.Err, res.Err) - require.Equal(t, c.Result.Value, res.Value, "query %q failed", c.Query) + // Within limit. + res := qry.Exec(test.Context()) + require.NoError(t, res.Err) + + // Exceeding limit. + engine.maxSamplesPerQuery = c.MaxSamples - 1 + res = qry.Exec(test.Context()) + require.Equal(t, ErrTooManySamples(env), res.Err) + }) } } From e2cd6c5f579e5529890edf281ad43caaa6073035 Mon Sep 17 00:00:00 2001 From: Guangwen Feng Date: Wed, 6 Jan 2021 15:54:35 +0800 Subject: [PATCH 5/5] Fix golint issue caused by typo Signed-off-by: Guangwen Feng --- tsdb/chunks/head_chunks.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsdb/chunks/head_chunks.go b/tsdb/chunks/head_chunks.go index d82c12d33f..051b9b1a89 100644 --- a/tsdb/chunks/head_chunks.go +++ b/tsdb/chunks/head_chunks.go @@ -70,7 +70,7 @@ const ( DefaultWriteBufferSize = 4 * 1024 * 1024 // 4 MiB. ) -// corruptionErr is an error that's returned when corruption is encountered. +// CorruptionErr is an error that's returned when corruption is encountered. type CorruptionErr struct { Dir string FileIndex int