Explore: Add transformations to correlation data links (#61799)

* bring in source from database

* bring in transformations from database

* add regex transformations to scopevar

* Consolidate types, add better example, cleanup

* Add var only if match

* Change ScopedVar to not require text, do not leak transformation-made variables between links

* Add mappings and start implementing logfmt

* Add mappings and start implementing logfmt

* Remove mappings, turn off global regex

* Add example yaml and omit transformations if empty

* Fix the yaml

* Add logfmt transformation

* Cleanup transformations and yaml

* add transformation field to FE types and use it, safeStringify logfmt values

* Add tests, only safe stringify if non-string, fix bug with safe stringify where it would return empty string with false value

* Add test for transformation field

* Do not add null transformations object

* Break out transformation logic, add tests to backend code

* Fix lint errors I understand 😅

* Fix the backend lint error

* Remove unnecessary code and mark new Transformations object as internal

* Add support for named capture groups

* Remove type assertion

* Remove variable name from transformation

* Add test for overriding regexes

* Add back variable name field, but change to mapValue

* fix go api test

* Change transformation types to enum, add better provisioning checks for bad type name and format

* Check for expression with regex transformations
This commit is contained in:
Kristina
2023-02-22 06:53:03 -06:00
committed by GitHub
parent f64b7fe8a7
commit 06dfe2156f
17 changed files with 377 additions and 21 deletions

View File

@@ -237,6 +237,8 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
label := "a label"
fieldName := "fieldName"
configType := correlations.ConfigTypeQuery
transformation := correlations.Transformation{Type: "logfmt"}
transformation2 := correlations.Transformation{Type: "regex", Expression: "testExpression", MapValue: "testVar"}
res := ctx.Post(PostParams{
url: fmt.Sprintf("/api/datasources/uid/%s/correlations", writableDs),
body: fmt.Sprintf(`{
@@ -246,7 +248,11 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
"config": {
"type": "%s",
"field": "%s",
"target": { "expr": "foo" }
"target": { "expr": "foo" },
"transformations": [
{"type": "logfmt"},
{"type": "regex", "expression": "testExpression", "mapValue": "testVar"}
]
}
}`, writableDs, description, label, configType, fieldName),
user: adminUser,
@@ -268,6 +274,8 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
require.Equal(t, configType, response.Result.Config.Type)
require.Equal(t, fieldName, response.Result.Config.Field)
require.Equal(t, map[string]interface{}{"expr": "foo"}, response.Result.Config.Target)
require.Equal(t, transformation, response.Result.Config.Transformations[0])
require.Equal(t, transformation2, response.Result.Config.Transformations[1])
require.NoError(t, res.Body.Close())
})

View File

@@ -79,6 +79,9 @@ func TestIntegrationReadCorrelation(t *testing.T) {
Type: correlations.ConfigTypeQuery,
Field: "foo",
Target: map[string]interface{}{},
Transformations: []correlations.Transformation{
{Type: "logfmt"},
},
},
})

View File

@@ -287,7 +287,8 @@ func TestIntegrationUpdateCorrelation(t *testing.T) {
"config": {
"field": "field",
"type": "query",
"target": { "expr": "bar" }
"target": { "expr": "bar" },
"transformations": [ {"type": "logfmt"} ]
}
}`,
})
@@ -305,6 +306,7 @@ func TestIntegrationUpdateCorrelation(t *testing.T) {
require.Equal(t, "1", response.Result.Description)
require.Equal(t, "field", response.Result.Config.Field)
require.Equal(t, map[string]interface{}{"expr": "bar"}, response.Result.Config.Target)
require.Equal(t, correlations.Transformation{Type: "logfmt"}, response.Result.Config.Transformations[0])
require.NoError(t, res.Body.Close())
// partially updating only label