Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit 6823dd1

Browse files
committed
Order the label name and value queries
Needed for tests and correctness
1 parent a91f428 commit 6823dd1

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pkg/pgmodel/lreader/labels_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const (
4848
tenantLabelValueQual = `value = $%d`
4949
getLabelNamesForTenant = `
5050
SELECT
51-
array_agg(keys.key)
51+
array_agg(keys.key order by keys.key)
5252
FROM (
5353
SELECT
5454
distinct l.key
@@ -76,7 +76,7 @@ const (
7676

7777
getLabelValuesForTenant = `
7878
SELECT
79-
array_agg(l.value)
79+
array_agg(l.value order by l.value)
8080
FROM _prom_catalog.label l
8181
WHERE key = $1 AND
8282
EXISTS(

pkg/pgmodel/lreader/labels_reader_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func TestLabelsReaderLabelsValues(t *testing.T) {
169169
name: "Tenant values are filtered when tenant is configured",
170170
sqlQueries: []model.SqlQuery{
171171
{
172-
Sql: "SELECT array_agg(l.value) FROM _prom_catalog.label l WHERE key = $1 AND EXISTS( SELECT 1 FROM _prom_catalog.series WHERE ( labels @> array[l.id] AND labels && ( SELECT array_agg(id :: INTEGER) FROM _prom_catalog.label WHERE key = '__tenant__' AND ( value = $2 ) )::int[] ) )",
172+
Sql: "SELECT array_agg(l.value order by l.value) FROM _prom_catalog.label l WHERE key = $1 AND EXISTS( SELECT 1 FROM _prom_catalog.series WHERE ( labels @> array[l.id] AND labels && ( SELECT array_agg(id :: INTEGER) FROM _prom_catalog.label WHERE key = '__tenant__' AND ( value = $2 ) )::int[] ) )",
173173
Args: []interface{}{"__tenant__", "a"},
174174
Results: model.RowResults{{[]string{"a"}}},
175175
},

0 commit comments

Comments
 (0)