Repository: prometheus/prometheus (language: go)

Issue:
promqltest: this load expression for native histogram should work
For float series, we can write the following to load a series into the test framework:

```
testcounter_reset_middle_total	0+27x4 0+27x5
```

Correspondingly, something like the following should work for native histograms:

```
native_histogram {{sum:100 count:100}}+{{sum:3 count:3}}x4 {{sum:0 count:0}}+{{sum:3 count:3}}x5
```

However, this results in the following:

```
141:60: parse error: unexpected "{"
```
(Where the position is the start of the 2nd part, i.e. `{{sum:0 count:0}}+{{sum:3 count:3}}x5`.)

It looks like the parser doesn't understand if there are two `+` tokens.

The following works as a work-around:

```
native_histogram {{sum:100 count:100}} {{sum:103 count:103}} {{sum:106 count:106}} {{sum:109 count:109}}  {{sum:112 count:112}} {{sum:0 count:0}}+{{sum:3 count:3}}x5
```


Discussion / hints:
@beorn7, please assign this to me. Will create a PR soon.

Fix patch:
diff --git a/promql/parser/lex.go b/promql/parser/lex.go
index 52658f318c5..0b76911e395 100644
--- a/promql/parser/lex.go
+++ b/promql/parser/lex.go
@@ -512,7 +512,7 @@ func lexHistogram(l *Lexer) stateFn {
 		l.histogramState = histogramStateNone
 		l.next()
 		l.emit(TIMES)
-		return lexNumber
+		return lexValueSequence
 	case histogramStateAdd:
 		l.histogramState = histogramStateNone
 		l.next()


Test patch:
diff --git a/promql/parser/lex_test.go b/promql/parser/lex_test.go
index c5475a8b940..ffcfc8aac92 100644
--- a/promql/parser/lex_test.go
+++ b/promql/parser/lex_test.go
@@ -691,6 +691,42 @@ var tests = []struct {
 				},
 				seriesDesc: true,
 			},
+			{
+				input: `{} {{sum:1}}+{{sum:0}}x2 {{sum:1}}+{{sum:0}}x3`,
+				expected: []Item{
+					{LEFT_BRACE, 0, `{`},
+					{RIGHT_BRACE, 1, `}`},
+					{SPACE, 2, ` `},
+					{OPEN_HIST, 3, `{{`},
+					{SUM_DESC, 5, `sum`},
+					{COLON, 8, `:`},
+					{NUMBER, 9, `1`},
+					{CLOSE_HIST, 10, `}}`},
+					{ADD, 12, `+`},
+					{OPEN_HIST, 13, `{{`},
+					{SUM_DESC, 15, `sum`},
+					{COLON, 18, `:`},
+					{NUMBER, 19, `0`},
+					{CLOSE_HIST, 20, `}}`},
+					{TIMES, 22, `x`},
+					{NUMBER, 23, `2`},
+					{SPACE, 24, ` `},
+					{OPEN_HIST, 25, `{{`},
+					{SUM_DESC, 27, `sum`},
+					{COLON, 30, `:`},
+					{NUMBER, 31, `1`},
+					{CLOSE_HIST, 32, `}}`},
+					{ADD, 34, `+`},
+					{OPEN_HIST, 35, `{{`},
+					{SUM_DESC, 37, `sum`},
+					{COLON, 40, `:`},
+					{NUMBER, 41, `0`},
+					{CLOSE_HIST, 42, `}}`},
+					{TIMES, 44, `x`},
+					{NUMBER, 45, `3`},
+				},
+				seriesDesc: true,
+			},
 		},
 	},
 	{
diff --git a/promql/parser/parse_test.go b/promql/parser/parse_test.go
index 64ce97304c5..06f41c3f778 100644
--- a/promql/parser/parse_test.go
+++ b/promql/parser/parse_test.go
@@ -4371,6 +4371,30 @@ func TestParseHistogramSeries(t *testing.T) {
 				},
 			},
 		},
+		{
+			name:  "series with two different increments",
+			input: `{} {{sum:1}}+{{sum:1}}x2 {{sum:2}}+{{sum:2}}x2`,
+			expected: []histogram.FloatHistogram{
+				{
+					Sum: 1,
+				},
+				{
+					Sum: 2,
+				},
+				{
+					Sum: 3,
+				},
+				{
+					Sum: 2,
+				},
+				{
+					Sum: 4,
+				},
+				{
+					Sum: 6,
+				},
+			},
+		},
 		{
 			name:  "series with decrement",
 			input: `{} {{buckets:[5 10 7] schema:1}}-{{buckets:[1 2 3] schema:1}}x2`,
diff --git a/promql/promqltest/testdata/native_histograms.test b/promql/promqltest/testdata/native_histograms.test
index dd119c0617c..751039e0290 100644
--- a/promql/promqltest/testdata/native_histograms.test
+++ b/promql/promqltest/testdata/native_histograms.test
@@ -57,7 +57,7 @@ clear
 
 # Repeat the same histogram 10 times.
 load 5m
-	multi_histogram	{{schema:0 sum:5 count:4 buckets:[1 2 1]}}x10
+	multi_histogram	{{schema:0 sum:5 count:4 buckets:[1 2 1]}}x10 {{schema:0 sum:5 count:4 buckets:[1 2 1]}}+{{}}x10
 
 eval instant at 5m histogram_count(multi_histogram)
 	{} 4