mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Add label_replace option to query builder (#47247)
* Add label_replace operation * Update
This commit is contained in:
@@ -121,6 +121,15 @@ describe('LokiQueryModeller', () => {
|
||||
).toBe('{app="grafana"} | line_format "{{.status_code}}"');
|
||||
});
|
||||
|
||||
it('Can render with label_format operation', () => {
|
||||
expect(
|
||||
modeller.renderQuery({
|
||||
labels: [{ label: 'app', op: '=', value: 'grafana' }],
|
||||
operations: [{ id: LokiOperationId.LabelFormat, params: ['new', 'old'] }],
|
||||
})
|
||||
).toBe('{app="grafana"} | label_format old=`new`');
|
||||
});
|
||||
|
||||
it('Can render simply binary operation with scalar', () => {
|
||||
expect(
|
||||
modeller.renderQuery({
|
||||
|
||||
@@ -84,6 +84,27 @@ export function getOperationDefintions(): QueryBuilderOperationDef[] {
|
||||
[Read the docs](https://grafana.com/docs/loki/latest/logql/log_queries/#line-format-expression) for more.
|
||||
`,
|
||||
},
|
||||
{
|
||||
id: LokiOperationId.LabelFormat,
|
||||
name: 'Label format',
|
||||
params: [
|
||||
{ name: 'Label', type: 'string' },
|
||||
{ name: 'Rename', type: 'string' },
|
||||
],
|
||||
defaultParams: ['', ''],
|
||||
alternativesKey: 'format',
|
||||
category: LokiVisualQueryOperationCategory.Formats,
|
||||
orderRank: LokiOperationOrder.LineFormats,
|
||||
renderer: (model, def, innerExpr) => `${innerExpr} | label_format ${model.params[1]}=\`${model.params[0]}\``,
|
||||
addOperationHandler: addLokiOperation,
|
||||
explainHandler: () =>
|
||||
`This will change name of label to desired new label. In the example below, label "error_level" will be renamed to "level".
|
||||
|
||||
Example: error_level=\`level\`
|
||||
|
||||
[Read the docs](https://grafana.com/docs/loki/latest/logql/log_queries/#labels-format-expression) for more.
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
id: LokiOperationId.LineContains,
|
||||
|
||||
@@ -31,6 +31,7 @@ export enum LokiOperationId {
|
||||
Json = 'json',
|
||||
Logfmt = 'logfmt',
|
||||
LineFormat = 'line_format',
|
||||
LabelFormat = 'label_format',
|
||||
Rate = 'rate',
|
||||
CountOverTime = 'count_over_time',
|
||||
SumOverTime = 'sum_over_time',
|
||||
|
||||
Reference in New Issue
Block a user