diff --git a/MAINTAINERS.md b/MAINTAINERS.md index e00da702c..a61d396a6 100644 --- a/MAINTAINERS.md +++ b/MAINTAINERS.md @@ -3,4 +3,6 @@ Maintainers of this repository with their focus areas: * Brian Brazil @brian-brazil: Console templates; semantics of PromQL, service discovery, and relabeling. * Fabian Reinartz @fabxc: PromQL parsing and evaluation; implementation of retrieval, alert notification, and service discovery. * Julius Volz @juliusv: Remote storage integrations; web UI. +* Krasi Georgiev @krasi-georgiev: TSDB - the storage engine. +* Ganesh Vernekar @codesome: TSDB - the storage engine. diff --git a/Makefile b/Makefile index 11d4fa508..b029fa67a 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,9 @@ TSDB_BENCHMARK_NUM_METRICS ?= 1000 TSDB_BENCHMARK_DATASET ?= "$(TSDB_PROJECT_DIR)/testdata/20kseries.json" TSDB_BENCHMARK_OUTPUT_DIR ?= "$(TSDB_CLI_DIR)/benchout" +.PHONY: all +all: common-all check_assets + include Makefile.common DOCKER_IMAGE_NAME ?= prometheus @@ -39,9 +42,11 @@ check_assets: assets exit 1; \ fi +.PHONY: build_tsdb build_tsdb: GO111MODULE=$(GO111MODULE) $(GO) build -o $(TSDB_BIN) $(TSDB_CLI_DIR) +.PHONY: bench_tsdb bench_tsdb: build_tsdb @echo ">> running benchmark, writing result to $(TSDB_BENCHMARK_OUTPUT_DIR)" @$(TSDB_BIN) bench write --metrics=$(TSDB_BENCHMARK_NUM_METRICS) --out=$(TSDB_BENCHMARK_OUTPUT_DIR) $(TSDB_BENCHMARK_DATASET) diff --git a/discovery/targetgroup/targetgroup_test.go b/discovery/targetgroup/targetgroup_test.go index ceb6bf9b9..18b4efe14 100644 --- a/discovery/targetgroup/targetgroup_test.go +++ b/discovery/targetgroup/targetgroup_test.go @@ -17,37 +17,88 @@ import ( "errors" "testing" + "github.com/prometheus/common/model" "github.com/prometheus/prometheus/util/testutil" "gopkg.in/yaml.v2" ) func TestTargetGroupStrictJsonUnmarshal(t *testing.T) { tests := []struct { - json string - expectedReply error + json string + expectedReply error + expectedTargets []model.LabelSet }{ { json: ` {"labels": {},"targets": []}`, + expectedReply: nil, + expectedTargets: []model.LabelSet{}, + }, + { + json: ` {"labels": {},"targets": ["localhost:9090","localhost:9091"]}`, expectedReply: nil, + expectedTargets: []model.LabelSet{ + model.LabelSet{"__address__": "localhost:9090"}, + model.LabelSet{"__address__": "localhost:9091"}}, }, { json: ` {"label": {},"targets": []}`, - expectedReply: errors.New("json: unknown field \"label\""), + expectedReply: errors.New("json: unknown field \"label\""), + expectedTargets: nil, }, { json: ` {"labels": {},"target": []}`, - expectedReply: errors.New("json: unknown field \"target\""), + expectedReply: errors.New("json: unknown field \"target\""), + expectedTargets: nil, }, } - tg := Group{} for _, test := range tests { + tg := Group{} actual := tg.UnmarshalJSON([]byte(test.json)) testutil.Equals(t, test.expectedReply, actual) + testutil.Equals(t, test.expectedTargets, tg.Targets) } } +func TestTargetGroupYamlMarshal(t *testing.T) { + marshal := func(g interface{}) []byte { + d, err := yaml.Marshal(g) + if err != nil { + panic(err) + } + return d + } + + tests := []struct { + expectedYaml string + expectetedErr error + group Group + }{ + { + //labels should be omitted if empty + group: Group{}, + expectedYaml: "targets: []\n", + expectetedErr: nil, + }, + { + //targets only exposes addresses + group: Group{Targets: []model.LabelSet{ + model.LabelSet{"__address__": "localhost:9090"}, + model.LabelSet{"__address__": "localhost:9091"}}, + Labels: model.LabelSet{"foo": "bar", "bar": "baz"}}, + expectedYaml: "targets:\n- localhost:9090\n- localhost:9091\nlabels:\n bar: baz\n foo: bar\n", + expectetedErr: nil, + }, + } + + for _, test := range tests { + actual, err := test.group.MarshalYAML() + testutil.Equals(t, test.expectetedErr, err) + testutil.Equals(t, test.expectedYaml, string(marshal(actual))) + } +} + func TestTargetGroupYamlUnmarshal(t *testing.T) { unmarshal := func(d []byte) func(interface{}) error { return func(o interface{}) error { @@ -61,18 +112,28 @@ func TestTargetGroupYamlUnmarshal(t *testing.T) { expectedReply error }{ { + //empty targe group yaml: "labels:\ntargets:\n", expectedNumberOfTargets: 0, expectedNumberOfLabels: 0, expectedReply: nil, }, { + //brackets syntax yaml: "labels:\n my: label\ntargets:\n ['localhost:9090', 'localhost:9191']", expectedNumberOfTargets: 2, expectedNumberOfLabels: 1, expectedReply: nil, }, { + //hyphen syntax + yaml: "targets:\n- localhost:9090\n- localhost:9091\nlabels:\n bar: baz\n foo: bar\n", + expectedNumberOfTargets: 2, + expectedNumberOfLabels: 2, + expectedReply: nil, + }, + { + //incorrect syntax yaml: "labels:\ntargets:\n 'localhost:9090'", expectedNumberOfTargets: 0, expectedNumberOfLabels: 0, @@ -89,3 +150,21 @@ func TestTargetGroupYamlUnmarshal(t *testing.T) { } } + +func TestString(t *testing.T) { + //String() should return only the source, regardless of other attributes + group1 := + Group{Targets: []model.LabelSet{ + model.LabelSet{"__address__": "localhost:9090"}, + model.LabelSet{"__address__": "localhost:9091"}}, + Source: "", + Labels: model.LabelSet{"foo": "bar", "bar": "baz"}} + group2 := + Group{Targets: []model.LabelSet{}, + Source: "", + Labels: model.LabelSet{}} + testutil.Equals(t, "", group1.String()) + testutil.Equals(t, "", group2.String()) + testutil.Equals(t, group1.String(), group2.String()) + +} diff --git a/tsdb/MAINTAINERS.md b/tsdb/MAINTAINERS.md deleted file mode 100644 index dcb57a80d..000000000 --- a/tsdb/MAINTAINERS.md +++ /dev/null @@ -1,4 +0,0 @@ -Maintainers of this repository: - -* Krasi Georgiev @krasi-georgiev -* Goutham Veeramachaneni @gouthamve \ No newline at end of file