From be75db3f986b2655604a113844df50cc3fc24d25 Mon Sep 17 00:00:00 2001 From: alen_abeshov Date: Fri, 9 Aug 2024 20:28:32 +0500 Subject: [PATCH] Added tests Signed-off-by: alen_abeshov --- spec/namespaces/observability.yaml | 2 +- spec/namespaces/query.yaml | 6 +- spec/schemas/observability._common.yaml | 5 - spec/schemas/query._common.yaml | 53 ++++++--- tests/observability/datasources.yaml | 101 ++++++++++++---- tests/observability/observability.yaml | 148 ++++++++++++++++++++---- 6 files changed, 247 insertions(+), 68 deletions(-) diff --git a/spec/namespaces/observability.yaml b/spec/namespaces/observability.yaml index cef49e195..3ba01dd70 100644 --- a/spec/namespaces/observability.yaml +++ b/spec/namespaces/observability.yaml @@ -117,7 +117,7 @@ components: content: application/json: schema: - $ref: '../schemas/observability._common.yaml#/components/schemas/ObservabilityObject' + $ref: '../schemas/observability._common.yaml#/components/schemas/ObservabilityObjectList' observability.get_object@404: description: Not Found content: diff --git a/spec/namespaces/query.yaml b/spec/namespaces/query.yaml index 464c2a67e..d3aa2288a 100644 --- a/spec/namespaces/query.yaml +++ b/spec/namespaces/query.yaml @@ -86,14 +86,12 @@ components: application/json: schema: type: string - example: Created DataSource with name my_prometheus query.datasources_update@200: description: Updated content: application/json: schema: type: string - example: Updated DataSource with name my_prometheus query.datasources_update@404: description: Not Found content: @@ -117,8 +115,8 @@ components: content: application/json: schema: - type: string - example: '' + type: object + properties: { } query.datasource_delete@404: description: Not Found content: diff --git a/spec/schemas/observability._common.yaml b/spec/schemas/observability._common.yaml index 68b04f1de..fc8018f55 100644 --- a/spec/schemas/observability._common.yaml +++ b/spec/schemas/observability._common.yaml @@ -43,12 +43,7 @@ components: savedQuery: $ref: '#/components/schemas/SavedQuery' required: - - createdTimeMs - - lastUpdatedTimeMs - objectId - - operationalPanel - - savedQuery - - savedVisualization - tenant OperationalPanel: diff --git a/spec/schemas/query._common.yaml b/spec/schemas/query._common.yaml index 86673a2c1..080c3afa3 100644 --- a/spec/schemas/query._common.yaml +++ b/spec/schemas/query._common.yaml @@ -7,28 +7,38 @@ paths: {} components: schemas: DataSourceList: - type: object - properties: - dataSources: - type: array - items: - $ref: '#/components/schemas/DataSource' - required: - - dataSources + type: array + items: + $ref: '#/components/schemas/DataSource' DataSource: type: object properties: name: type: string - type: + description: + type: string + connector: + type: string + allowedRoles: + type: array + items: + type: string + properties: + type: object + additionalProperties: true + resultIndex: + type: string + status: type: string configuration: $ref: '#/components/schemas/DataSourceConfiguration' required: - - configuration + - connector - name - - type + - properties + - resultIndex + - status DataSourceConfiguration: type: object @@ -96,11 +106,26 @@ components: properties: name: type: string - type: + description: + type: string + connector: + type: string + allowedRoles: + type: array + items: + type: string + properties: + type: object + additionalProperties: true + resultIndex: + type: string + status: type: string configuration: $ref: '#/components/schemas/DataSourceConfiguration' required: - - configuration + - connector - name - - type + - properties + - resultIndex + - status diff --git a/tests/observability/datasources.yaml b/tests/observability/datasources.yaml index 7dfbcda29..5fac36f5b 100644 --- a/tests/observability/datasources.yaml +++ b/tests/observability/datasources.yaml @@ -3,45 +3,100 @@ $schema: ../../json_schemas/test_story.schema.yaml description: Test various operations of the OpenSearch Query Datasources API. prologues: - - path: /_plugins/_query/_datasources + - path: /_plugins/_query/_datasources/{datasource_name} + method: DELETE + parameters: + datasource_name: test_datasource + status: [204, 404] + +chapters: + - synopsis: Create a new query datasource. + path: /_plugins/_query/_datasources method: POST request: payload: name: test_datasource - type: prometheus - configuration: - endpoint: "http://localhost:9090" - credentials: - username: "admin" - password: "admin" -epilogues: - - path: /_plugins/_query/_datasources/test_datasource - method: DELETE - status: [204, 404] -chapters: - - synopsis: Retrieve specific datasource. - path: /_plugins/_query/_datasources/test_datasource + description: '' + connector: PROMETHEUS + allowedRoles: [] + properties: + prometheus.uri: 'http://localhost:9090' + resultIndex: query_execution_result_test_datasource + status: ACTIVE + response: + status: 201 + payload: Created DataSource with name test_datasource + + - synopsis: Retrieve the list of all query datasources. + path: /_plugins/_query/_datasources method: GET response: status: 200 + payload: [] - - synopsis: Update specific datasource. + - synopsis: Retrieve a specific query datasource by name. + path: /_plugins/_query/_datasources/{datasource_name} + method: GET + parameters: + datasource_name: test_datasource + response: + status: 200 + payload: + name: test_datasource + description: '' + connector: PROMETHEUS + allowedRoles: [] + properties: + prometheus.uri: 'http://localhost:9090' + resultIndex: query_execution_result_test_datasource + status: ACTIVE + + - synopsis: Update an existing query datasource. path: /_plugins/_query/_datasources method: PUT request: payload: name: test_datasource - type: prometheus - configuration: - endpoint: "http://localhost:9091" - credentials: - username: "admin" - password: "admin" + description: Updated description + connector: PROMETHEUS + allowedRoles: [] + properties: + prometheus.uri: 'http://localhost:9091' + resultIndex: query_execution_result_test_datasource + status: ACTIVE response: status: 200 + payload: Updated DataSource with name test_datasource - - synopsis: Retrieve list of datasources. - path: /_plugins/_query/_datasources + - synopsis: Retrieve the updated query datasource by name. + path: /_plugins/_query/_datasources/{datasource_name} method: GET + parameters: + datasource_name: test_datasource response: status: 200 + payload: + name: test_datasource + description: Updated description + connector: PROMETHEUS + allowedRoles: [] + properties: + prometheus.uri: 'http://localhost:9091' + resultIndex: query_execution_result_test_datasource + status: ACTIVE + + - synopsis: Delete the query datasource by name. + path: /_plugins/_query/_datasources/{datasource_name} + method: DELETE + parameters: + datasource_name: test_datasource + response: + status: 204 + + +epilogues: + - path: /_plugins/_query/_datasources/{datasource_name} + method: DELETE + parameters: + datasource_name: test_datasource + status: [204, 404] diff --git a/tests/observability/observability.yaml b/tests/observability/observability.yaml index 216dd7734..4498669dd 100644 --- a/tests/observability/observability.yaml +++ b/tests/observability/observability.yaml @@ -3,54 +3,160 @@ $schema: ../../json_schemas/test_story.schema.yaml description: Test various operations of the OpenSearch Observability Object API. prologues: + - path: /_plugins/_observability/object/{object_id} + method: DELETE + parameters: + object_id: test_object + status: [200, 404] - path: /_plugins/_observability/object method: POST request: payload: objectId: test_object - lastUpdatedTimeMs: 1627580400000 - createdTimeMs: 1627580400000 - tenant: test_tenant operationalPanel: name: test_panel visualizations: [] - timeRange: { from: "now-1h", to: "now" } - queryFilter: { query: "", language: "ppl" } + timeRange: + from: now-1h + to: now + queryFilter: + query: '' + language: ppl applicationId: test_app - savedVisualization: { name: "viz1", description: "desc1", query: "", type: "line" } - savedQuery: { name: "query1", description: "desc1", query: "", selected_date_range: { start: "now-1d", end: "now" } } -epilogues: - - path: /_plugins/_observability/object/test_object - method: DELETE - status: [200, 404] + savedVisualization: + name: viz1 + description: desc1 + query: '' + type: line + selected_date_range: + start: now-1d + end: now + text: Last 24 hours + selected_timestamp: + name: timestamp + type: time + selected_fields: + text: field1 + tokens: + - name: field1 + type: text + savedQuery: + name: query1 + description: desc1 + query: '' + selected_date_range: + start: now-1d + end: now + text: Last 24 hours + selected_timestamp: + name: timestamp + type: time + selected_fields: + text: field1 + tokens: + - name: field1 + type: text + status: [200] + chapters: - - synopsis: Retrieve specific Observability object. - path: /_plugins/_observability/object/test_object + - synopsis: Retrieve specific Observability object after creation. + path: /_plugins/_observability/object/{object_id} + id: observatory_object method: GET + parameters: + object_id: test_object response: status: 200 + payload: + startIndex: 0 + totalHits: 1 + totalHitRelation: eq + observabilityObjectList: [] + - synopsis: Update specific Observability object. - path: /_plugins/_observability/object/test_object + path: /_plugins/_observability/object/{object_id} method: PUT + parameters: + object_id: test_object request: payload: objectId: test_object - lastUpdatedTimeMs: 1627580400000 - createdTimeMs: 1627580400000 - tenant: test_tenant + tenant: '' operationalPanel: name: updated_test_panel visualizations: [] - timeRange: { from: "now-1h", to: "now" } - queryFilter: { query: "", language: "ppl" } + timeRange: + from: now-1h + to: now + queryFilter: + query: '' + language: ppl applicationId: test_app - savedVisualization: { name: "viz1", description: "desc1", query: "", type: "line" } - savedQuery: { name: "query1", description: "desc1", query: "", selected_date_range: { start: "now-1d", end: "now" } } + savedVisualization: + name: '[Logs] Count total requests by tags' + description: '' + query: 'source = opensearch_dashboards_sample_data_logs | stats count() by tags' + type: bar + selected_date_range: + start: now/y + end: now + text: '' + selected_timestamp: + name: timestamp + type: timestamp + selected_fields: + text: '' + tokens: [] + savedQuery: + name: query1 + description: desc1 + query: '' + selected_date_range: + start: now-1d + end: now + text: Last 24 hours + selected_timestamp: + name: timestamp + type: time + selected_fields: + text: field1 + tokens: + - name: field1 + type: text + response: + status: 200 + payload: + objectId: test_object + + - synopsis: Retrieve specific Observability object after update. + path: /_plugins/_observability/object/{object_id} + method: GET + parameters: + object_id: test_object response: status: 200 + payload: + startIndex: 0 + totalHits: 1 + totalHitRelation: eq + observabilityObjectList: [] + - synopsis: Retrieve list of Observability objects. path: /_plugins/_observability/object method: GET response: status: 200 + payload: + startIndex: 0 + totalHits: 0 + totalHitRelation: eq + observabilityObjectList: [] + + +epilogues: + - path: /_plugins/_observability/object/{object_id} + method: DELETE + parameters: + object_id: test_object + status: [200, 404]