mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Glue: Add DB migration & support provisioning for user-defined correlations config (#55560)
* Allow provisioning correlation config * Simplify code * Fix reading correlations test * Fix linting errors * Fix linting errors * remove simpleJson * Clean up * Fix tests * Update swagger docs * Fix linting * Fix linting * Clean up swagger definitions Co-authored-by: Elfo404 <me@giordanoricci.com>
This commit is contained in:
@@ -5,6 +5,8 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/correlations"
|
||||
"github.com/grafana/grafana/pkg/services/datasources"
|
||||
@@ -134,20 +136,37 @@ func (dc *DatasourceProvisioner) applyChanges(ctx context.Context, configPath st
|
||||
return nil
|
||||
}
|
||||
|
||||
func makeCreateCorrelationCommand(correlation map[string]interface{}, SourceUid string, OrgId int64) (correlations.CreateCorrelationCommand, error) {
|
||||
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")
|
||||
}
|
||||
|
||||
return correlations.CreateCorrelationCommand{
|
||||
SourceUID: SourceUid,
|
||||
createCommand := correlations.CreateCorrelationCommand{
|
||||
SourceUID: SourceUID,
|
||||
TargetUID: targetUID,
|
||||
Label: correlation["label"].(string),
|
||||
Description: correlation["description"].(string),
|
||||
OrgId: OrgId,
|
||||
SkipReadOnlyCheck: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
if correlation["config"] != nil {
|
||||
jsonbody, err := json.Marshal(correlation["config"])
|
||||
if err != nil {
|
||||
return correlations.CreateCorrelationCommand{}, err
|
||||
}
|
||||
|
||||
config := correlations.CorrelationConfig{}
|
||||
if err := json.Unmarshal(jsonbody, &config); err != nil {
|
||||
return correlations.CreateCorrelationCommand{}, err
|
||||
}
|
||||
|
||||
createCommand.Config = config
|
||||
}
|
||||
|
||||
return createCommand, nil
|
||||
}
|
||||
|
||||
func (dc *DatasourceProvisioner) deleteDatasources(ctx context.Context, dsToDelete []*deleteDatasourceConfig) error {
|
||||
|
Reference in New Issue
Block a user