From 4b2144fe403e20eac07216291ac29cfff383ddc8 Mon Sep 17 00:00:00 2001 From: Giordano Ricci Date: Wed, 27 Jul 2022 07:01:46 +0100 Subject: [PATCH] Correlations: change casing of *UID properties (#52836) * Correlations: change casing of *UID properties * add link to correlations HTTP API --- devenv/datasources.yaml | 4 +- docs/sources/developers/http_api/_index.md | 1 + .../developers/http_api/correlations.md | 12 +-- pkg/api/docs/definitions/correlations.go | 4 +- pkg/services/correlations/models.go | 6 +- .../datasources/config_reader_test.go | 2 +- .../provisioning/datasources/datasources.go | 6 +- .../all-properties/all-properties.yaml | 2 +- .../one-datasource-two-correlations.yaml | 4 +- .../testdata/version-0/version-0.yaml | 2 +- .../api/correlations/correlations_test.go | 10 +- public/api-merged.json | 92 +++++++++---------- public/api-spec.json | 92 +++++++++---------- 13 files changed, 119 insertions(+), 118 deletions(-) diff --git a/devenv/datasources.yaml b/devenv/datasources.yaml index c742eab6072..11ef5cf9bf2 100644 --- a/devenv/datasources.yaml +++ b/devenv/datasources.yaml @@ -248,10 +248,10 @@ datasources: url: http://localhost:3100 editable: false correlations: - - targetUid: gdev-jaeger + - targetUID: gdev-jaeger label: "Jaeger traces" description: "Related traces stored in Jaeger" - - targetUid: gdev-zipkin + - targetUID: gdev-zipkin label: "Zipkin traces" description: "Related traces stored in Zipkin" jsonData: diff --git a/docs/sources/developers/http_api/_index.md b/docs/sources/developers/http_api/_index.md index 65827a1aeee..ab0a79f5de4 100644 --- a/docs/sources/developers/http_api/_index.md +++ b/docs/sources/developers/http_api/_index.md @@ -25,6 +25,7 @@ dashboards, creating users, and updating data sources. - [Alerting Provisioning API]({{< relref "alerting_provisioning/" >}}) - [Annotations API]({{< relref "annotations/" >}}) - [Authentication API]({{< relref "auth/" >}}) +- [Correlations API]({{< relref "correlations/" >}}) - [Dashboard API]({{< relref "dashboard/" >}}) - [Dashboard Permissions API]({{< relref "dashboard_permissions/" >}}) - [Dashboard Versions API]({{< relref "dashboard_versions/" >}}) diff --git a/docs/sources/developers/http_api/correlations.md b/docs/sources/developers/http_api/correlations.md index d3dde170f02..60a0373b59e 100644 --- a/docs/sources/developers/http_api/correlations.md +++ b/docs/sources/developers/http_api/correlations.md @@ -19,9 +19,9 @@ This API can be used to define correlations between data sources. ## Create correlations -`POST /api/datasources/uid/:sourceUid/correlations` +`POST /api/datasources/uid/:sourceUID/correlations` -Creates a correlation between two data sources - the source data source indicated by the path UID, and the target data source which is specified in the body. +Creates a correlation between two data sources - the source data source identified by `sourceUID` in the path, and the target data source which is specified in the body. **Example request:** @@ -31,7 +31,7 @@ Accept: application/json Content-Type: application/json Authorization: Bearer eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFsNFZXdE9ZWmNrMkZYbk { - "targetUid": "PDDA8E780A17E7EF1", + "targetUID": "PDDA8E780A17E7EF1", "label": "My Label", "description": "Logs to Traces", } @@ -39,7 +39,7 @@ 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. @@ -53,8 +53,8 @@ Content-Type: application/json "result": { "description": "Logs to Traces", "label": "My Label", - "sourceUid": "uyBf2637k", - "targetUid": "PDDA8E780A17E7EF1", + "sourceUID": "uyBf2637k", + "targetUID": "PDDA8E780A17E7EF1", "uid": "50xhMlg9k" } } diff --git a/pkg/api/docs/definitions/correlations.go b/pkg/api/docs/definitions/correlations.go index e1c5a6fce9c..11a70f5e522 100644 --- a/pkg/api/docs/definitions/correlations.go +++ b/pkg/api/docs/definitions/correlations.go @@ -4,7 +4,7 @@ import ( "github.com/grafana/grafana/pkg/services/correlations" ) -// swagger:route POST /datasources/uid/{uid}/correlations correlations createCorrelation +// swagger:route POST /datasources/uid/{sourceUID}/correlations correlations createCorrelation // // Add correlation. // @@ -23,7 +23,7 @@ type CreateCorrelationParams struct { Body correlations.CreateCorrelationCommand `json:"body"` // in:path // required:true - SourceUID string `json:"uid"` + SourceUID string `json:"sourceUID"` } //swagger:response createCorrelationResponse diff --git a/pkg/services/correlations/models.go b/pkg/services/correlations/models.go index 8a006c08699..0ebe9ca87e6 100644 --- a/pkg/services/correlations/models.go +++ b/pkg/services/correlations/models.go @@ -19,10 +19,10 @@ type Correlation struct { UID string `json:"uid" xorm:"pk 'uid'"` // UID of the data source the correlation originates from // example:d0oxYRg4z - SourceUID string `json:"sourceUid" xorm:"pk 'source_uid'"` + SourceUID string `json:"sourceUID" xorm:"pk 'source_uid'"` // UID of the data source the correlation points to // example:PE1C5CBDA0504A6A3 - TargetUID string `json:"targetUid" xorm:"target_uid"` + TargetUID string `json:"targetUID" xorm:"target_uid"` // Label identifying the correlation // example: My Label Label string `json:"label" xorm:"label"` @@ -48,7 +48,7 @@ type CreateCorrelationCommand struct { SkipReadOnlyCheck bool `json:"-"` // Target data source UID to which the correlation is created // example:PE1C5CBDA0504A6A3 - TargetUID string `json:"targetUid" binding:"Required"` + TargetUID string `json:"targetUID" binding:"Required"` // Optional label identifying the correlation // example: My label Label string `json:"label"` diff --git a/pkg/services/provisioning/datasources/config_reader_test.go b/pkg/services/provisioning/datasources/config_reader_test.go index 85e7355782d..b82a21ff5f2 100644 --- a/pkg/services/provisioning/datasources/config_reader_test.go +++ b/pkg/services/provisioning/datasources/config_reader_test.go @@ -309,7 +309,7 @@ func validateDatasource(t *testing.T, dsCfg *configs) { require.Equal(t, ds.Version, 10) require.Equal(t, []map[string]interface{}{{ - "targetUid": "a target", + "targetUID": "a target", "label": "a label", "description": "a description", }}, ds.Correlations) diff --git a/pkg/services/provisioning/datasources/datasources.go b/pkg/services/provisioning/datasources/datasources.go index 93f64cc973a..0ff191b5c3e 100644 --- a/pkg/services/provisioning/datasources/datasources.go +++ b/pkg/services/provisioning/datasources/datasources.go @@ -135,14 +135,14 @@ func (dc *DatasourceProvisioner) applyChanges(ctx context.Context, configPath st } func makeCreateCorrelationCommand(correlation map[string]interface{}, SourceUid string, OrgId int64) (correlations.CreateCorrelationCommand, error) { - targetUid, ok := correlation["targetUid"].(string) + targetUID, ok := correlation["targetUID"].(string) if !ok { - return correlations.CreateCorrelationCommand{}, fmt.Errorf("correlation missing targetUid") + return correlations.CreateCorrelationCommand{}, fmt.Errorf("correlation missing targetUID") } return correlations.CreateCorrelationCommand{ SourceUID: SourceUid, - TargetUID: targetUid, + TargetUID: targetUID, Label: correlation["label"].(string), Description: correlation["description"].(string), OrgId: OrgId, diff --git a/pkg/services/provisioning/datasources/testdata/all-properties/all-properties.yaml b/pkg/services/provisioning/datasources/testdata/all-properties/all-properties.yaml index e0b59def681..e7ff9b43b19 100644 --- a/pkg/services/provisioning/datasources/testdata/all-properties/all-properties.yaml +++ b/pkg/services/provisioning/datasources/testdata/all-properties/all-properties.yaml @@ -13,7 +13,7 @@ datasources: withCredentials: true isDefault: true correlations: - - targetUid: a target + - targetUID: a target label: a label description: a description jsonData: diff --git a/pkg/services/provisioning/datasources/testdata/one-datasource-two-correlations/one-datasource-two-correlations.yaml b/pkg/services/provisioning/datasources/testdata/one-datasource-two-correlations/one-datasource-two-correlations.yaml index d6f257a46d3..eb58683a1ee 100644 --- a/pkg/services/provisioning/datasources/testdata/one-datasource-two-correlations/one-datasource-two-correlations.yaml +++ b/pkg/services/provisioning/datasources/testdata/one-datasource-two-correlations/one-datasource-two-correlations.yaml @@ -7,9 +7,9 @@ datasources: access: proxy url: http://localhost:8080 correlations: - - targetUid: graphite + - targetUID: graphite label: a label description: a description - - targetUid: graphite + - targetUID: graphite label: a second label description: a second description \ No newline at end of file diff --git a/pkg/services/provisioning/datasources/testdata/version-0/version-0.yaml b/pkg/services/provisioning/datasources/testdata/version-0/version-0.yaml index 6b73357c72d..3e2f49c9072 100644 --- a/pkg/services/provisioning/datasources/testdata/version-0/version-0.yaml +++ b/pkg/services/provisioning/datasources/testdata/version-0/version-0.yaml @@ -11,7 +11,7 @@ datasources: with_credentials: true is_default: true correlations: - - targetUid: a target + - targetUID: a target label: a label description: a description json_data: diff --git a/pkg/tests/api/correlations/correlations_test.go b/pkg/tests/api/correlations/correlations_test.go index 8409440ef58..ba2c77f0381 100644 --- a/pkg/tests/api/correlations/correlations_test.go +++ b/pkg/tests/api/correlations/correlations_test.go @@ -125,7 +125,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) { res := ctx.Post(PostParams{ url: fmt.Sprintf("/api/datasources/uid/%s/correlations", "nonexistent-ds-uid"), body: fmt.Sprintf(`{ - "targetUid": "%s" + "targetUID": "%s" }`, writableDs), user: adminUser, }) @@ -148,7 +148,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) { res := ctx.Post(PostParams{ url: fmt.Sprintf("/api/datasources/uid/%s/correlations", writableDs), body: `{ - "targetUid": "nonexistent-uid-uid" + "targetUID": "nonexistent-uid-uid" }`, user: adminUser, }) @@ -171,7 +171,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) { res := ctx.Post(PostParams{ url: fmt.Sprintf("/api/datasources/uid/%s/correlations", readOnlyDS), body: fmt.Sprintf(`{ - "targetUid": "%s" + "targetUID": "%s" }`, readOnlyDS), user: adminUser, }) @@ -194,7 +194,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) { res := ctx.Post(PostParams{ url: fmt.Sprintf("/api/datasources/uid/%s/correlations", writableDs), body: fmt.Sprintf(`{ - "targetUid": "%s" + "targetUID": "%s" }`, readOnlyDS), user: adminUser, }) @@ -222,7 +222,7 @@ func TestIntegrationCreateCorrelation(t *testing.T) { res := ctx.Post(PostParams{ url: fmt.Sprintf("/api/datasources/uid/%s/correlations", writableDs), body: fmt.Sprintf(`{ - "targetUid": "%s", + "targetUID": "%s", "description": "%s", "label": "%s" }`, writableDs, description, label), diff --git a/public/api-merged.json b/public/api-merged.json index 5d59621e810..f8b7bc0726d 100644 --- a/public/api-merged.json +++ b/public/api-merged.json @@ -4140,6 +4140,49 @@ } } }, + "/datasources/uid/{sourceUID}/correlations": { + "post": { + "tags": ["correlations"], + "summary": "Add correlation.", + "operationId": "createCorrelation", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateCorrelationCommand" + } + }, + { + "type": "string", + "name": "sourceUID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/createCorrelationResponse" + }, + "400": { + "$ref": "#/responses/badRequestError" + }, + "401": { + "$ref": "#/responses/unauthorisedError" + }, + "403": { + "$ref": "#/responses/forbiddenError" + }, + "404": { + "$ref": "#/responses/notFoundError" + }, + "500": { + "$ref": "#/responses/internalServerError" + } + } + } + }, "/datasources/uid/{uid}": { "get": { "description": "If you are running Grafana Enterprise and have Fine-grained access control enabled\nyou need to have a permission with action: `datasources:read` and scopes: `datasources:*`, `datasources:uid:*` and `datasources:uid:kLtEtcRGk` (single data source).", @@ -4243,49 +4286,6 @@ } } }, - "/datasources/uid/{uid}/correlations": { - "post": { - "tags": ["correlations"], - "summary": "Add correlation.", - "operationId": "createCorrelation", - "parameters": [ - { - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/CreateCorrelationCommand" - } - }, - { - "type": "string", - "name": "uid", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "$ref": "#/responses/createCorrelationResponse" - }, - "400": { - "$ref": "#/responses/badRequestError" - }, - "401": { - "$ref": "#/responses/unauthorisedError" - }, - "403": { - "$ref": "#/responses/forbiddenError" - }, - "404": { - "$ref": "#/responses/notFoundError" - }, - "500": { - "$ref": "#/responses/internalServerError" - } - } - } - }, "/datasources/uid/{uid}/health": { "get": { "tags": ["datasources"], @@ -10534,12 +10534,12 @@ "type": "string", "example": "My Label" }, - "sourceUid": { + "sourceUID": { "description": "UID of the data source the correlation originates from", "type": "string", "example": "d0oxYRg4z" }, - "targetUid": { + "targetUID": { "description": "UID of the data source the correlation points to", "type": "string", "example": "PE1C5CBDA0504A6A3" @@ -10600,7 +10600,7 @@ "type": "string", "example": "My label" }, - "targetUid": { + "targetUID": { "description": "Target data source UID to which the correlation is created", "type": "string", "example": "PE1C5CBDA0504A6A3" diff --git a/public/api-spec.json b/public/api-spec.json index dd099f04cd3..a6874091cca 100644 --- a/public/api-spec.json +++ b/public/api-spec.json @@ -3559,6 +3559,49 @@ } } }, + "/datasources/uid/{sourceUID}/correlations": { + "post": { + "tags": ["correlations"], + "summary": "Add correlation.", + "operationId": "createCorrelation", + "parameters": [ + { + "name": "body", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/CreateCorrelationCommand" + } + }, + { + "type": "string", + "name": "sourceUID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/createCorrelationResponse" + }, + "400": { + "$ref": "#/responses/badRequestError" + }, + "401": { + "$ref": "#/responses/unauthorisedError" + }, + "403": { + "$ref": "#/responses/forbiddenError" + }, + "404": { + "$ref": "#/responses/notFoundError" + }, + "500": { + "$ref": "#/responses/internalServerError" + } + } + } + }, "/datasources/uid/{uid}": { "get": { "description": "If you are running Grafana Enterprise and have Fine-grained access control enabled\nyou need to have a permission with action: `datasources:read` and scopes: `datasources:*`, `datasources:uid:*` and `datasources:uid:kLtEtcRGk` (single data source).", @@ -3662,49 +3705,6 @@ } } }, - "/datasources/uid/{uid}/correlations": { - "post": { - "tags": ["correlations"], - "summary": "Add correlation.", - "operationId": "createCorrelation", - "parameters": [ - { - "name": "body", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/CreateCorrelationCommand" - } - }, - { - "type": "string", - "name": "uid", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "$ref": "#/responses/createCorrelationResponse" - }, - "400": { - "$ref": "#/responses/badRequestError" - }, - "401": { - "$ref": "#/responses/unauthorisedError" - }, - "403": { - "$ref": "#/responses/forbiddenError" - }, - "404": { - "$ref": "#/responses/notFoundError" - }, - "500": { - "$ref": "#/responses/internalServerError" - } - } - } - }, "/datasources/uid/{uid}/health": { "get": { "tags": ["datasources"], @@ -9566,12 +9566,12 @@ "type": "string", "example": "My Label" }, - "sourceUid": { + "sourceUID": { "description": "UID of the data source the correlation originates from", "type": "string", "example": "d0oxYRg4z" }, - "targetUid": { + "targetUID": { "description": "UID of the data source the correlation points to", "type": "string", "example": "PE1C5CBDA0504A6A3" @@ -9632,7 +9632,7 @@ "type": "string", "example": "My label" }, - "targetUid": { + "targetUID": { "description": "Target data source UID to which the correlation is created", "type": "string", "example": "PE1C5CBDA0504A6A3"