Skip to content

Commit

Permalink
Sidecar: Fix process external label when promethues v2.28+ use units.…
Browse files Browse the repository at this point in the history
…Bytes config type (thanos-io#4656)

Signed-off-by: hanjm <hanjinming@outlook.com>
  • Loading branch information
hanjm committed Sep 12, 2021
1 parent 0ac5daa commit 546bc3c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 3 additions & 1 deletion pkg/promclient/promclient.go
Expand Up @@ -176,7 +176,9 @@ func (c *Client) ExternalLabels(ctx context.Context, base *url.URL) (labels.Labe
if err := json.Unmarshal(body, &d); err != nil {
return nil, errors.Wrapf(err, "unmarshal response: %v", string(body))
}
var cfg config.Config
var cfg struct {
GlobalConfig config.GlobalConfig `yaml:"global"`
}
if err := yaml.Unmarshal([]byte(d.Data.YAML), &cfg); err != nil {
return nil, errors.Wrapf(err, "parse Prometheus config: %v", d.Data.YAML)
}
Expand Down
16 changes: 10 additions & 6 deletions pkg/promclient/promclient_e2e_test.go
Expand Up @@ -15,12 +15,14 @@ import (

"github.com/oklog/ulid"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/pkg/timestamp"
"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/runutil"
"github.com/thanos-io/thanos/pkg/testutil"
"github.com/thanos-io/thanos/pkg/testutil/e2eutil"
"gopkg.in/yaml.v3"
)

func TestIsWALFileAccessible_e2e(t *testing.T) {
Expand All @@ -38,12 +40,14 @@ func TestIsWALFileAccessible_e2e(t *testing.T) {

func TestExternalLabels_e2e(t *testing.T) {
e2eutil.ForeachPrometheus(t, func(t testing.TB, p *e2eutil.Prometheus) {
p.SetConfig(`
global:
external_labels:
region: eu-west
az: 1
`)
// Keep consist with the config processing in function (*Client).ExternalLabels.
cfg := config.Config{GlobalConfig: config.GlobalConfig{ExternalLabels: []labels.Label{
{Name: "region", Value: "eu-west"},
{Name: "az", Value: "1"},
}}}
cfgData, err := yaml.Marshal(cfg)
testutil.Ok(t, err)
p.SetConfig(string(cfgData))

testutil.Ok(t, p.Start())

Expand Down

0 comments on commit 546bc3c

Please sign in to comment.