Skip to content

Commit c37625a

Browse files
authored
[FEATURE] add loki values, value names and logql variables (#651)
Signed-off-by: Gabriel Bernal <gbernal@redhat.com>
1 parent 2026cf8 commit c37625a

26 files changed

Lines changed: 1459 additions & 412 deletions

loki/package.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,33 @@
7474
},
7575
"name": "LokiLogQuery"
7676
}
77+
},
78+
{
79+
"kind": "Variable",
80+
"spec": {
81+
"display": {
82+
"name": "Loki Label Values Variable"
83+
},
84+
"name": "LokiLabelValuesVariable"
85+
}
86+
},
87+
{
88+
"kind": "Variable",
89+
"spec": {
90+
"display": {
91+
"name": "Loki Label Names Variable"
92+
},
93+
"name": "LokiLabelNamesVariable"
94+
}
95+
},
96+
{
97+
"kind": "Variable",
98+
"spec": {
99+
"display": {
100+
"name": "Loki LogQL Variable"
101+
},
102+
"name": "LokiLogQLVariable"
103+
}
77104
}
78105
]
79106
}

loki/rsbuild.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export default createConfigForPlugin({
2525
'./LokiDatasource': './src/datasources/loki-datasource',
2626
'./LokiTimeSeriesQuery': './src/queries/loki-time-series-query',
2727
'./LokiLogQuery': './src/queries/loki-log-query',
28+
'./LokiLabelValuesVariable': './src/variables/LokiLabelValuesVariable.tsx',
29+
'./LokiLabelNamesVariable': './src/variables/LokiLabelNamesVariable.tsx',
30+
'./LokiLogQLVariable': './src/variables/LokiLogQLVariable.tsx',
2831
},
2932
shared: {
3033
react: { requiredVersion: '18.2.0', singleton: true },
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package model
15+
16+
import (
17+
ds "github.com/perses/plugins/loki/schemas/datasources:model"
18+
)
19+
20+
kind: "LokiLabelNamesVariable"
21+
spec: close({
22+
ds.#selector
23+
matchers?: [...string]
24+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"kind": "LokiLabelNamesVariable",
3+
"spec": {
4+
"matchers": [
5+
"{job=\"myapp\"}"
6+
]
7+
}
8+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package model
15+
16+
import (
17+
"strings"
18+
ds "github.com/perses/plugins/loki/schemas/datasources:model"
19+
)
20+
21+
kind: "LokiLabelValuesVariable"
22+
spec: close({
23+
ds.#selector
24+
labelName: strings.MinRunes(1)
25+
matchers?: [...string]
26+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"kind": "LokiLabelValuesVariable",
3+
"spec": {
4+
"labelName": "job",
5+
"matchers": [
6+
"{job=\"myapp\"}"
7+
]
8+
}
9+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright The Perses Authors
2+
// Licensed under the Apache License, Version 2.0 (the "License");
3+
// you may not use this file except in compliance with the License.
4+
// You may obtain a copy of the License at
5+
//
6+
// http://www.apache.org/licenses/LICENSE-2.0
7+
//
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
14+
package model
15+
16+
import (
17+
"strings"
18+
ds "github.com/perses/plugins/loki/schemas/datasources:model"
19+
)
20+
21+
kind: "LokiLogQLVariable"
22+
spec: close({
23+
ds.#selector
24+
expr: strings.MinRunes(1)
25+
labelName: strings.MinRunes(1)
26+
})
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"kind": "LokiLogQLVariable",
3+
"spec": {
4+
"expr": "count_over_time({job=\"myapp\"}[1h])",
5+
"labelName": ""
6+
}
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"kind": "LokiLogQLVariable",
3+
"spec": {
4+
"expr": "count_over_time({job=\"myapp\"}[1h])",
5+
"labelName": "job"
6+
}
7+
}

loki/src/components/complete.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ async function completeLabelName(completionCfg: CompletionConfig): Promise<Compl
365365
const end = completionCfg.timeRange?.end ? toUnixSeconds(new Date(completionCfg.timeRange.end).getTime()) : undefined;
366366

367367
try {
368-
const response = await completionCfg.client.labels(start, end);
369-
if (response.status === 'success') {
368+
const response = await completionCfg.client.labels({ start, end });
369+
if (response.status === 'success' && response.data) {
370370
return response.data.map((label: string) => ({ label }));
371371
}
372372
return [];
@@ -387,8 +387,8 @@ async function completeLabelValue(completionCfg: CompletionConfig, label: string
387387
const end = completionCfg.timeRange?.end ? toUnixSeconds(new Date(completionCfg.timeRange.end).getTime()) : undefined;
388388

389389
try {
390-
const response = await completionCfg.client.labelValues(label, start, end);
391-
if (response.status === 'success') {
390+
const response = await completionCfg.client.labelValues({ labelName: label, start, end });
391+
if (response.status === 'success' && response.data) {
392392
return response.data.map((value: string) => ({
393393
label: value ?? '',
394394
displayLabel: value ?? '(empty string)',

0 commit comments

Comments
 (0)