diff --git a/docs/sources/administration/correlations/create-a-new-correlation/index.md b/docs/sources/administration/correlations/create-a-new-correlation/index.md index 485376804b4..9eedf7ed657 100644 --- a/docs/sources/administration/correlations/create-a-new-correlation/index.md +++ b/docs/sources/administration/correlations/create-a-new-correlation/index.md @@ -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) diff --git a/pkg/services/correlations/database.go b/pkg/services/correlations/database.go index cd8361108a3..c9a78cbb042 100644 --- a/pkg/services/correlations/database.go +++ b/pkg/services/correlations/database.go @@ -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 { diff --git a/pkg/services/correlations/models.go b/pkg/services/correlations/models.go index 4e941517a38..5c655db2798 100644 --- a/pkg/services/correlations/models.go +++ b/pkg/services/correlations/models.go @@ -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 ( diff --git a/pkg/services/provisioning/datasources/datasources.go b/pkg/services/provisioning/datasources/datasources.go index 55edd021d00..05c242fb9c4 100644 --- a/pkg/services/provisioning/datasources/datasources.go +++ b/pkg/services/provisioning/datasources/datasources.go @@ -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 diff --git a/pkg/tests/api/correlations/correlations_provisioning_api_test.go b/pkg/tests/api/correlations/correlations_provisioning_api_test.go index e8c1f1a5d8a..2146652f5d4 100644 --- a/pkg/tests/api/correlations/correlations_provisioning_api_test.go +++ b/pkg/tests/api/correlations/correlations_provisioning_api_test.go @@ -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) }) }