mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Glue: Correlations minor APIs behavior improvements (#56078)
* add correlation config type, CorrelationConfig validator & default values * make config required when creating correlations * make targetUID optional, add validation for createCommand & configType * fix tests * update remaining tests * fix lint error * Update pkg/services/correlations/models.go Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com> * update docs Co-authored-by: Piotr Jamróz <pm.jamroz@gmail.com>
This commit is contained in:
@@ -138,20 +138,19 @@ func (dc *DatasourceProvisioner) applyChanges(ctx context.Context, configPath st
|
||||
|
||||
func makeCreateCorrelationCommand(correlation map[string]interface{}, SourceUID string, OrgId int64) (correlations.CreateCorrelationCommand, error) {
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
targetUID, ok := correlation["targetUID"].(string)
|
||||
if !ok {
|
||||
return correlations.CreateCorrelationCommand{}, fmt.Errorf("correlation missing targetUID")
|
||||
}
|
||||
|
||||
createCommand := correlations.CreateCorrelationCommand{
|
||||
SourceUID: SourceUID,
|
||||
TargetUID: targetUID,
|
||||
Label: correlation["label"].(string),
|
||||
Description: correlation["description"].(string),
|
||||
OrgId: OrgId,
|
||||
SkipReadOnlyCheck: true,
|
||||
}
|
||||
|
||||
targetUID, ok := correlation["targetUID"].(string)
|
||||
if ok {
|
||||
createCommand.TargetUID = &targetUID
|
||||
}
|
||||
|
||||
if correlation["config"] != nil {
|
||||
jsonbody, err := json.Marshal(correlation["config"])
|
||||
if err != nil {
|
||||
@@ -164,6 +163,14 @@ func makeCreateCorrelationCommand(correlation map[string]interface{}, SourceUID
|
||||
}
|
||||
|
||||
createCommand.Config = config
|
||||
} else {
|
||||
// when provisioning correlations without config we default to type="query"
|
||||
createCommand.Config = correlations.CorrelationConfig{
|
||||
Type: correlations.ConfigTypeQuery,
|
||||
}
|
||||
}
|
||||
if err := createCommand.Validate(); err != nil {
|
||||
return correlations.CreateCorrelationCommand{}, err
|
||||
}
|
||||
|
||||
return createCommand, nil
|
||||
|
Reference in New Issue
Block a user