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:
@@ -271,7 +271,8 @@ func TestDatasourceAsConfig(t *testing.T) {
|
||||
t.Run("Deleting datasource deletes existing correlations", func(t *testing.T) {
|
||||
store := &spyStore{items: []*datasources.DataSource{{Name: "old-data-source", OrgId: 1, Id: 1, Uid: "some-uid"}}}
|
||||
orgStore := &mockOrgStore{}
|
||||
correlationsStore := &mockCorrelationsStore{items: []correlations.Correlation{{UID: "some-uid", SourceUID: "some-uid", TargetUID: "target-uid"}}}
|
||||
targetUid := "target-uid"
|
||||
correlationsStore := &mockCorrelationsStore{items: []correlations.Correlation{{UID: "some-uid", SourceUID: "some-uid", TargetUID: &targetUid}}}
|
||||
dc := newDatasourceProvisioner(logger, store, correlationsStore, orgStore)
|
||||
err := dc.applyChanges(context.Background(), deleteOneDatasource)
|
||||
if err != nil {
|
||||
|
||||
@@ -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