Repository: VictoriaMetrics/VictoriaMetrics
Pull request #170 (2019-09-03 14:47:05)

Don't render extraLabels in ServiceMonitor if they are not given
This produced invalid YAML before.


Patch:
diff --git a/app/vmselect/promql/binary_op.go b/app/vmselect/promql/binary_op.go
index 609ce1020..e3b2478e8 100644
--- a/app/vmselect/promql/binary_op.go
+++ b/app/vmselect/promql/binary_op.go
@@ -322,6 +322,7 @@ func adjustBinaryOpTags(be *binaryOpExpr, left, right []*timeseries) ([]*timeser
 			}
 			src := tssRight[0]
 			for _, ts := range tssLeft {
+				resetMetricGroupIfRequired(be, ts)
 				ts.MetricName.AddMissingTags(joinTags, &src.MetricName)
 				rvsLeft = append(rvsLeft, ts)
 				rvsRight = append(rvsRight, src)
@@ -332,6 +333,7 @@ func adjustBinaryOpTags(be *binaryOpExpr, left, right []*timeseries) ([]*timeser
 			}
 			src := tssLeft[0]
 			for _, ts := range tssRight {
+				resetMetricGroupIfRequired(be, ts)
 				ts.MetricName.AddMissingTags(joinTags, &src.MetricName)
 				rvsLeft = append(rvsLeft, src)
 				rvsRight = append(rvsRight, ts)
diff --git a/deployment/docker/docker-compose.yml b/deployment/docker/docker-compose.yml
index 698c8f8de..d6f891ae9 100644
--- a/deployment/docker/docker-compose.yml
+++ b/deployment/docker/docker-compose.yml
@@ -21,7 +21,7 @@ services:
     restart: always
   vmstorage:
     container_name: vmstorage
-    image: victoriametrics/vmstorage:v1.27.0-cluster
+    image: victoriametrics/vmstorage:v1.27.1-cluster
     ports:
       - 8482:8482
       - 8400:8400
@@ -35,7 +35,7 @@ services:
     restart: always
   vminsert:
     container_name: vminsert
-    image: victoriametrics/vminsert:v1.27.0-cluster
+    image: victoriametrics/vminsert:v1.27.1-cluster
     depends_on:
       - "vmstorage"
     command:
@@ -47,7 +47,7 @@ services:
     restart: always
   vmselect:
     container_name: vmselect
-    image: victoriametrics/vmselect:v1.27.0-cluster
+    image: victoriametrics/vmselect:v1.27.1-cluster
     depends_on:
       - "vmstorage"
     command:
diff --git a/deployment/k8s/helm/victoria-metrics/templates/vminsert-service-monitor.yaml b/deployment/k8s/helm/victoria-metrics/templates/vminsert-service-monitor.yaml
index 45255ceae..701612cfc 100644
--- a/deployment/k8s/helm/victoria-metrics/templates/vminsert-service-monitor.yaml
+++ b/deployment/k8s/helm/victoria-metrics/templates/vminsert-service-monitor.yaml
@@ -8,7 +8,9 @@ metadata:
   {{- end }}
   labels:
   {{- include "victoria-metrics.vminsert.labels" . | nindent 4 }}
+  {{- if .Values.vminsert.serviceMonitor.extraLabels }}
 {{ toYaml .Values.vminsert.serviceMonitor.extraLabels | indent 4 }}
+  {{- end }}
   name: {{ template "victoria-metrics.vminsert.fullname" . }}
 spec:
   namespaceSelector:
diff --git a/deployment/k8s/helm/victoria-metrics/templates/vmselect-service-monitor.yaml b/deployment/k8s/helm/victoria-metrics/templates/vmselect-service-monitor.yaml
index c166259c2..04663aa26 100644
--- a/deployment/k8s/helm/victoria-metrics/templates/vmselect-service-monitor.yaml
+++ b/deployment/k8s/helm/victoria-metrics/templates/vmselect-service-monitor.yaml
@@ -8,7 +8,9 @@ metadata:
   {{- end }}
   labels:
   {{- include "victoria-metrics.vmselect.labels" . | nindent 4 }}
+  {{- if .Values.vmselect.serviceMonitor.extraLabels }}
 {{ toYaml .Values.vmselect.serviceMonitor.extraLabels | indent 4 }}
+  {{- end }}
   name: {{ template "victoria-metrics.vmselect.fullname" . }}
 spec:
   namespaceSelector:
diff --git a/deployment/k8s/helm/victoria-metrics/templates/vmstorage-service-monitor.yaml b/deployment/k8s/helm/victoria-metrics/templates/vmstorage-service-monitor.yaml
index 70ff76363..e616a848a 100644
--- a/deployment/k8s/helm/victoria-metrics/templates/vmstorage-service-monitor.yaml
+++ b/deployment/k8s/helm/victoria-metrics/templates/vmstorage-service-monitor.yaml
@@ -8,7 +8,9 @@ metadata:
   {{- end }}
   labels:
   {{- include "victoria-metrics.vmstorage.labels" . | nindent 4 }}
+  {{- if .Values.vmstorage.serviceMonitor.extraLabels }}
 {{ toYaml .Values.vmstorage.serviceMonitor.extraLabels | indent 4 }}
+  {{- end }}
   name: {{ template "victoria-metrics.vmstorage.fullname" . }}
 spec:
   namespaceSelector:
diff --git a/deployment/k8s/helm/victoria-metrics/values.yaml b/deployment/k8s/helm/victoria-metrics/values.yaml
index 79f95472b..541824076 100644
--- a/deployment/k8s/helm/victoria-metrics/values.yaml
+++ b/deployment/k8s/helm/victoria-metrics/values.yaml
@@ -12,7 +12,7 @@ vmselect:
   name: vmselect
   image:
     repository: victoriametrics/vmselect
-    tag: v1.27.0-cluster
+    tag: v1.27.1-cluster
     pullPolicy: IfNotPresent
   priorityClassName: ""
   extraArgs: {}
@@ -109,7 +109,7 @@ vminsert:
   name: vminsert
   image:
     repository: victoriametrics/vminsert
-    tag: v1.27.0-cluster
+    tag: v1.27.1-cluster
     pullPolicy: IfNotPresent
   priorityClassName: ""
   extraArgs: {}
@@ -172,7 +172,7 @@ vmstorage:
   name: vmstorage
   image:
     repository: victoriametrics/vmstorage
-    tag: v1.27.0-cluster
+    tag: v1.27.1-cluster
     pullPolicy: IfNotPresent
   priorityClassName: ""
   fullnameOverride:


Test patch:
diff --git a/app/vmselect/promql/exec_test.go b/app/vmselect/promql/exec_test.go
index 5b4d2015d..5929084cd 100644
--- a/app/vmselect/promql/exec_test.go
+++ b/app/vmselect/promql/exec_test.go
@@ -1869,9 +1869,9 @@ func TestExecSuccess(t *testing.T) {
 		resultExpected := []netstorage.Result{r}
 		f(q, resultExpected)
 	})
-	t.Run(`vector * on(foo) group_left() duplicate_timeseries`, func(t *testing.T) {
+	t.Run(`vector * on(foo) group_left() duplicate_nonoverlapping_timeseries`, func(t *testing.T) {
 		t.Parallel()
-		q := `label_set(time()/10, "foo", "bar") + on(foo) group_left() (
+		q := `label_set(time()/10, "foo", "bar", "xx", "yy", "__name__", "qwert") + on(foo) group_left() (
 			label_set(time() < 1400, "foo", "bar", "op", "le"),
 			label_set(time() >= 1400, "foo", "bar", "op", "ge"),
 		)`
@@ -1880,13 +1880,85 @@ func TestExecSuccess(t *testing.T) {
 			Values:     []float64{1100, 1320, 1540, 1760, 1980, 2200},
 			Timestamps: timestampsExpected,
 		}
-		r1.MetricName.Tags = []storage.Tag{{
-			Key:   []byte("foo"),
-			Value: []byte("bar"),
-		}}
+		r1.MetricName.Tags = []storage.Tag{
+			{
+				Key:   []byte("foo"),
+				Value: []byte("bar"),
+			},
+			{
+				Key:   []byte("xx"),
+				Value: []byte("yy"),
+			},
+		}
 		resultExpected := []netstorage.Result{r1}
 		f(q, resultExpected)
 	})
+	t.Run(`vector * on(foo) group_left(__name__)`, func(t *testing.T) {
+		t.Parallel()
+		q := `label_set(time()/10, "foo", "bar", "xx", "yy", "__name__", "qwert") + on(foo) group_left(__name__)
+			label_set(time(), "foo", "bar", "__name__", "aaa")`
+		r1 := netstorage.Result{
+			MetricName: metricNameExpected,
+			Values:     []float64{1100, 1320, 1540, 1760, 1980, 2200},
+			Timestamps: timestampsExpected,
+		}
+		r1.MetricName.MetricGroup = []byte("aaa")
+		r1.MetricName.Tags = []storage.Tag{
+			{
+				Key:   []byte("foo"),
+				Value: []byte("bar"),
+			},
+			{
+				Key:   []byte("xx"),
+				Value: []byte("yy"),
+			},
+		}
+		resultExpected := []netstorage.Result{r1}
+		f(q, resultExpected)
+	})
+	t.Run(`vector * on(foo) group_right()`, func(t *testing.T) {
+		t.Parallel()
+		q := `sort(label_set(time()/10, "foo", "bar", "xx", "yy", "__name__", "qwert") + on(foo) group_right(xx) (
+			label_set(time(), "foo", "bar", "__name__", "aaa"),
+			label_set(time()+3, "foo", "bar", "__name__", "yyy","ppp", "123"),
+		))`
+		r1 := netstorage.Result{
+			MetricName: metricNameExpected,
+			Values:     []float64{1100, 1320, 1540, 1760, 1980, 2200},
+			Timestamps: timestampsExpected,
+		}
+		r1.MetricName.Tags = []storage.Tag{
+			{
+				Key:   []byte("foo"),
+				Value: []byte("bar"),
+			},
+			{
+				Key:   []byte("xx"),
+				Value: []byte("yy"),
+			},
+		}
+		r2 := netstorage.Result{
+			MetricName: metricNameExpected,
+			Values:     []float64{1103, 1323, 1543, 1763, 1983, 2203},
+			Timestamps: timestampsExpected,
+		}
+		r2.MetricName.Tags = []storage.Tag{
+			{
+				Key:   []byte("foo"),
+				Value: []byte("bar"),
+			},
+			{
+				Key:   []byte("ppp"),
+				Value: []byte("123"),
+			},
+			{
+				Key:   []byte("xx"),
+				Value: []byte("yy"),
+			},
+		}
+		resultExpected := []netstorage.Result{r1, r2}
+		f(q, resultExpected)
+	})
 	t.Run(`vector * on() group_left scalar`, func(t *testing.T) {
 		t.Parallel()
 		q := `sort_desc((label_set(time(), "foo", "bar") or label_set(10, "foo", "qwert")) * on() group_left 2)`