Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions loki/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,33 @@
},
"name": "LokiLogQuery"
}
},
{
"kind": "Variable",
"spec": {
"display": {
"name": "Loki Label Values Variable"
},
"name": "LokiLabelValuesVariable"
}
},
{
"kind": "Variable",
"spec": {
"display": {
"name": "Loki Label Names Variable"
},
"name": "LokiLabelNamesVariable"
}
},
{
"kind": "Variable",
"spec": {
"display": {
"name": "Loki LogQL Variable"
},
"name": "LokiLogQLVariable"
}
}
]
}
Expand Down
3 changes: 3 additions & 0 deletions loki/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default createConfigForPlugin({
'./LokiDatasource': './src/datasources/loki-datasource',
'./LokiTimeSeriesQuery': './src/queries/loki-time-series-query',
'./LokiLogQuery': './src/queries/loki-log-query',
'./LokiLabelValuesVariable': './src/variables/LokiLabelValuesVariable.tsx',
'./LokiLabelNamesVariable': './src/variables/LokiLabelNamesVariable.tsx',
'./LokiLogQLVariable': './src/variables/LokiLogQLVariable.tsx',
},
shared: {
react: { requiredVersion: '18.2.0', singleton: true },
Expand Down
24 changes: 24 additions & 0 deletions loki/schemas/variables/loki-label-names/loki-label-names.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright The Perses Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

import (
ds "github.com/perses/plugins/loki/schemas/datasources:model"
)

kind: "LokiLabelNamesVariable"
spec: close({
ds.#selector
matchers?: [...string]
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"kind": "LokiLabelNamesVariable",
"spec": {
"matchers": [
"{job=\"myapp\"}"
]
}
}
26 changes: 26 additions & 0 deletions loki/schemas/variables/loki-label-values/loki-label-values.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The Perses Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

import (
"strings"
ds "github.com/perses/plugins/loki/schemas/datasources:model"
)

kind: "LokiLabelValuesVariable"
spec: close({
ds.#selector
labelName: strings.MinRunes(1)
matchers?: [...string]
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"kind": "LokiLabelValuesVariable",
"spec": {
"labelName": "job",
"matchers": [
"{job=\"myapp\"}"
]
}
}
26 changes: 26 additions & 0 deletions loki/schemas/variables/loki-logql/loki-logql.cue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright The Perses Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

import (
"strings"
ds "github.com/perses/plugins/loki/schemas/datasources:model"
)

kind: "LokiLogQLVariable"
spec: close({
ds.#selector
expr: strings.MinRunes(1)
labelName: strings.MinRunes(1)
})
7 changes: 7 additions & 0 deletions loki/schemas/variables/loki-logql/tests/invalid/no-label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "LokiLogQLVariable",
"spec": {
"expr": "count_over_time({job=\"myapp\"}[1h])",
"labelName": ""
}
}
7 changes: 7 additions & 0 deletions loki/schemas/variables/loki-logql/tests/valid/loki-logql.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"kind": "LokiLogQLVariable",
"spec": {
"expr": "count_over_time({job=\"myapp\"}[1h])",
"labelName": "job"
}
}
8 changes: 4 additions & 4 deletions loki/src/components/complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ async function completeLabelName(completionCfg: CompletionConfig): Promise<Compl
const end = completionCfg.timeRange?.end ? toUnixSeconds(new Date(completionCfg.timeRange.end).getTime()) : undefined;

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

try {
const response = await completionCfg.client.labelValues(label, start, end);
if (response.status === 'success') {
const response = await completionCfg.client.labelValues({ labelName: label, start, end });
if (response.status === 'success' && response.data) {
return response.data.map((value: string) => ({
label: value ?? '',
displayLabel: value ?? '(empty string)',
Expand Down
5 changes: 2 additions & 3 deletions loki/src/datasources/loki-datasource/LokiDatasource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ const createClient: DatasourcePlugin<LokiDatasourceSpec, LokiClient>['createClie
},
query: (params, headers) => query(params, { datasourceUrl, headers: headers ?? specHeaders }),
queryRange: (params, headers) => queryRange(params, { datasourceUrl, headers: headers ?? specHeaders }),
labels: (start, end, headers) => labels(start, end, { datasourceUrl, headers: headers ?? specHeaders }),
labelValues: (label, start, end, headers) =>
labelValues(label, start, end, { datasourceUrl, headers: headers ?? specHeaders }),
labels: (params, headers) => labels(params, { datasourceUrl, headers: headers ?? specHeaders }),
labelValues: (params, headers) => labelValues(params, { datasourceUrl, headers: headers ?? specHeaders }),
series: (match, start, end, headers) =>
series(match, start, end, { datasourceUrl, headers: headers ?? specHeaders }),
volume: (params, headers) => volume(params, { datasourceUrl, headers: headers ?? specHeaders }),
Expand Down
1 change: 1 addition & 0 deletions loki/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ export { getPluginModule } from './getPluginModule';
export * from './model';
export * from './queries';
export * from './datasources';
export * from './variables';
2 changes: 1 addition & 1 deletion loki/src/model/loki-client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface LokiQueryResponse {
};
}

export type LokiQueryRangeResponse = LokiQueryRangeMatrixResponse & LokiQueryRangeStreamsResponse;
export type LokiQueryRangeResponse = LokiQueryRangeMatrixResponse | LokiQueryRangeStreamsResponse;

export interface LokiQueryRangeMatrixResponse {
status: 'success' | 'error';
Expand Down
Loading
Loading