Correlations: Add better handling to correlation type and update documentation (#109922)

* Add better type handling when correlation is created from provisioning and fix documentation

* add external example

* change error when deprecated key is used
This commit is contained in:
Kristina
2025-08-26 10:14:05 -05:00
committed by GitHub
parent fc739de01d
commit 1c587a983f
5 changed files with 24 additions and 13 deletions
@@ -52,8 +52,8 @@ datasources:
- targetUID: uid
label: "test"
description: "..."
type: query
config:
type: "query"
target:
expr: "..."
field: "name"
@@ -64,6 +64,14 @@ datasources:
mapValue: "other"
- type: logfmt
field: "test"
- targetUID: uid2
label: "test 2"
description: "..."
type: external
config:
target:
url: "http://${example}"
field: "name"
```
Description of provisioning properties:
@@ -77,12 +85,12 @@ Description of provisioning properties:
**description**
: Optional description
**type**
: Correlation type. Valid values are "query" for linking to a data source query and "external" for linking to an external URL.
**config**
: Config object
**config.type**
: Correlation type. Valid values are "query" for linking to a data source query and "external" for linking to an external URL.
**config.target**
: [Target query model](#determine-target-query-model-structure)
+1 -1
View File
@@ -30,7 +30,7 @@ func (s CorrelationsService) createCorrelation(ctx context.Context, cmd CreateCo
if correlation.Config.Type == CorrelationType("query") {
correlation.Type = CorrelationType("query")
} else if correlation.Config.Type != "" {
return correlation, ErrInvalidConfigType
return correlation, ErrConfigTypeDeprecated
}
err := s.SQLStore.WithTransactionalDbSession(ctx, func(session *db.Session) error {
+1 -1
View File
@@ -20,7 +20,7 @@ var (
ErrTransformationRegexReqExp = errors.New("regex transformations require expression")
ErrCorrelationsQuotaFailed = errors.New("error getting correlations quota")
ErrCorrelationsQuotaReached = errors.New("correlations quota reached")
ErrInvalidConfigType = errors.New("correlation contains non default value in config.type")
ErrConfigTypeDeprecated = errors.New("config.type is deprecated; please move type to be sibling of config")
)
const (
@@ -194,9 +194,12 @@ func (dc *DatasourceProvisioner) applyChanges(ctx context.Context, configPath st
func makeCreateCorrelationCommand(correlation map[string]any, SourceUID string, OrgId int64) (correlations.CreateCorrelationCommand, error) {
// we look for a correlation type at the root if it is defined, if not use default
// we ignore the legacy config.type value - the only valid value at that version was "query"
var corrType = correlation["type"]
if corrType == nil || corrType == "" {
corrType = correlations.CorrelationType("query")
var corrTypeStr = correlation["type"]
var corrType = correlations.CorrelationType("query")
// if corTypeStr is nil, an empty string, or query, leave it as query
if corrTypeStr == "external" {
corrType = correlations.CorrelationType("external")
}
var json = jsoniter.ConfigCompatibleWithStandardLibrary
@@ -206,7 +209,7 @@ func makeCreateCorrelationCommand(correlation map[string]any, SourceUID string,
Description: correlation["description"].(string),
OrgId: OrgId,
Provisioned: true,
Type: corrType.(correlations.CorrelationType),
Type: corrType,
}
targetUID, ok := correlation["targetUID"].(string)
@@ -230,8 +233,8 @@ func makeCreateCorrelationCommand(correlation map[string]any, SourceUID string,
}
// config.type is a deprecated place for this value. We will default it to "query" for legacy purposes but non-query correlations should have type outside of config
if config.Type != correlations.CorrelationType("query") {
return correlations.CreateCorrelationCommand{}, correlations.ErrInvalidConfigType
if config.Type != "" && config.Type != correlations.CorrelationType("query") {
return correlations.CreateCorrelationCommand{}, correlations.ErrConfigTypeDeprecated
}
createCommand.Config = config
@@ -175,6 +175,6 @@ func TestIntegrationCreateOrUpdateCorrelation(t *testing.T) {
})
require.Error(t, err)
require.ErrorIs(t, err, correlations.ErrInvalidConfigType)
require.ErrorIs(t, err, correlations.ErrConfigTypeDeprecated)
})
}