mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Correlations: Migrate config type to root (#91855)
* WIP
* Validate new field, and add value in provisioning if not defined in correct spot
* Simplify logic, use correct value
* fix tests
* Fix linter errors
* fix swagger and tests
* 😬
* Auto-generation isnt doing this..
* Fix linter
* test if nullable is the issue…
* Change structure on the frontend fields
* Try with backtick
* try programatic quoting
* Try only quote non-ints
* quoting, no backticks
* Remove debugging
This commit is contained in:
@@ -38,8 +38,8 @@ Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk
|
||||
```
|
||||
|
||||
JSON body schema:
|
||||
|
||||
- **targetUID** – Target data source uid.
|
||||
- **targetUID** – Target data source uid.
|
||||
- **label** – A label for the correlation.
|
||||
- **description** – A description for the correlation.
|
||||
|
||||
@@ -65,8 +65,8 @@ Content-Type: application/json
|
||||
`DELETE /api/datasources/uid/:sourceUID/correlations/:correlationUID`
|
||||
|
||||
Deletes a correlation.
|
||||
|
||||
**Example request:**
|
||||
**Example request:**
|
||||
|
||||
```http
|
||||
DELETE /api/datasources/uid/uyBf2637k/correlations/J6gn7d31L HTTP/1.1
|
||||
@@ -153,8 +153,8 @@ Content-Type: application/json
|
||||
|
||||
Status codes:
|
||||
|
||||
- **200** – OK
|
||||
- **401** – Unauthorized
|
||||
- **401** – Unauthorized
|
||||
- **404** – Not found, either source data source or correlation were not found
|
||||
- **500** – Internal error
|
||||
|
||||
@@ -197,8 +197,8 @@ Content-Type: application/json
|
||||
|
||||
- **page** - Optional. Specify which page number to return. Use the limit parameter to specify the number of correlations per page. The default is page 1.
|
||||
- **limit** - Optional. Limits the number of returned correlations per page. The default is 100 correlations per page. The maximum limit is 1000 correlations in a page.
|
||||
- **sourceUID** - Optional. Specify a source datasource UID to filter by. This can be repeated to filter by multiple datasources.
|
||||
|
||||
|
||||
**Example request:**
|
||||
|
||||
```http
|
||||
@@ -239,8 +239,8 @@ Content-Type: application/json
|
||||
"targetUID": "PDDA8E780A17E7EF1",
|
||||
"uid": "J6gn7d31L",
|
||||
"provisioned": false,
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {},
|
||||
}
|
||||
@@ -252,8 +252,8 @@ Content-Type: application/json
|
||||
"targetUID": "P15396BDD62B2BE29",
|
||||
"uid": "uWCpURgVk",
|
||||
"provisioned": false,
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {},
|
||||
}
|
||||
@@ -301,8 +301,8 @@ Content-Type: application/json
|
||||
"targetUID": "PDDA8E780A17E7EF1",
|
||||
"uid": "J6gn7d31L",
|
||||
"provisioned": false,
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {},
|
||||
}
|
||||
@@ -314,8 +314,8 @@ Content-Type: application/json
|
||||
"targetUID": "P15396BDD62B2BE29",
|
||||
"uid": "uWCpURgVk",
|
||||
"provisioned": false,
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {},
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ func (s CorrelationsService) createCorrelation(ctx context.Context, cmd CreateCo
|
||||
Description: cmd.Description,
|
||||
Config: cmd.Config,
|
||||
Provisioned: cmd.Provisioned,
|
||||
Type: cmd.Type,
|
||||
}
|
||||
|
||||
err := s.SQLStore.WithTransactionalDbSession(ctx, func(session *db.Session) error {
|
||||
@@ -131,14 +132,14 @@ func (s CorrelationsService) updateCorrelation(ctx context.Context, cmd UpdateCo
|
||||
correlation.Description = *cmd.Description
|
||||
session.MustCols("description")
|
||||
}
|
||||
if cmd.Type != nil {
|
||||
correlation.Type = *cmd.Type
|
||||
}
|
||||
if cmd.Config != nil {
|
||||
session.MustCols("config")
|
||||
if cmd.Config.Field != nil {
|
||||
correlation.Config.Field = *cmd.Config.Field
|
||||
}
|
||||
if cmd.Config.Type != nil {
|
||||
correlation.Config.Type = *cmd.Config.Type
|
||||
}
|
||||
if cmd.Config.Target != nil {
|
||||
correlation.Config.Target = *cmd.Config.Target
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ const (
|
||||
QuotaTarget quota.Target = "correlations"
|
||||
)
|
||||
|
||||
type CorrelationConfigType string
|
||||
type CorrelationType string
|
||||
|
||||
type Transformation struct {
|
||||
//Enum: regex,logfmt
|
||||
@@ -38,11 +38,11 @@ type Transformation struct {
|
||||
}
|
||||
|
||||
const (
|
||||
ConfigTypeQuery CorrelationConfigType = "query"
|
||||
TypeQuery CorrelationType = "query"
|
||||
)
|
||||
|
||||
func (t CorrelationConfigType) Validate() error {
|
||||
if t != ConfigTypeQuery {
|
||||
func (t CorrelationType) Validate() error {
|
||||
if t != TypeQuery {
|
||||
return fmt.Errorf("%s: \"%s\"", ErrInvalidConfigType, t)
|
||||
}
|
||||
return nil
|
||||
@@ -68,8 +68,9 @@ type CorrelationConfig struct {
|
||||
// example: message
|
||||
Field string `json:"field" binding:"Required"`
|
||||
// Target type
|
||||
// required:true
|
||||
Type CorrelationConfigType `json:"type" binding:"Required"`
|
||||
// This is deprecated: use the type property outside of config
|
||||
// deprecated:true
|
||||
Type CorrelationType `json:"type"`
|
||||
// Target data query
|
||||
// required:true
|
||||
// example: {"prop1":"value1","prop2":"value"}
|
||||
@@ -87,12 +88,10 @@ func (c CorrelationConfig) MarshalJSON() ([]byte, error) {
|
||||
target = map[string]any{}
|
||||
}
|
||||
return json.Marshal(struct {
|
||||
Type CorrelationConfigType `json:"type"`
|
||||
Field string `json:"field"`
|
||||
Target map[string]any `json:"target"`
|
||||
Transformations Transformations `json:"transformations,omitempty"`
|
||||
Field string `json:"field"`
|
||||
Target map[string]any `json:"target"`
|
||||
Transformations Transformations `json:"transformations,omitempty"`
|
||||
}{
|
||||
Type: ConfigTypeQuery,
|
||||
Field: c.Field,
|
||||
Target: target,
|
||||
Transformations: transformations,
|
||||
@@ -124,6 +123,8 @@ type Correlation struct {
|
||||
Config CorrelationConfig `json:"config" xorm:"jsonb config"`
|
||||
// Provisioned True if the correlation was created during provisioning
|
||||
Provisioned bool `json:"provisioned"`
|
||||
// The type of correlation. Currently, only valid value is "query"
|
||||
Type CorrelationType `json:"type" binding:"Required"`
|
||||
}
|
||||
|
||||
type GetCorrelationsResponseBody struct {
|
||||
@@ -147,7 +148,7 @@ type CreateCorrelationCommand struct {
|
||||
// UID of the data source for which correlation is created.
|
||||
SourceUID string `json:"-"`
|
||||
OrgId int64 `json:"-"`
|
||||
// Target data source UID to which the correlation is created. required if config.type = query
|
||||
// Target data source UID to which the correlation is created. required if type = query
|
||||
// example: PE1C5CBDA0504A6A3
|
||||
TargetUID *string `json:"targetUID"`
|
||||
// Optional label identifying the correlation
|
||||
@@ -160,14 +161,16 @@ type CreateCorrelationCommand struct {
|
||||
Config CorrelationConfig `json:"config" binding:"Required"`
|
||||
// True if correlation was created with provisioning. This makes it read-only.
|
||||
Provisioned bool `json:"provisioned"`
|
||||
// correlation type, currently only valid value is "query"
|
||||
Type CorrelationType `json:"type" binding:"Required"`
|
||||
}
|
||||
|
||||
func (c CreateCorrelationCommand) Validate() error {
|
||||
if err := c.Config.Type.Validate(); err != nil {
|
||||
if err := c.Type.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.TargetUID == nil && c.Config.Type == ConfigTypeQuery {
|
||||
return fmt.Errorf("correlations of type \"%s\" must have a targetUID", ConfigTypeQuery)
|
||||
if c.TargetUID == nil && c.Type == TypeQuery {
|
||||
return fmt.Errorf("correlations of type \"%s\" must have a targetUID", TypeQuery)
|
||||
}
|
||||
|
||||
if err := c.Config.Transformations.Validate(); err != nil {
|
||||
@@ -202,8 +205,6 @@ type CorrelationConfigUpdateDTO struct {
|
||||
// Field used to attach the correlation link
|
||||
// example: message
|
||||
Field *string `json:"field"`
|
||||
// Target type
|
||||
Type *CorrelationConfigType `json:"type"`
|
||||
// Target data query
|
||||
// example: {"prop1":"value1","prop2":"value"}
|
||||
Target *map[string]any `json:"target"`
|
||||
@@ -212,16 +213,6 @@ type CorrelationConfigUpdateDTO struct {
|
||||
Transformations []Transformation `json:"transformations"`
|
||||
}
|
||||
|
||||
func (c CorrelationConfigUpdateDTO) Validate() error {
|
||||
if c.Type != nil {
|
||||
if err := c.Type.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateCorrelationCommand is the command for updating a correlation
|
||||
// swagger:model
|
||||
type UpdateCorrelationCommand struct {
|
||||
@@ -238,16 +229,12 @@ type UpdateCorrelationCommand struct {
|
||||
Description *string `json:"description"`
|
||||
// Correlation Configuration
|
||||
Config *CorrelationConfigUpdateDTO `json:"config"`
|
||||
// correlation type
|
||||
Type *CorrelationType `json:"type"`
|
||||
}
|
||||
|
||||
func (c UpdateCorrelationCommand) Validate() error {
|
||||
if c.Config != nil {
|
||||
if err := c.Config.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if c.Label == nil && c.Description == nil && (c.Config == nil || (c.Config.Field == nil && c.Config.Type == nil && c.Config.Target == nil)) {
|
||||
if c.Label == nil && c.Description == nil && c.Type == nil && (c.Config == nil || (c.Config.Field == nil && c.Config.Target == nil)) {
|
||||
return ErrUpdateCorrelationEmptyParams
|
||||
}
|
||||
|
||||
|
||||
@@ -14,13 +14,13 @@ func TestCorrelationModels(t *testing.T) {
|
||||
config := &CorrelationConfig{
|
||||
Field: "field",
|
||||
Target: map[string]any{},
|
||||
Type: ConfigTypeQuery,
|
||||
}
|
||||
cmd := &CreateCorrelationCommand{
|
||||
SourceUID: "some-uid",
|
||||
OrgId: 1,
|
||||
TargetUID: &targetUid,
|
||||
Config: *config,
|
||||
Type: TypeQuery,
|
||||
}
|
||||
|
||||
require.NoError(t, cmd.Validate())
|
||||
@@ -30,7 +30,7 @@ func TestCorrelationModels(t *testing.T) {
|
||||
config := &CorrelationConfig{
|
||||
Field: "field",
|
||||
Target: map[string]any{},
|
||||
Type: ConfigTypeQuery,
|
||||
Type: TypeQuery,
|
||||
}
|
||||
cmd := &CreateCorrelationCommand{
|
||||
SourceUID: "some-uid",
|
||||
@@ -60,7 +60,7 @@ func TestCorrelationModels(t *testing.T) {
|
||||
t.Run("CorrelationConfigType Validate", func(t *testing.T) {
|
||||
t.Run("Successfully validates a correct type", func(t *testing.T) {
|
||||
type test struct {
|
||||
input CorrelationConfigType
|
||||
input CorrelationType
|
||||
assertion require.ErrorAssertionFunc
|
||||
}
|
||||
|
||||
@@ -79,13 +79,12 @@ func TestCorrelationModels(t *testing.T) {
|
||||
t.Run("Applies a default empty object if target is not defined", func(t *testing.T) {
|
||||
config := CorrelationConfig{
|
||||
Field: "field",
|
||||
Type: ConfigTypeQuery,
|
||||
}
|
||||
|
||||
data, err := json.Marshal(config)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.Equal(t, `{"type":"query","field":"field","target":{}}`, string(data))
|
||||
require.Equal(t, `{"field":"field","target":{}}`, string(data))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
@@ -192,6 +192,13 @@ 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.TypeQuery
|
||||
}
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
createCommand := correlations.CreateCorrelationCommand{
|
||||
SourceUID: SourceUID,
|
||||
@@ -199,6 +206,7 @@ func makeCreateCorrelationCommand(correlation map[string]any, SourceUID string,
|
||||
Description: correlation["description"].(string),
|
||||
OrgId: OrgId,
|
||||
Provisioned: true,
|
||||
Type: corrType.(correlations.CorrelationType),
|
||||
}
|
||||
|
||||
targetUID, ok := correlation["targetUID"].(string)
|
||||
@@ -222,11 +230,6 @@ func makeCreateCorrelationCommand(correlation map[string]any, SourceUID string,
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -38,7 +38,6 @@ func addCorrelationsMigrations(mg *Migrator) {
|
||||
// All existing records will have '0' assigned
|
||||
{Name: "org_id", Type: DB_BigInt, IsPrimaryKey: true, Default: "0"},
|
||||
{Name: "source_uid", Type: DB_NVarchar, Length: 40, Nullable: false, IsPrimaryKey: true},
|
||||
// Nullable because in the future we want to have correlations to external resources
|
||||
{Name: "target_uid", Type: DB_NVarchar, Length: 40, Nullable: true},
|
||||
{Name: "label", Type: DB_Text, Nullable: false},
|
||||
{Name: "description", Type: DB_Text, Nullable: false},
|
||||
@@ -63,4 +62,8 @@ func addCorrelationsMigrations(mg *Migrator) {
|
||||
mg.AddMigration("add provisioning column", NewAddColumnMigration(correlationsV2, &Column{
|
||||
Name: "provisioned", Type: DB_Bool, Nullable: false, Default: "0",
|
||||
}))
|
||||
|
||||
mg.AddMigration("add type column", NewAddColumnMigration(correlationsV2, &Column{
|
||||
Name: "type", Type: DB_NVarchar, Length: 40, Nullable: false, Default: "'query'",
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ func populateDB(t *testing.T, db db.DB, cfg *setting.Cfg) {
|
||||
Config: correlations.CorrelationConfig{
|
||||
Field: "field",
|
||||
Target: map[string]any{},
|
||||
Type: correlations.ConfigTypeQuery,
|
||||
Type: correlations.TypeQuery,
|
||||
},
|
||||
}
|
||||
correlation, err := correlationsSvc.CreateCorrelation(context.Background(), cmd)
|
||||
|
||||
@@ -115,8 +115,8 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
url: fmt.Sprintf("/api/datasources/uid/%s/correlations", "nonexistent-ds-uid"),
|
||||
body: fmt.Sprintf(`{
|
||||
"targetUID": "%s",
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {}
|
||||
}
|
||||
@@ -137,13 +137,13 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
require.NoError(t, res.Body.Close())
|
||||
})
|
||||
|
||||
t.Run("inexistent target data source should result in a 404 if config.type=query", func(t *testing.T) {
|
||||
t.Run("inexistent target data source should result in a 404 if type=query", func(t *testing.T) {
|
||||
res := ctx.Post(PostParams{
|
||||
url: fmt.Sprintf("/api/datasources/uid/%s/correlations", writableDs),
|
||||
body: `{
|
||||
"targetUID": "nonexistent-uid-uid",
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {}
|
||||
}
|
||||
@@ -169,8 +169,8 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
url: fmt.Sprintf("/api/datasources/uid/%s/correlations", readOnlyDS),
|
||||
body: fmt.Sprintf(`{
|
||||
"targetUID": "%s",
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {}
|
||||
}
|
||||
@@ -200,8 +200,8 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
url: fmt.Sprintf("/api/datasources/uid/%s/correlations", writableDs),
|
||||
body: fmt.Sprintf(`{
|
||||
"targetUID": "%s",
|
||||
"type": "query",
|
||||
"config": {
|
||||
"type": "query",
|
||||
"field": "message",
|
||||
"target": {}
|
||||
}
|
||||
@@ -230,7 +230,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
description := "a description"
|
||||
label := "a label"
|
||||
fieldName := "fieldName"
|
||||
configType := correlations.ConfigTypeQuery
|
||||
corrType := correlations.TypeQuery
|
||||
transformation := correlations.Transformation{Type: "logfmt"}
|
||||
transformation2 := correlations.Transformation{Type: "regex", Expression: "testExpression", MapValue: "testVar"}
|
||||
res := ctx.Post(PostParams{
|
||||
@@ -239,8 +239,8 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
"targetUID": "%s",
|
||||
"description": "%s",
|
||||
"label": "%s",
|
||||
"type": "%s",
|
||||
"config": {
|
||||
"type": "%s",
|
||||
"field": "%s",
|
||||
"target": { "expr": "foo" },
|
||||
"transformations": [
|
||||
@@ -248,7 +248,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
{"type": "regex", "expression": "testExpression", "mapValue": "testVar"}
|
||||
]
|
||||
}
|
||||
}`, writableDs, description, label, configType, fieldName),
|
||||
}`, writableDs, description, label, corrType, fieldName),
|
||||
user: adminUser,
|
||||
})
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
@@ -265,7 +265,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) {
|
||||
require.Equal(t, writableDs, *response.Result.TargetUID)
|
||||
require.Equal(t, description, response.Result.Description)
|
||||
require.Equal(t, label, response.Result.Label)
|
||||
require.Equal(t, configType, response.Result.Config.Type)
|
||||
require.Equal(t, corrType, response.Result.Type)
|
||||
require.Equal(t, fieldName, response.Result.Config.Field)
|
||||
require.Equal(t, map[string]any{"expr": "foo"}, response.Result.Config.Target)
|
||||
require.Equal(t, transformation, response.Result.Config.Transformations[0])
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestIntegrationCreateOrUpdateCorrelation(t *testing.T) {
|
||||
OrgId: dataSource.OrgID,
|
||||
Label: "needs migration",
|
||||
Config: correlations.CorrelationConfig{
|
||||
Type: correlations.ConfigTypeQuery,
|
||||
Type: correlations.TypeQuery,
|
||||
Field: "foo",
|
||||
Target: map[string]any{},
|
||||
Transformations: []correlations.Transformation{
|
||||
@@ -55,7 +55,7 @@ func TestIntegrationCreateOrUpdateCorrelation(t *testing.T) {
|
||||
OrgId: dataSource.OrgID,
|
||||
Label: "existing",
|
||||
Config: correlations.CorrelationConfig{
|
||||
Type: correlations.ConfigTypeQuery,
|
||||
Type: correlations.TypeQuery,
|
||||
Field: "foo",
|
||||
Target: map[string]any{},
|
||||
Transformations: []correlations.Transformation{
|
||||
|
||||
@@ -77,8 +77,8 @@ func TestIntegrationReadCorrelation(t *testing.T) {
|
||||
SourceUID: dsWithCorrelations.UID,
|
||||
TargetUID: &dsWithCorrelations.UID,
|
||||
OrgId: dsWithCorrelations.OrgID,
|
||||
Type: correlations.TypeQuery,
|
||||
Config: correlations.CorrelationConfig{
|
||||
Type: correlations.ConfigTypeQuery,
|
||||
Field: "foo",
|
||||
Target: map[string]any{},
|
||||
Transformations: []correlations.Transformation{
|
||||
|
||||
@@ -263,9 +263,9 @@ func TestIntegrationUpdateCorrelation(t *testing.T) {
|
||||
body: `{
|
||||
"label": "1",
|
||||
"description": "1",
|
||||
"type": "query",
|
||||
"config": {
|
||||
"field": "field",
|
||||
"type": "query",
|
||||
"target": { "expr": "bar" },
|
||||
"transformations": [ {"type": "logfmt"} ]
|
||||
}
|
||||
|
||||
@@ -3330,15 +3330,9 @@
|
||||
},
|
||||
"transformations": {
|
||||
"$ref": "#/definitions/Transformations"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/CorrelationConfigType"
|
||||
}
|
||||
}
|
||||
},
|
||||
"CorrelationConfigType": {
|
||||
"type": "string"
|
||||
},
|
||||
"CorrelationConfigUpdateDTO": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -3372,9 +3366,6 @@
|
||||
"variable": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/CorrelationConfigType"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -13839,6 +13839,9 @@
|
||||
"type": "string",
|
||||
"example": "PE1C5CBDA0504A6A3"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/CorrelationType"
|
||||
},
|
||||
"uid": {
|
||||
"description": "Unique identifier of the correlation",
|
||||
"type": "string",
|
||||
@@ -13850,7 +13853,6 @@
|
||||
"type": "object",
|
||||
"required": [
|
||||
"field",
|
||||
"type",
|
||||
"target"
|
||||
],
|
||||
"properties": {
|
||||
@@ -13872,13 +13874,10 @@
|
||||
"$ref": "#/definitions/Transformations"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/CorrelationConfigType"
|
||||
"$ref": "#/definitions/CorrelationType"
|
||||
}
|
||||
}
|
||||
},
|
||||
"CorrelationConfigType": {
|
||||
"type": "string"
|
||||
},
|
||||
"CorrelationConfigUpdateDTO": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
@@ -13912,12 +13911,12 @@
|
||||
"variable": "name"
|
||||
}
|
||||
]
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/CorrelationConfigType"
|
||||
}
|
||||
}
|
||||
},
|
||||
"CorrelationType": {
|
||||
"type": "string"
|
||||
},
|
||||
"CounterResetHint": {
|
||||
"description": "or alternatively that we are dealing with a gauge histogram, where counter resets do not apply.",
|
||||
"type": "integer",
|
||||
@@ -13954,9 +13953,12 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"targetUID": {
|
||||
"description": "Target data source UID to which the correlation is created. required if config.type = query",
|
||||
"description": "Target data source UID to which the correlation is created. required if type = query",
|
||||
"type": "string",
|
||||
"example": "PE1C5CBDA0504A6A3"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/CorrelationType"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -21419,6 +21421,9 @@
|
||||
"description": "Optional label identifying the correlation",
|
||||
"type": "string",
|
||||
"example": "My label"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/definitions/CorrelationType"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -361,10 +361,10 @@ describe('CorrelationsPage', () => {
|
||||
uid: '1',
|
||||
label: 'Some label',
|
||||
provisioned: false,
|
||||
type: 'query',
|
||||
config: {
|
||||
field: 'line',
|
||||
target: {},
|
||||
type: 'query',
|
||||
transformations: [
|
||||
{ type: SupportedTransformationType.Regex, expression: 'url=http[s]?://(S*)', mapValue: 'path' },
|
||||
],
|
||||
@@ -375,7 +375,8 @@ describe('CorrelationsPage', () => {
|
||||
targetUID: 'loki',
|
||||
uid: '2',
|
||||
label: 'Prometheus to Loki',
|
||||
config: { field: 'label', target: {}, type: 'query' },
|
||||
type: 'query',
|
||||
config: { field: 'label', target: {} },
|
||||
provisioned: false,
|
||||
},
|
||||
]
|
||||
@@ -598,10 +599,10 @@ describe('CorrelationsPage', () => {
|
||||
uid: '1',
|
||||
label: 'Loki to Loki',
|
||||
provisioned: false,
|
||||
type: 'query',
|
||||
config: {
|
||||
field: 'line',
|
||||
target: {},
|
||||
type: 'query',
|
||||
transformations: [
|
||||
{ type: SupportedTransformationType.Regex, expression: 'url=http[s]?://(S*)', mapValue: 'path' },
|
||||
],
|
||||
@@ -613,10 +614,10 @@ describe('CorrelationsPage', () => {
|
||||
uid: '2',
|
||||
label: 'Loki to Prometheus',
|
||||
provisioned: false,
|
||||
type: 'query',
|
||||
config: {
|
||||
field: 'line',
|
||||
target: {},
|
||||
type: 'query',
|
||||
transformations: [
|
||||
{ type: SupportedTransformationType.Regex, expression: 'url=http[s]?://(S*)', mapValue: 'path' },
|
||||
],
|
||||
@@ -627,7 +628,8 @@ describe('CorrelationsPage', () => {
|
||||
targetUID: 'loki',
|
||||
uid: '3',
|
||||
label: 'Prometheus to Loki',
|
||||
config: { field: 'label', target: {}, type: 'query' },
|
||||
type: 'query',
|
||||
config: { field: 'label', target: {} },
|
||||
provisioned: false,
|
||||
},
|
||||
{
|
||||
@@ -635,7 +637,8 @@ describe('CorrelationsPage', () => {
|
||||
targetUID: 'prometheus',
|
||||
uid: '4',
|
||||
label: 'Prometheus to Prometheus',
|
||||
config: { field: 'label', target: {}, type: 'query' },
|
||||
type: 'query',
|
||||
config: { field: 'label', target: {} },
|
||||
provisioned: false,
|
||||
},
|
||||
]
|
||||
@@ -660,10 +663,10 @@ describe('CorrelationsPage', () => {
|
||||
uid: '1',
|
||||
label: 'Some label',
|
||||
provisioned: true,
|
||||
type: 'query',
|
||||
config: {
|
||||
field: 'line',
|
||||
target: {},
|
||||
type: 'query',
|
||||
transformations: [{ type: SupportedTransformationType.Regex, expression: '(?:msg)=' }],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -44,7 +44,7 @@ export const AddCorrelationForm = ({ onClose, onCreated }: Props) => {
|
||||
}
|
||||
}, [error, loading, value, onCreated]);
|
||||
|
||||
const defaultValues: Partial<FormDTO> = { config: { type: 'query', target: {}, field: '' } };
|
||||
const defaultValues: Partial<FormDTO> = { type: 'query', config: { target: {}, field: '' } };
|
||||
|
||||
return (
|
||||
<PanelContainer className={styles.panelContainer}>
|
||||
|
||||
@@ -29,7 +29,7 @@ export const ConfigureCorrelationBasicInfoForm = () => {
|
||||
<Trans i18nKey="correlations.basic-info-form.sub-text">
|
||||
<p>Define text that will describe the correlation.</p>
|
||||
</Trans>
|
||||
<input type="hidden" {...register('config.type')} />
|
||||
<input type="hidden" {...register('type')} />
|
||||
<Field
|
||||
label={t('correlations.basic-info-form.label-label', 'Label')}
|
||||
description={t(
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { SupportedTransformationType } from '@grafana/data';
|
||||
import { t } from 'app/core/internationalization';
|
||||
|
||||
import { CorrelationConfig } from '../types';
|
||||
import { CorrelationConfig, CorrelationType } from '../types';
|
||||
|
||||
export interface FormDTO {
|
||||
sourceUID: string;
|
||||
targetUID: string;
|
||||
label: string;
|
||||
description: string;
|
||||
type: CorrelationType;
|
||||
config: CorrelationConfig;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,11 @@ export interface RemoveCorrelationResponse {
|
||||
message: string;
|
||||
}
|
||||
|
||||
type CorrelationConfigType = 'query';
|
||||
export type CorrelationType = 'query';
|
||||
|
||||
export interface CorrelationConfig {
|
||||
field: string;
|
||||
target: object; // this contains anything that would go in the query editor, so any extension off DataQuery a datasource would have, and needs to be generic
|
||||
type: CorrelationConfigType;
|
||||
transformations?: DataLinkTransformationConfig[];
|
||||
}
|
||||
|
||||
@@ -44,6 +43,7 @@ export interface Correlation {
|
||||
provisioned: boolean;
|
||||
orgId?: number;
|
||||
config: CorrelationConfig;
|
||||
type: CorrelationType;
|
||||
}
|
||||
|
||||
export type GetCorrelationsParams = {
|
||||
|
||||
@@ -111,7 +111,8 @@ function setup() {
|
||||
label: 'logs to metrics',
|
||||
source: loki,
|
||||
target: prometheus,
|
||||
config: { type: 'query', field: 'traceId', target: { expr: 'target Prometheus query' } },
|
||||
type: 'query',
|
||||
config: { field: 'traceId', target: { expr: 'target Prometheus query' } },
|
||||
provisioned: false,
|
||||
},
|
||||
// Test multiple correlations attached to the same field
|
||||
@@ -120,7 +121,8 @@ function setup() {
|
||||
label: 'logs to logs',
|
||||
source: loki,
|
||||
target: elastic,
|
||||
config: { type: 'query', field: 'traceId', target: { expr: 'target Elastic query' } },
|
||||
type: 'query',
|
||||
config: { field: 'traceId', target: { expr: 'target Elastic query' } },
|
||||
provisioned: false,
|
||||
},
|
||||
{
|
||||
@@ -128,7 +130,8 @@ function setup() {
|
||||
label: 'metrics to logs',
|
||||
source: prometheus,
|
||||
target: elastic,
|
||||
config: { type: 'query', field: 'value', target: { expr: 'target Elastic query' } },
|
||||
type: 'query',
|
||||
config: { field: 'value', target: { expr: 'target Elastic query' } },
|
||||
provisioned: false,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -81,10 +81,10 @@ export function saveCurrentCorrelation(
|
||||
targetUID: targetDatasource.uid,
|
||||
label: label || (await generateDefaultLabel(sourcePane, targetPane)),
|
||||
description,
|
||||
type: 'query',
|
||||
config: {
|
||||
field: targetPane.correlationEditorHelperData.resultField,
|
||||
target: targetPane.queries[0],
|
||||
type: 'query',
|
||||
transformations: transformations,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -3898,6 +3898,9 @@
|
||||
"example": "PE1C5CBDA0504A6A3",
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/components/schemas/CorrelationType"
|
||||
},
|
||||
"uid": {
|
||||
"description": "Unique identifier of the correlation",
|
||||
"example": "50xhMlg9k",
|
||||
@@ -3926,19 +3929,15 @@
|
||||
"$ref": "#/components/schemas/Transformations"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/components/schemas/CorrelationConfigType"
|
||||
"$ref": "#/components/schemas/CorrelationType"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"field",
|
||||
"type",
|
||||
"target"
|
||||
],
|
||||
"type": "object"
|
||||
},
|
||||
"CorrelationConfigType": {
|
||||
"type": "string"
|
||||
},
|
||||
"CorrelationConfigUpdateDTO": {
|
||||
"properties": {
|
||||
"field": {
|
||||
@@ -3971,13 +3970,13 @@
|
||||
"$ref": "#/components/schemas/Transformation"
|
||||
},
|
||||
"type": "array"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/components/schemas/CorrelationConfigType"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
},
|
||||
"CorrelationType": {
|
||||
"type": "string"
|
||||
},
|
||||
"CounterResetHint": {
|
||||
"description": "or alternatively that we are dealing with a gauge histogram, where counter resets do not apply.",
|
||||
"format": "uint8",
|
||||
@@ -4013,9 +4012,12 @@
|
||||
"type": "boolean"
|
||||
},
|
||||
"targetUID": {
|
||||
"description": "Target data source UID to which the correlation is created. required if config.type = query",
|
||||
"description": "Target data source UID to which the correlation is created. required if type = query",
|
||||
"example": "PE1C5CBDA0504A6A3",
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/components/schemas/CorrelationType"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
@@ -11477,6 +11479,9 @@
|
||||
"description": "Optional label identifying the correlation",
|
||||
"example": "My label",
|
||||
"type": "string"
|
||||
},
|
||||
"type": {
|
||||
"$ref": "#/components/schemas/CorrelationType"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
||||
Reference in New Issue
Block a user