From 0ce12257874800101827d9cc24be46032ef42bdc Mon Sep 17 00:00:00 2001 From: Shamcle Ren Date: Wed, 28 Feb 2024 14:34:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E6=8E=A5=E5=8F=A3=20--story=3D116308311=20(#?= =?UTF-8?q?222)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/unify-query/Makefile | 2 +- pkg/unify-query/docs/docs.go | 742 +++++++++++++++++- pkg/unify-query/docs/swagger.json | 726 ++++++++++++++++- pkg/unify-query/docs/swagger.yaml | 491 +++++++++++- pkg/unify-query/go.mod | 2 +- pkg/unify-query/main.go | 8 +- pkg/unify-query/service/http/api.go | 67 +- pkg/unify-query/service/http/api/api.go | 4 +- pkg/unify-query/service/http/api/response.go | 2 +- pkg/unify-query/service/http/check_handler.go | 210 +++++ pkg/unify-query/service/http/handler.go | 52 +- pkg/unify-query/service/http/hook.go | 3 + pkg/unify-query/service/http/info.go | 2 + pkg/unify-query/service/http/register_urls.go | 18 +- pkg/unify-query/service/http/service.go | 2 +- pkg/unify-query/service/http/settings.go | 3 + pkg/unify-query/swagger/swagger.go | 557 ------------- pkg/unify-query/swagger/swagger.json | 527 ------------- pkg/unify-query/swagger/swagger.yaml | 364 --------- 19 files changed, 2223 insertions(+), 1559 deletions(-) create mode 100644 pkg/unify-query/service/http/check_handler.go delete mode 100644 pkg/unify-query/swagger/swagger.go delete mode 100644 pkg/unify-query/swagger/swagger.json delete mode 100644 pkg/unify-query/swagger/swagger.yaml diff --git a/pkg/unify-query/Makefile b/pkg/unify-query/Makefile index 2e6c8d31d..27e901e6b 100644 --- a/pkg/unify-query/Makefile +++ b/pkg/unify-query/Makefile @@ -33,7 +33,7 @@ test: .PHONY: swag swag: - swag init --parseDependency --parseInternal + swag init --parseDependency true --parseInternal true .PHONY: fmt fmt: diff --git a/pkg/unify-query/docs/docs.go b/pkg/unify-query/docs/docs.go index a794eceb4..3af98861a 100644 --- a/pkg/unify-query/docs/docs.go +++ b/pkg/unify-query/docs/docs.go @@ -1,8 +1,18 @@ -// Code generated by swaggo/swag. DO NOT EDIT. +// Tencent is pleased to support the open source community by making +// 蓝鲸智云 - 监控平台 (BlueKing - Monitor) available. +// Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. +// Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at http://opensource.org/licenses/MIT +// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. +// Package docs Code generated by swaggo/swag. DO NOT EDIT package docs -import "github.com/swaggo/swag" +import ( + "github.com/swaggo/swag" +) const docTemplate = `{ "schemes": {{ marshal .Schemes }}, @@ -22,7 +32,7 @@ const docTemplate = `{ "application/json" ], "summary": "query relation multi resource", - "operationId": "api-relation-multi-resource", + "operationId": "relation_multi_resource_query", "parameters": [ { "type": "string", @@ -64,13 +74,435 @@ const docTemplate = `{ } } }, + "/api/v1/relation/multi_resource_range": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query relation multi resource", + "operationId": "relation_multi_resource_query_range", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/cmdb.RelationMultiResourceRangeRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/cmdb.RelationMultiResourceRangeResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/api.ErrResponse" + } + } + } + } + }, + "/check/query/ts": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query promql monitor check by ts", + "operationId": "check-query-promql", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryPromQL" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.CheckResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/promql": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query monitor by promql", + "operationId": "query_promql", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryPromQL" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.PromData" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, "/query/ts": { "post": { "produces": [ "application/json" ], - "summary": "query monitor by ts", - "operationId": "ts-query-request", + "summary": "query monitor by ts", + "operationId": "query_ts", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryTs" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.PromData" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/exemplar": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query monitor by ts exemplar", + "operationId": "query_ts_exemplar", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryTs" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.PromData" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/info/field_keys": { + "post": { + "produces": [ + "application/json" + ], + "summary": "info field keys", + "operationId": "info_field_keys", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/infos.Params" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/info/series": { + "post": { + "produces": [ + "application/json" + ], + "summary": "info series", + "operationId": "info_series", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/infos.Params" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/http.SeriesData" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/info/tag_keys": { + "post": { + "produces": [ + "application/json" + ], + "summary": "info tag keys", + "operationId": "info_tag_keys", "parameters": [ { "type": "string", @@ -93,13 +525,20 @@ const docTemplate = `{ "name": "X-Bk-Scope-Space-Uid", "in": "header" }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, { "description": "json data", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/structured.QueryTs" + "$ref": "#/definitions/infos.Params" } } ], @@ -107,7 +546,13 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } } }, "400": { @@ -119,13 +564,13 @@ const docTemplate = `{ } } }, - "/query/ts/exemplar": { + "/query/ts/info/tag_values": { "post": { "produces": [ "application/json" ], - "summary": "query monitor by ts exemplar", - "operationId": "ts-query-exemplar-request", + "summary": "info tag values", + "operationId": "info_tag_values", "parameters": [ { "type": "string", @@ -148,13 +593,20 @@ const docTemplate = `{ "name": "X-Bk-Scope-Space-Uid", "in": "header" }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, { "description": "json data", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/structured.QueryTs" + "$ref": "#/definitions/infos.Params" } } ], @@ -162,7 +614,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "$ref": "#/definitions/http.TagValuesData" } }, "400": { @@ -174,13 +626,13 @@ const docTemplate = `{ } } }, - "/query/ts/promql": { - "post": { + "/query/ts/label/{label_name}/values": { + "get": { "produces": [ "application/json" ], - "summary": "query monitor by promql", - "operationId": "ts-query-request-promql", + "summary": "info label values", + "operationId": "info_label_values", "parameters": [ { "type": "string", @@ -203,13 +655,20 @@ const docTemplate = `{ "name": "X-Bk-Scope-Space-Uid", "in": "header" }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, { "description": "json data", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/structured.QueryPromQL" + "$ref": "#/definitions/infos.Params" } } ], @@ -217,7 +676,13 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } } }, "400": { @@ -235,7 +700,7 @@ const docTemplate = `{ "application/json" ], "summary": "promql to struct", - "operationId": "promql-to-struct", + "operationId": "transform_promql_to_struct", "parameters": [ { "type": "string", @@ -272,7 +737,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "$ref": "#/definitions/structured.QueryTs" } }, "400": { @@ -290,7 +755,7 @@ const docTemplate = `{ "application/json" ], "summary": "query struct to promql", - "operationId": "struct-to-promql", + "operationId": "transform_struct_to_promql", "parameters": [ { "type": "string", @@ -327,7 +792,7 @@ const docTemplate = `{ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "$ref": "#/definitions/structured.QueryPromQL" } }, "400": { @@ -355,6 +820,88 @@ const docTemplate = `{ "type": "string" } }, + "cmdb.MatchersWithTimestamp": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/cmdb.Matcher" + } + }, + "timestamp": { + "type": "integer" + } + } + }, + "cmdb.RelationMultiResourceRangeRequest": { + "type": "object", + "properties": { + "query_list": { + "type": "array", + "items": { + "type": "object", + "properties": { + "end_time": { + "type": "integer" + }, + "look_back_delta": { + "type": "string" + }, + "source_info": { + "$ref": "#/definitions/cmdb.Matcher" + }, + "start_time": { + "type": "integer" + }, + "step": { + "type": "string" + }, + "target_type": { + "type": "string" + } + } + } + } + } + }, + "cmdb.RelationMultiResourceRangeResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/cmdb.RelationMultiResourceRangeResponseData" + } + } + } + }, + "cmdb.RelationMultiResourceRangeResponseData": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "source_info": { + "$ref": "#/definitions/cmdb.Matcher" + }, + "source_type": { + "type": "string" + }, + "target_list": { + "type": "array", + "items": { + "$ref": "#/definitions/cmdb.MatchersWithTimestamp" + } + }, + "target_type": { + "type": "string" + } + } + }, "cmdb.RelationMultiResourceRequest": { "type": "object", "properties": { @@ -428,6 +975,29 @@ const docTemplate = `{ } } }, + "http.CheckItem": { + "type": "object", + "properties": { + "error": {}, + "json_data": { + "type": "string" + }, + "step_name": { + "type": "string" + } + } + }, + "http.CheckResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/http.CheckItem" + } + } + } + }, "http.ErrResponse": { "type": "object", "properties": { @@ -450,6 +1020,29 @@ const docTemplate = `{ } } }, + "http.SeriesData": { + "type": "object", + "properties": { + "keys": { + "type": "array", + "items": { + "type": "string" + } + }, + "measurement": { + "type": "string" + }, + "series": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, "http.TablesItem": { "type": "object", "properties": { @@ -492,6 +1085,55 @@ const docTemplate = `{ } } }, + "http.TagValuesData": { + "type": "object", + "properties": { + "values": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "infos.Params": { + "type": "object", + "properties": { + "conditions": { + "$ref": "#/definitions/structured.Conditions" + }, + "data_source": { + "type": "string" + }, + "end_time": { + "type": "string" + }, + "keys": { + "type": "array", + "items": { + "type": "string" + } + }, + "limit": { + "type": "integer" + }, + "metric_name": { + "type": "string" + }, + "slimit": { + "type": "integer" + }, + "start_time": { + "type": "string" + }, + "table_id": { + "type": "string" + } + } + }, "structured.AggregateMethod": { "type": "object", "properties": { @@ -506,11 +1148,20 @@ const docTemplate = `{ "bk_target_cloud_id" ] }, + "is_sub_query": { + "description": "IsSubQuery 判断是否为子查询", + "type": "boolean" + }, "method": { "description": "Method 聚合方法", "type": "string", "example": "mean" }, + "window": { + "description": "Window 聚合周期", + "type": "string", + "example": "60s" + }, "without": { "description": "Without", "type": "boolean" @@ -598,6 +1249,11 @@ const docTemplate = `{ "$ref": "#/definitions/structured.AggregateMethod" } }, + "is_regexp": { + "description": "IsRegexp 指标是否使用正则查询", + "type": "boolean", + "example": false + }, "limit": { "description": "Limit 点数限制数量", "type": "integer", @@ -663,6 +1319,11 @@ const docTemplate = `{ "type": "string" } }, + "down_sample_range": { + "description": "DownSampleRange 降采样:大于Step才能生效,可以为空", + "type": "string", + "example": "5m" + }, "end": { "type": "string" }, @@ -768,6 +1429,14 @@ const docTemplate = `{ "type": "string", "example": "avg_over_time" }, + "is_sub_query": { + "description": "IsSubQuery 判断是否为子查询", + "type": "boolean" + }, + "node_index": { + "description": "NodeIndex 聚合函数的位置,用于还原 promql 的定位", + "type": "integer" + }, "window": { "description": "Window 聚合周期", "type": "string", @@ -778,6 +1447,14 @@ const docTemplate = `{ "time.Duration": { "type": "integer", "enum": [ + -9223372036854775808, + 9223372036854775807, + 1, + 1000, + 1000000, + 1000000000, + 60000000000, + 3600000000000, -9223372036854775808, 9223372036854775807, 1, @@ -788,6 +1465,14 @@ const docTemplate = `{ 3600000000000 ], "x-enum-varnames": [ + "minDuration", + "maxDuration", + "Nanosecond", + "Microsecond", + "Millisecond", + "Second", + "Minute", + "Hour", "minDuration", "maxDuration", "Nanosecond", @@ -798,17 +1483,22 @@ const docTemplate = `{ "Hour" ] } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } } }` // SwaggerInfo holds exported Swagger Info so clients can modify it var SwaggerInfo = &swag.Spec{ - Version: "", + Version: "1.0", Host: "", - BasePath: "", + BasePath: "/", Schemes: []string{}, - Title: "", - Description: "", + Title: "bk-unify-query", + Description: "bk unify-query swagger api", InfoInstanceName: "swagger", SwaggerTemplate: docTemplate, LeftDelim: "{{", diff --git a/pkg/unify-query/docs/swagger.json b/pkg/unify-query/docs/swagger.json index ea42692c6..1aaba9b3d 100644 --- a/pkg/unify-query/docs/swagger.json +++ b/pkg/unify-query/docs/swagger.json @@ -1,8 +1,12 @@ { "swagger": "2.0", "info": { - "contact": {} + "description": "bk unify-query swagger api", + "title": "bk-unify-query", + "contact": {}, + "version": "1.0" }, + "basePath": "/", "paths": { "/api/v1/relation/multi_resource": { "post": { @@ -10,7 +14,7 @@ "application/json" ], "summary": "query relation multi resource", - "operationId": "api-relation-multi-resource", + "operationId": "relation_multi_resource_query", "parameters": [ { "type": "string", @@ -52,13 +56,435 @@ } } }, + "/api/v1/relation/multi_resource_range": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query relation multi resource", + "operationId": "relation_multi_resource_query_range", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/cmdb.RelationMultiResourceRangeRequest" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/cmdb.RelationMultiResourceRangeResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/api.ErrResponse" + } + } + } + } + }, + "/check/query/ts": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query promql monitor check by ts", + "operationId": "check-query-promql", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryPromQL" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.CheckResponse" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/promql": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query monitor by promql", + "operationId": "query_promql", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryPromQL" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.PromData" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, "/query/ts": { "post": { "produces": [ "application/json" ], - "summary": "query monitor by ts", - "operationId": "ts-query-request", + "summary": "query monitor by ts", + "operationId": "query_ts", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryTs" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.PromData" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/exemplar": { + "post": { + "produces": [ + "application/json" + ], + "summary": "query monitor by ts exemplar", + "operationId": "query_ts_exemplar", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/structured.QueryTs" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "$ref": "#/definitions/http.PromData" + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/info/field_keys": { + "post": { + "produces": [ + "application/json" + ], + "summary": "info field keys", + "operationId": "info_field_keys", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/infos.Params" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/info/series": { + "post": { + "produces": [ + "application/json" + ], + "summary": "info series", + "operationId": "info_series", + "parameters": [ + { + "type": "string", + "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", + "description": "TraceID", + "name": "traceparent", + "in": "header" + }, + { + "type": "string", + "default": "username:goodman", + "description": "来源", + "name": "Bk-Query-Source", + "in": "header" + }, + { + "type": "string", + "default": "bkcc__2", + "description": "空间UID", + "name": "X-Bk-Scope-Space-Uid", + "in": "header" + }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, + { + "description": "json data", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/infos.Params" + } + } + ], + "responses": { + "200": { + "description": "OK", + "schema": { + "type": "array", + "items": { + "$ref": "#/definitions/http.SeriesData" + } + } + }, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/http.ErrResponse" + } + } + } + } + }, + "/query/ts/info/tag_keys": { + "post": { + "produces": [ + "application/json" + ], + "summary": "info tag keys", + "operationId": "info_tag_keys", "parameters": [ { "type": "string", @@ -81,13 +507,20 @@ "name": "X-Bk-Scope-Space-Uid", "in": "header" }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, { "description": "json data", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/structured.QueryTs" + "$ref": "#/definitions/infos.Params" } } ], @@ -95,7 +528,13 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } } }, "400": { @@ -107,13 +546,13 @@ } } }, - "/query/ts/exemplar": { + "/query/ts/info/tag_values": { "post": { "produces": [ "application/json" ], - "summary": "query monitor by ts exemplar", - "operationId": "ts-query-exemplar-request", + "summary": "info tag values", + "operationId": "info_tag_values", "parameters": [ { "type": "string", @@ -136,13 +575,20 @@ "name": "X-Bk-Scope-Space-Uid", "in": "header" }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, { "description": "json data", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/structured.QueryTs" + "$ref": "#/definitions/infos.Params" } } ], @@ -150,7 +596,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "$ref": "#/definitions/http.TagValuesData" } }, "400": { @@ -162,13 +608,13 @@ } } }, - "/query/ts/promql": { - "post": { + "/query/ts/label/{label_name}/values": { + "get": { "produces": [ "application/json" ], - "summary": "query monitor by promql", - "operationId": "ts-query-request-promql", + "summary": "info label values", + "operationId": "info_label_values", "parameters": [ { "type": "string", @@ -191,13 +637,20 @@ "name": "X-Bk-Scope-Space-Uid", "in": "header" }, + { + "type": "string", + "default": "", + "description": "是否跳过空间验证", + "name": "X-Bk-Scope-Skip-Space", + "in": "header" + }, { "description": "json data", "name": "data", "in": "body", "required": true, "schema": { - "$ref": "#/definitions/structured.QueryPromQL" + "$ref": "#/definitions/infos.Params" } } ], @@ -205,7 +658,13 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } } }, "400": { @@ -223,7 +682,7 @@ "application/json" ], "summary": "promql to struct", - "operationId": "promql-to-struct", + "operationId": "transform_promql_to_struct", "parameters": [ { "type": "string", @@ -260,7 +719,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "$ref": "#/definitions/structured.QueryTs" } }, "400": { @@ -278,7 +737,7 @@ "application/json" ], "summary": "query struct to promql", - "operationId": "struct-to-promql", + "operationId": "transform_struct_to_promql", "parameters": [ { "type": "string", @@ -315,7 +774,7 @@ "200": { "description": "OK", "schema": { - "$ref": "#/definitions/http.PromData" + "$ref": "#/definitions/structured.QueryPromQL" } }, "400": { @@ -343,6 +802,88 @@ "type": "string" } }, + "cmdb.MatchersWithTimestamp": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/cmdb.Matcher" + } + }, + "timestamp": { + "type": "integer" + } + } + }, + "cmdb.RelationMultiResourceRangeRequest": { + "type": "object", + "properties": { + "query_list": { + "type": "array", + "items": { + "type": "object", + "properties": { + "end_time": { + "type": "integer" + }, + "look_back_delta": { + "type": "string" + }, + "source_info": { + "$ref": "#/definitions/cmdb.Matcher" + }, + "start_time": { + "type": "integer" + }, + "step": { + "type": "string" + }, + "target_type": { + "type": "string" + } + } + } + } + } + }, + "cmdb.RelationMultiResourceRangeResponse": { + "type": "object", + "properties": { + "data": { + "type": "array", + "items": { + "$ref": "#/definitions/cmdb.RelationMultiResourceRangeResponseData" + } + } + } + }, + "cmdb.RelationMultiResourceRangeResponseData": { + "type": "object", + "properties": { + "code": { + "type": "integer" + }, + "message": { + "type": "string" + }, + "source_info": { + "$ref": "#/definitions/cmdb.Matcher" + }, + "source_type": { + "type": "string" + }, + "target_list": { + "type": "array", + "items": { + "$ref": "#/definitions/cmdb.MatchersWithTimestamp" + } + }, + "target_type": { + "type": "string" + } + } + }, "cmdb.RelationMultiResourceRequest": { "type": "object", "properties": { @@ -416,6 +957,29 @@ } } }, + "http.CheckItem": { + "type": "object", + "properties": { + "error": {}, + "json_data": { + "type": "string" + }, + "step_name": { + "type": "string" + } + } + }, + "http.CheckResponse": { + "type": "object", + "properties": { + "list": { + "type": "array", + "items": { + "$ref": "#/definitions/http.CheckItem" + } + } + } + }, "http.ErrResponse": { "type": "object", "properties": { @@ -438,6 +1002,29 @@ } } }, + "http.SeriesData": { + "type": "object", + "properties": { + "keys": { + "type": "array", + "items": { + "type": "string" + } + }, + "measurement": { + "type": "string" + }, + "series": { + "type": "array", + "items": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, "http.TablesItem": { "type": "object", "properties": { @@ -480,6 +1067,55 @@ } } }, + "http.TagValuesData": { + "type": "object", + "properties": { + "values": { + "type": "object", + "additionalProperties": { + "type": "array", + "items": { + "type": "string" + } + } + } + } + }, + "infos.Params": { + "type": "object", + "properties": { + "conditions": { + "$ref": "#/definitions/structured.Conditions" + }, + "data_source": { + "type": "string" + }, + "end_time": { + "type": "string" + }, + "keys": { + "type": "array", + "items": { + "type": "string" + } + }, + "limit": { + "type": "integer" + }, + "metric_name": { + "type": "string" + }, + "slimit": { + "type": "integer" + }, + "start_time": { + "type": "string" + }, + "table_id": { + "type": "string" + } + } + }, "structured.AggregateMethod": { "type": "object", "properties": { @@ -494,11 +1130,20 @@ "bk_target_cloud_id" ] }, + "is_sub_query": { + "description": "IsSubQuery 判断是否为子查询", + "type": "boolean" + }, "method": { "description": "Method 聚合方法", "type": "string", "example": "mean" }, + "window": { + "description": "Window 聚合周期", + "type": "string", + "example": "60s" + }, "without": { "description": "Without", "type": "boolean" @@ -586,6 +1231,11 @@ "$ref": "#/definitions/structured.AggregateMethod" } }, + "is_regexp": { + "description": "IsRegexp 指标是否使用正则查询", + "type": "boolean", + "example": false + }, "limit": { "description": "Limit 点数限制数量", "type": "integer", @@ -651,6 +1301,11 @@ "type": "string" } }, + "down_sample_range": { + "description": "DownSampleRange 降采样:大于Step才能生效,可以为空", + "type": "string", + "example": "5m" + }, "end": { "type": "string" }, @@ -756,6 +1411,14 @@ "type": "string", "example": "avg_over_time" }, + "is_sub_query": { + "description": "IsSubQuery 判断是否为子查询", + "type": "boolean" + }, + "node_index": { + "description": "NodeIndex 聚合函数的位置,用于还原 promql 的定位", + "type": "integer" + }, "window": { "description": "Window 聚合周期", "type": "string", @@ -766,6 +1429,14 @@ "time.Duration": { "type": "integer", "enum": [ + -9223372036854775808, + 9223372036854775807, + 1, + 1000, + 1000000, + 1000000000, + 60000000000, + 3600000000000, -9223372036854775808, 9223372036854775807, 1, @@ -776,6 +1447,14 @@ 3600000000000 ], "x-enum-varnames": [ + "minDuration", + "maxDuration", + "Nanosecond", + "Microsecond", + "Millisecond", + "Second", + "Minute", + "Hour", "minDuration", "maxDuration", "Nanosecond", @@ -786,5 +1465,10 @@ "Hour" ] } + }, + "securityDefinitions": { + "BasicAuth": { + "type": "basic" + } } } \ No newline at end of file diff --git a/pkg/unify-query/docs/swagger.yaml b/pkg/unify-query/docs/swagger.yaml index b05e97559..4573fa075 100644 --- a/pkg/unify-query/docs/swagger.yaml +++ b/pkg/unify-query/docs/swagger.yaml @@ -1,3 +1,4 @@ +basePath: / definitions: api.ErrResponse: properties: @@ -8,6 +9,59 @@ definitions: additionalProperties: type: string type: object + cmdb.MatchersWithTimestamp: + properties: + items: + items: + $ref: '#/definitions/cmdb.Matcher' + type: array + timestamp: + type: integer + type: object + cmdb.RelationMultiResourceRangeRequest: + properties: + query_list: + items: + properties: + end_time: + type: integer + look_back_delta: + type: string + source_info: + $ref: '#/definitions/cmdb.Matcher' + start_time: + type: integer + step: + type: string + target_type: + type: string + type: object + type: array + type: object + cmdb.RelationMultiResourceRangeResponse: + properties: + data: + items: + $ref: '#/definitions/cmdb.RelationMultiResourceRangeResponseData' + type: array + type: object + cmdb.RelationMultiResourceRangeResponseData: + properties: + code: + type: integer + message: + type: string + source_info: + $ref: '#/definitions/cmdb.Matcher' + source_type: + type: string + target_list: + items: + $ref: '#/definitions/cmdb.MatchersWithTimestamp' + type: array + target_type: + type: string + type: object cmdb.RelationMultiResourceRequest: properties: query_list: @@ -55,6 +109,21 @@ definitions: message: type: string type: object + http.CheckItem: + properties: + error: {} + json_data: + type: string + step_name: + type: string + type: object + http.CheckResponse: + properties: + list: + items: + $ref: '#/definitions/http.CheckItem' + type: array + type: object http.ErrResponse: properties: error: @@ -69,6 +138,21 @@ definitions: status: $ref: '#/definitions/github_com_TencentBlueKing_bkmonitor-datalink_pkg_unify-query_metadata.Status' type: object + http.SeriesData: + properties: + keys: + items: + type: string + type: array + measurement: + type: string + series: + items: + items: + type: string + type: array + type: array + type: object http.TablesItem: properties: columns: @@ -97,6 +181,38 @@ definitions: type: array type: array type: object + http.TagValuesData: + properties: + values: + additionalProperties: + items: + type: string + type: array + type: object + type: object + infos.Params: + properties: + conditions: + $ref: '#/definitions/structured.Conditions' + data_source: + type: string + end_time: + type: string + keys: + items: + type: string + type: array + limit: + type: integer + metric_name: + type: string + slimit: + type: integer + start_time: + type: string + table_id: + type: string + type: object structured.AggregateMethod: properties: dimensions: @@ -107,10 +223,17 @@ definitions: items: type: string type: array + is_sub_query: + description: IsSubQuery 判断是否为子查询 + type: boolean method: description: Method 聚合方法 example: mean type: string + window: + description: Window 聚合周期 + example: 60s + type: string without: description: Without type: boolean @@ -171,6 +294,10 @@ definitions: items: $ref: '#/definitions/structured.AggregateMethod' type: array + is_regexp: + description: IsRegexp 指标是否使用正则查询 + example: false + type: boolean limit: description: Limit 点数限制数量 example: 0 @@ -216,6 +343,10 @@ definitions: items: type: string type: array + down_sample_range: + description: DownSampleRange 降采样:大于Step才能生效,可以为空 + example: 5m + type: string end: type: string instant: @@ -293,6 +424,12 @@ definitions: description: Function 时间聚合方法 example: avg_over_time type: string + is_sub_query: + description: IsSubQuery 判断是否为子查询 + type: boolean + node_index: + description: NodeIndex 聚合函数的位置,用于还原 promql 的定位 + type: integer window: description: Window 聚合周期 example: 60s @@ -308,6 +445,14 @@ definitions: - 1000000000 - 60000000000 - 3600000000000 + - -9223372036854775808 + - 9223372036854775807 + - 1 + - 1000 + - 1000000 + - 1000000000 + - 60000000000 + - 3600000000000 type: integer x-enum-varnames: - minDuration @@ -318,12 +463,23 @@ definitions: - Second - Minute - Hour + - minDuration + - maxDuration + - Nanosecond + - Microsecond + - Millisecond + - Second + - Minute + - Hour info: contact: {} + description: bk unify-query swagger api + title: bk-unify-query + version: "1.0" paths: /api/v1/relation/multi_resource: post: - operationId: api-relation-multi-resource + operationId: relation_multi_resource_query parameters: - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 description: TraceID @@ -353,9 +509,120 @@ paths: schema: $ref: '#/definitions/api.ErrResponse' summary: query relation multi resource + /api/v1/relation/multi_resource_range: + post: + operationId: relation_multi_resource_query_range + parameters: + - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 + description: TraceID + in: header + name: traceparent + type: string + - default: bkcc__2 + description: 空间UID + in: header + name: X-Bk-Scope-Space-Uid + type: string + - description: json data + in: body + name: data + required: true + schema: + $ref: '#/definitions/cmdb.RelationMultiResourceRangeRequest' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/cmdb.RelationMultiResourceRangeResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/api.ErrResponse' + summary: query relation multi resource + /check/query/ts: + post: + operationId: check-query-promql + parameters: + - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 + description: TraceID + in: header + name: traceparent + type: string + - default: bkcc__2 + description: 空间UID + in: header + name: X-Bk-Scope-Space-Uid + type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string + - description: json data + in: body + name: data + required: true + schema: + $ref: '#/definitions/structured.QueryPromQL' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/http.CheckResponse' + "400": + description: Bad Request + schema: + $ref: '#/definitions/http.ErrResponse' + summary: query promql monitor check by ts + /query/promql: + post: + operationId: query_promql + parameters: + - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 + description: TraceID + in: header + name: traceparent + type: string + - default: username:goodman + description: 来源 + in: header + name: Bk-Query-Source + type: string + - default: bkcc__2 + description: 空间UID + in: header + name: X-Bk-Scope-Space-Uid + type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string + - description: json data + in: body + name: data + required: true + schema: + $ref: '#/definitions/structured.QueryPromQL' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/http.PromData' + "400": + description: Bad Request + schema: + $ref: '#/definitions/http.ErrResponse' + summary: query monitor by promql /query/ts: post: - operationId: ts-query-request + operationId: query_ts parameters: - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 description: TraceID @@ -372,6 +639,11 @@ paths: in: header name: X-Bk-Scope-Space-Uid type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string - description: json data in: body name: data @@ -392,7 +664,7 @@ paths: summary: query monitor by ts /query/ts/exemplar: post: - operationId: ts-query-exemplar-request + operationId: query_ts_exemplar parameters: - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 description: TraceID @@ -409,6 +681,11 @@ paths: in: header name: X-Bk-Scope-Space-Uid type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string - description: json data in: body name: data @@ -427,9 +704,9 @@ paths: schema: $ref: '#/definitions/http.ErrResponse' summary: query monitor by ts exemplar - /query/ts/promql: + /query/ts/info/field_keys: post: - operationId: ts-query-request-promql + operationId: info_field_keys parameters: - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 description: TraceID @@ -446,27 +723,214 @@ paths: in: header name: X-Bk-Scope-Space-Uid type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string - description: json data in: body name: data required: true schema: - $ref: '#/definitions/structured.QueryPromQL' + $ref: '#/definitions/infos.Params' produces: - application/json responses: "200": description: OK schema: - $ref: '#/definitions/http.PromData' + items: + items: + type: string + type: array + type: array "400": description: Bad Request schema: $ref: '#/definitions/http.ErrResponse' - summary: query monitor by promql + summary: info field keys + /query/ts/info/series: + post: + operationId: info_series + parameters: + - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 + description: TraceID + in: header + name: traceparent + type: string + - default: username:goodman + description: 来源 + in: header + name: Bk-Query-Source + type: string + - default: bkcc__2 + description: 空间UID + in: header + name: X-Bk-Scope-Space-Uid + type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string + - description: json data + in: body + name: data + required: true + schema: + $ref: '#/definitions/infos.Params' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + $ref: '#/definitions/http.SeriesData' + type: array + "400": + description: Bad Request + schema: + $ref: '#/definitions/http.ErrResponse' + summary: info series + /query/ts/info/tag_keys: + post: + operationId: info_tag_keys + parameters: + - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 + description: TraceID + in: header + name: traceparent + type: string + - default: username:goodman + description: 来源 + in: header + name: Bk-Query-Source + type: string + - default: bkcc__2 + description: 空间UID + in: header + name: X-Bk-Scope-Space-Uid + type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string + - description: json data + in: body + name: data + required: true + schema: + $ref: '#/definitions/infos.Params' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + items: + type: string + type: array + type: array + "400": + description: Bad Request + schema: + $ref: '#/definitions/http.ErrResponse' + summary: info tag keys + /query/ts/info/tag_values: + post: + operationId: info_tag_values + parameters: + - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 + description: TraceID + in: header + name: traceparent + type: string + - default: username:goodman + description: 来源 + in: header + name: Bk-Query-Source + type: string + - default: bkcc__2 + description: 空间UID + in: header + name: X-Bk-Scope-Space-Uid + type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string + - description: json data + in: body + name: data + required: true + schema: + $ref: '#/definitions/infos.Params' + produces: + - application/json + responses: + "200": + description: OK + schema: + $ref: '#/definitions/http.TagValuesData' + "400": + description: Bad Request + schema: + $ref: '#/definitions/http.ErrResponse' + summary: info tag values + /query/ts/label/{label_name}/values: + get: + operationId: info_label_values + parameters: + - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 + description: TraceID + in: header + name: traceparent + type: string + - default: username:goodman + description: 来源 + in: header + name: Bk-Query-Source + type: string + - default: bkcc__2 + description: 空间UID + in: header + name: X-Bk-Scope-Space-Uid + type: string + - default: "" + description: 是否跳过空间验证 + in: header + name: X-Bk-Scope-Skip-Space + type: string + - description: json data + in: body + name: data + required: true + schema: + $ref: '#/definitions/infos.Params' + produces: + - application/json + responses: + "200": + description: OK + schema: + items: + items: + type: string + type: array + type: array + "400": + description: Bad Request + schema: + $ref: '#/definitions/http.ErrResponse' + summary: info label values /query/ts/promql_to_struct: post: - operationId: promql-to-struct + operationId: transform_promql_to_struct parameters: - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 description: TraceID @@ -495,7 +959,7 @@ paths: "200": description: OK schema: - $ref: '#/definitions/http.PromData' + $ref: '#/definitions/structured.QueryTs' "400": description: Bad Request schema: @@ -503,7 +967,7 @@ paths: summary: promql to struct /query/ts/struct_to_promql: post: - operationId: struct-to-promql + operationId: transform_struct_to_promql parameters: - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 description: TraceID @@ -532,10 +996,13 @@ paths: "200": description: OK schema: - $ref: '#/definitions/http.PromData' + $ref: '#/definitions/structured.QueryPromQL' "400": description: Bad Request schema: $ref: '#/definitions/http.ErrResponse' summary: query struct to promql +securityDefinitions: + BasicAuth: + type: basic swagger: "2.0" diff --git a/pkg/unify-query/go.mod b/pkg/unify-query/go.mod index 1b86b4224..783bbd42c 100755 --- a/pkg/unify-query/go.mod +++ b/pkg/unify-query/go.mod @@ -39,7 +39,6 @@ require ( github.com/swaggo/swag v1.16.1 github.com/thomaspoignant/go-feature-flag v1.0.1 github.com/tinylib/msgp v1.1.6 - github.com/uptrace/opentelemetry-go-extra/otelzap v0.2.1 go.etcd.io/bbolt v1.3.3 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.32.0 go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.42.0 @@ -147,6 +146,7 @@ require ( github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect github.com/uptrace/opentelemetry-go-extra/otelutil v0.2.1 // indirect + github.com/uptrace/opentelemetry-go-extra/otelzap v0.2.1 // indirect github.com/valyala/fastrand v1.1.0 // indirect github.com/valyala/histogram v1.2.0 // indirect github.com/willf/bitset v1.1.3 // indirect diff --git a/pkg/unify-query/main.go b/pkg/unify-query/main.go index ad3dae4a9..0399903fb 100644 --- a/pkg/unify-query/main.go +++ b/pkg/unify-query/main.go @@ -14,9 +14,15 @@ import ( _ "go.uber.org/automaxprocs" "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/cmd" - _ "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/swagger" ) +// @title bk-unify-query +// @version 1.0 +// @description bk unify-query swagger api + +// @BasePath / + +// @securityDefinitions.basic BasicAuth func main() { cmd.Execute() } diff --git a/pkg/unify-query/service/http/api.go b/pkg/unify-query/service/http/api.go index 659f5308e..fb5dae0ed 100644 --- a/pkg/unify-query/service/http/api.go +++ b/pkg/unify-query/service/http/api.go @@ -32,32 +32,81 @@ import ( ) // HandlerFieldKeys -// @Summary query monitor by promql -// @ID ts-query-request-promql +// @Summary info field keys +// @ID info_field_keys // @Produce json -// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) -// @Param Bk-Query-Source header string false "来源" default(username:goodman) -// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) -// @Param data body structured.QueryPromQL true "json data" -// @Success 200 {object} PromData +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body infos.Params true "json data" +// @Success 200 {array} []string // @Failure 400 {object} ErrResponse -// @Router /query/ts/promql [post] +// @Router /query/ts/info/field_keys [post] func HandlerFieldKeys(c *gin.Context) { handlerInfo(c, infos.FieldKeys) } +// HandlerTagKeys +// @Summary info tag keys +// @ID info_tag_keys +// @Produce json +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body infos.Params true "json data" +// @Success 200 {array} []string +// @Failure 400 {object} ErrResponse +// @Router /query/ts/info/tag_keys [post] func HandlerTagKeys(c *gin.Context) { handlerInfo(c, infos.TagKeys) } +// HandlerTagValues +// @Summary info tag values +// @ID info_tag_values +// @Produce json +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body infos.Params true "json data" +// @Success 200 {object} TagValuesData +// @Failure 400 {object} ErrResponse +// @Router /query/ts/info/tag_values [post] func HandlerTagValues(c *gin.Context) { handlerInfo(c, infos.TagValues) } +// HandlerSeries +// @Summary info series +// @ID info_series +// @Produce json +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body infos.Params true "json data" +// @Success 200 {object} SeriesDataList +// @Failure 400 {object} ErrResponse +// @Router /query/ts/info/series [post] func HandlerSeries(c *gin.Context) { handlerInfo(c, infos.Series) } +// HandlerLabelValues +// @Summary info label values +// @ID info_label_values +// @Produce json +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body infos.Params true "json data" +// @Success 200 {array} []string +// @Failure 400 {object} ErrResponse +// @Router /query/ts/label/{label_name}/values [get] func HandlerLabelValues(c *gin.Context) { var ( key = infos.TagValues @@ -278,7 +327,7 @@ func queryInfo(ctx context.Context, key infos.InfoType, params *infos.Params) (i } } - data = []*SeriesData{ + data = SeriesDataList{ { Keys: keys, Series: series, diff --git a/pkg/unify-query/service/http/api/api.go b/pkg/unify-query/service/http/api/api.go index 32266cd96..cddcd9663 100644 --- a/pkg/unify-query/service/http/api/api.go +++ b/pkg/unify-query/service/http/api/api.go @@ -25,7 +25,7 @@ import ( // HandlerAPIRelationMultiResource // @Summary query relation multi resource -// @ID api-relation-multi-resource +// @ID relation_multi_resource_query // @Produce json // @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) // @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) @@ -86,7 +86,7 @@ func HandlerAPIRelationMultiResource(c *gin.Context) { // HandlerAPIRelationMultiResourceRange // @Summary query relation multi resource -// @ID api-relation-multi-resource +// @ID relation_multi_resource_query_range // @Produce json // @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) // @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) diff --git a/pkg/unify-query/service/http/api/response.go b/pkg/unify-query/service/http/api/response.go index d714d3236..2d227cb2e 100644 --- a/pkg/unify-query/service/http/api/response.go +++ b/pkg/unify-query/service/http/api/response.go @@ -22,7 +22,7 @@ import ( "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/metric" ) -// ErrResponse +// ErrResponse 输出结构体 type ErrResponse struct { Err string `json:"error"` } diff --git a/pkg/unify-query/service/http/check_handler.go b/pkg/unify-query/service/http/check_handler.go new file mode 100644 index 000000000..6a757ca91 --- /dev/null +++ b/pkg/unify-query/service/http/check_handler.go @@ -0,0 +1,210 @@ +// Tencent is pleased to support the open source community by making +// 蓝鲸智云 - 监控平台 (BlueKing - Monitor) available. +// Copyright (C) 2022 THL A29 Limited, a Tencent company. All rights reserved. +// Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. +// You may obtain a copy of the License at http://opensource.org/licenses/MIT +// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on +// an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the +// specific language governing permissions and limitations under the License. + +package http + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "strings" + + "github.com/gin-gonic/gin" + + "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/consul" + "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/metadata" + "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/query/structured" + "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/tsdb/prometheus" +) + +type CheckItem struct { + Error error `json:"error,omitempty"` + StepName string `json:"step_name,omitempty"` + JsonData string `json:"json_data,omitempty"` +} + +func (c *CheckItem) String() string { + var s []string + s = append(s, fmt.Sprintf("step-name: %s", c.StepName)) + if c.Error != nil { + s = append(s, fmt.Sprintf("error: %v", c.Error)) + } else { + s = append(s, fmt.Sprintf("data: %s", c.JsonData)) + } + return strings.Join(s, "\n") +} + +type CheckResponse struct { + List []*CheckItem `json:"list"` +} + +func (c *CheckResponse) Step(name string, data interface{}) { + var jsonData string + s, err := json.Marshal(data) + if err != nil { + jsonData = fmt.Sprintf("%+v", data) + } else { + jsonData = fmt.Sprintf("%s", s) + } + + c.List = append(c.List, &CheckItem{ + StepName: name, + JsonData: jsonData, + }) +} + +func (c *CheckResponse) Error(name string, err error) { + c.List = append(c.List, &CheckItem{ + StepName: name, + Error: err, + }) +} + +func (c *CheckResponse) String() string { + var s []string + for _, i := range c.List { + s = append(s, i.String()) + } + return strings.Join(s, "\n-------------------------------------------------\n") +} + +// HandlerCheckQueryTs +// @Summary query ts monitor check by ts +// @ID check_query_ts +// @Produce json +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body structured.QueryTs true "json data" +// @Success 200 {object} CheckResponse +// @Failure 400 {object} ErrResponse +// @Router /check/query/ts [post] +func HandlerCheckQueryTs(c *gin.Context) { + var ( + ctx = c.Request.Context() + checkResponse = &CheckResponse{} + ) + + // 解析请求 body + query := &structured.QueryTs{} + err := json.NewDecoder(c.Request.Body).Decode(query) + if err != nil { + checkResponse.Error("query ts json decoder", err) + return + } + + checkQueryTs(ctx, query, checkResponse) + c.String(http.StatusOK, checkResponse.String()) +} + +// HandlerCheckQueryPromQL +// @Summary query promql monitor check by ts +// @ID check_query_promql +// @Produce json +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body structured.QueryPromQL true "json data" +// @Success 200 {object} CheckResponse +// @Failure 400 {object} ErrResponse +// @Router /check/query/ts [post] +func HandlerCheckQueryPromQL(c *gin.Context) { + var ( + ctx = c.Request.Context() + checkResponse = &CheckResponse{} + ) + + // 解析请求 body + queryPromQL := &structured.QueryPromQL{} + err := json.NewDecoder(c.Request.Body).Decode(queryPromQL) + if err != nil { + checkResponse.Error("query promQL json decoder", err) + return + } + + // promql to struct + query, err := promQLToStruct(ctx, queryPromQL) + if err != nil { + checkResponse.Error("promQLToString", err) + return + } + + checkQueryTs(ctx, query, checkResponse) + c.String(http.StatusOK, checkResponse.String()) +} + +// checkQueryTs 根据传入的查询进行校验判断 +func checkQueryTs(ctx context.Context, q *structured.QueryTs, r *CheckResponse) { + var err error + + r.Step("query ts", q) + + user := metadata.GetUser(ctx) + r.Step("metadata user", user) + + // 查询转换信息 + qr, err := q.ToQueryReference(ctx) + if err != nil { + r.Error("q.ToQueryReference", err) + return + } + r.Step("query-reference", qr) + + start, end, _, _, err := structured.ToTime(q.Start, q.End, q.Step, q.Timezone) + if err != nil { + r.Error("structured.ToTime", err) + return + } + + // 写入查询缓存 + metadata.SetQueryParams(ctx, &metadata.QueryParams{ + Start: start.Unix(), + End: end.Unix(), + }) + + // 判断是否查询 vm + ok, vmExpand, err := qr.CheckVmQuery(ctx) + if err != nil { + r.Error("qr.CheckVmQuery", err) + return + } + + promQL, err := q.ToPromExpr(ctx, nil, nil) + if err != nil { + r.Error("q.ToPromExpr", err) + return + } + r.Step("query promQL", promQL.String()) + + // vm query + if ok { + r.Step("query instance", consul.VictoriaMetricsStorageType) + r.Step("query vmExpand", vmExpand) + } else { + for _, qm := range qr { + for _, qry := range qm.QueryList { + instance := prometheus.GetInstance(ctx, qry) + if instance == nil { + r.Error("prometheus.GetInstance", fmt.Errorf("instance is null, with storageID %s", qry.StorageID)) + continue + } + + r.Step("instance id", qry.StorageID) + r.Step("instance type", instance.GetInstanceType()) + r.Step("query struct", qry) + } + } + } + + status := metadata.GetStatus(ctx) + if status != nil { + r.Step("metadata status", status) + } +} diff --git a/pkg/unify-query/service/http/handler.go b/pkg/unify-query/service/http/handler.go index fda3997ba..76f2532a2 100644 --- a/pkg/unify-query/service/http/handler.go +++ b/pkg/unify-query/service/http/handler.go @@ -413,13 +413,13 @@ func promQLToStruct(ctx context.Context, queryPromQL *structured.QueryPromQL) (* // HandlerPromQLToStruct // @Summary promql to struct -// @ID promql-to-struct +// @ID transform_promql_to_struct // @Produce json // @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) // @Param Bk-Query-Source header string false "来源" default(username:goodman) // @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) // @Param data body structured.QueryPromQL true "json data" -// @Success 200 {object} PromData +// @Success 200 {object} structured.QueryTs // @Failure 400 {object} ErrResponse // @Router /query/ts/promql_to_struct [post] func HandlerPromQLToStruct(c *gin.Context) { @@ -463,13 +463,13 @@ func HandlerPromQLToStruct(c *gin.Context) { // HandlerStructToPromQL // @Summary query struct to promql -// @ID struct-to-promql +// @ID transform_struct_to_promql // @Produce json // @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) // @Param Bk-Query-Source header string false "来源" default(username:goodman) // @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) // @Param data body structured.QueryTs true "json data" -// @Success 200 {object} PromData +// @Success 200 {object} structured.QueryPromQL // @Failure 400 {object} ErrResponse // @Router /query/ts/struct_to_promql [post] func HandlerStructToPromQL(c *gin.Context) { @@ -514,12 +514,13 @@ func HandlerStructToPromQL(c *gin.Context) { // HandlerQueryExemplar 查询时序 exemplar 数据 // @Summary query monitor by ts exemplar -// @ID ts-query-exemplar-request +// @ID query_ts_exemplar // @Produce json -// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) -// @Param Bk-Query-Source header string false "来源" default(username:goodman) -// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) -// @Param data body structured.QueryTs true "json data" +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body structured.QueryTs true "json data" // @Success 200 {object} PromData // @Failure 400 {object} ErrResponse // @Router /query/ts/exemplar [post] @@ -575,12 +576,13 @@ func HandlerQueryExemplar(c *gin.Context) { // HandlerQueryTs // @Summary query monitor by ts -// @ID ts-query-request +// @ID query_ts // @Produce json -// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) -// @Param Bk-Query-Source header string false "来源" default(username:goodman) -// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) -// @Param data body structured.QueryTs true "json data" +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body structured.QueryTs true "json data" // @Success 200 {object} PromData // @Failure 400 {object} ErrResponse // @Router /query/ts [post] @@ -638,15 +640,16 @@ func HandlerQueryTs(c *gin.Context) { // HandlerQueryPromQL // @Summary query monitor by promql -// @ID ts-query-request-promql +// @ID query_promql // @Produce json -// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) -// @Param Bk-Query-Source header string false "来源" default(username:goodman) -// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) -// @Param data body structured.QueryPromQL true "json data" +// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) +// @Param Bk-Query-Source header string false "来源" default(username:goodman) +// @Param X-Bk-Scope-Space-Uid header string false "空间UID" default(bkcc__2) +// @Param X-Bk-Scope-Skip-Space header string false "是否跳过空间验证" default() +// @Param data body structured.QueryPromQL true "json data" // @Success 200 {object} PromData // @Failure 400 {object} ErrResponse -// @Router /query/ts/promql [post] +// @Router /query/promql [post] func HandlerQueryPromQL(c *gin.Context) { var ( ctx = c.Request.Context() @@ -711,15 +714,6 @@ func HandleInfluxDBPrint(c *gin.Context) { c.String(200, res) } -// HandlerQueryTsClusterMetrics -// @Summary query ClusterMetrics ts -// @ID ts-query-request-cluster-metrics -// @Produce json -// @Param traceparent header string false "TraceID" default(00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01) -// @Param data body structured.QueryTs true "json data" -// @Success 200 {object} PromData -// @Failure 400 {object} ErrResponse -// @Router /query/ts/cluster_metrics [post] func HandlerQueryTsClusterMetrics(c *gin.Context) { var ( ctx = c.Request.Context() diff --git a/pkg/unify-query/service/http/hook.go b/pkg/unify-query/service/http/hook.go index 6971bfcb9..384d48c24 100644 --- a/pkg/unify-query/service/http/hook.go +++ b/pkg/unify-query/service/http/hook.go @@ -58,6 +58,9 @@ func setDefaultConfig() { viper.SetDefault(TsDBPrintHandlePathConfigPath, "/tsdb_print") viper.SetDefault(InfluxDBPrintHandlePathConfigPath, "/influxdb_print") + viper.SetDefault(CheckQueryTsConfigPath, "/check/query/ts") + viper.SetDefault(CheckQueryPromQLConfigPath, "/check/query/ts/promql") + viper.SetDefault(AlignInfluxdbResultConfigPath, true) viper.SetDefault(InfoDefaultLimit, 100) diff --git a/pkg/unify-query/service/http/info.go b/pkg/unify-query/service/http/info.go index d2469cdda..01aa41a13 100644 --- a/pkg/unify-query/service/http/info.go +++ b/pkg/unify-query/service/http/info.go @@ -36,6 +36,8 @@ type TagValuesData struct { Values map[string][]string `json:"values"` } +type SeriesDataList []*SeriesData + // SeriesData type SeriesData struct { Measurement string `json:"measurement"` diff --git a/pkg/unify-query/service/http/register_urls.go b/pkg/unify-query/service/http/register_urls.go index 1fff2618f..a3ae6bbcd 100644 --- a/pkg/unify-query/service/http/register_urls.go +++ b/pkg/unify-query/service/http/register_urls.go @@ -15,18 +15,11 @@ import ( "github.com/gin-gonic/gin" "github.com/spf13/viper" - swaggerFiles "github.com/swaggo/files" - ginSwagger "github.com/swaggo/gin-swagger" "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/log" "github.com/TencentBlueKing/bkmonitor-datalink/pkg/unify-query/query/infos" ) -// registerSwagger -func registerSwagger(g *gin.Engine) { - g.GET("/sagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) -} - // registerTSQueryService: /query/ts func registerTSQueryService(g *gin.Engine) { servicePath := viper.GetString(TSQueryHandlePathConfigPath) @@ -67,6 +60,17 @@ func registerTSQueryPromQLToStructService(g *gin.Engine) { log.Infof(context.TODO(), "ts service register in path->[%s]", servicePath) } +// registerCheckService 注册 check 类型接口 +func registerCheckService(g *gin.Engine) { + queryTsPath := viper.GetString(CheckQueryTsConfigPath) + g.POST(queryTsPath, HandlerCheckQueryTs) + log.Infof(context.TODO(), "check service register in path->[%s]", queryTsPath) + + queryPromQLPath := viper.GetString(CheckQueryPromQLConfigPath) + g.POST(queryPromQLPath, HandlerCheckQueryPromQL) + log.Infof(context.TODO(), "check service register in path->[%s]", queryPromQLPath) +} + // registerTSQueryInfoService: /query/ts/info func registerTSQueryInfoService(g *gin.Engine) { servicePath := viper.GetString(TSQueryInfoHandlePathConfigPath) diff --git a/pkg/unify-query/service/http/service.go b/pkg/unify-query/service/http/service.go index 0bf91a181..b63fc9b31 100644 --- a/pkg/unify-query/service/http/service.go +++ b/pkg/unify-query/service/http/service.go @@ -100,7 +100,7 @@ func (s *Service) Reload(ctx context.Context) { registerSpaceKeyPrint(s.g) registerTsDBPrint(s.g) registerFeatureFlag(s.g) - registerSwagger(s.g) + registerCheckService(s.g) api.RegisterRelation(ctx, s.g) diff --git a/pkg/unify-query/service/http/settings.go b/pkg/unify-query/service/http/settings.go index ed4801c19..523d6963d 100644 --- a/pkg/unify-query/service/http/settings.go +++ b/pkg/unify-query/service/http/settings.go @@ -53,6 +53,9 @@ const ( FeatureFlagHandlePathConfigPath = "http.path.feature_flag_path" ESHandlePathConfigPath = "http.path.es" + CheckQueryTsConfigPath = "http.path.check_query_ts" + CheckQueryPromQLConfigPath = "http.path.check_query_promql" + // 查询配置 InfoDefaultLimit = "http.info.limit" diff --git a/pkg/unify-query/swagger/swagger.go b/pkg/unify-query/swagger/swagger.go deleted file mode 100644 index 633bbbf51..000000000 --- a/pkg/unify-query/swagger/swagger.go +++ /dev/null @@ -1,557 +0,0 @@ -// Code generated by swaggo/swag. DO NOT EDIT. - -package swagger - -import "github.com/swaggo/swag" - -const docTemplate = `{ - "schemes": {{ marshal .Schemes }}, - "swagger": "2.0", - "info": { - "description": "{{escape .Description}}", - "title": "{{.Title}}", - "contact": {}, - "version": "{{.Version}}" - }, - "host": "{{.Host}}", - "basePath": "{{.BasePath}}", - "paths": { - "/query/ts": { - "post": { - "produces": [ - "application/json" - ], - "summary": "query monitor by ts", - "operationId": "ts-query-request", - "parameters": [ - { - "type": "string", - "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", - "description": "TraceID", - "name": "traceparent", - "in": "header" - }, - { - "type": "string", - "default": "username:goodman", - "description": "来源", - "name": "Bk-Query-Source", - "in": "header" - }, - { - "type": "string", - "default": "bkcc__2", - "description": "空间UID", - "name": "X-Bk-Scope-Space-Uid", - "in": "header" - }, - { - "description": "json data", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/structured.QueryTs" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.PromData" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.ErrResponse" - } - } - } - } - }, - "/query/ts/exemplar": { - "post": { - "produces": [ - "application/json" - ], - "summary": "query monitor by ts exemplar", - "operationId": "ts-query-exemplar-request", - "parameters": [ - { - "type": "string", - "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", - "description": "TraceID", - "name": "traceparent", - "in": "header" - }, - { - "type": "string", - "default": "username:goodman", - "description": "来源", - "name": "Bk-Query-Source", - "in": "header" - }, - { - "type": "string", - "default": "bkcc__2", - "description": "空间UID", - "name": "X-Bk-Scope-Space-Uid", - "in": "header" - }, - { - "description": "json data", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/structured.QueryTs" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.PromData" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.ErrResponse" - } - } - } - } - }, - "/query/ts/promql": { - "post": { - "produces": [ - "application/json" - ], - "summary": "query monitor by promql", - "operationId": "ts-query-request-promql", - "parameters": [ - { - "type": "string", - "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", - "description": "TraceID", - "name": "traceparent", - "in": "header" - }, - { - "type": "string", - "default": "username:goodman", - "description": "来源", - "name": "Bk-Query-Source", - "in": "header" - }, - { - "type": "string", - "default": "bkcc__2", - "description": "空间UID", - "name": "X-Bk-Scope-Space-Uid", - "in": "header" - }, - { - "description": "json data", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/structured.QueryPromQL" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.PromData" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.ErrResponse" - } - } - } - } - } - }, - "definitions": { - "http.ErrResponse": { - "type": "object", - "properties": { - "error": { - "type": "string" - } - } - }, - "http.PromData": { - "type": "object", - "properties": { - "series": { - "type": "array", - "items": { - "$ref": "#/definitions/http.TablesItem" - } - }, - "status": { - "$ref": "#/definitions/metadata.Status" - } - } - }, - "http.TablesItem": { - "type": "object", - "properties": { - "columns": { - "type": "array", - "items": { - "type": "string" - } - }, - "group_keys": { - "type": "array", - "items": { - "type": "string" - } - }, - "group_values": { - "type": "array", - "items": { - "type": "string" - } - }, - "metric_name": { - "type": "string" - }, - "name": { - "type": "string" - }, - "types": { - "type": "array", - "items": { - "type": "string" - } - }, - "values": { - "type": "array", - "items": { - "type": "array", - "items": {} - } - } - } - }, - "metadata.Status": { - "type": "object", - "properties": { - "code": { - "type": "string" - }, - "message": { - "type": "string" - } - } - }, - "structured.AggregateMethod": { - "type": "object", - "properties": { - "dimensions": { - "description": "Dimensions 聚合维度", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "bk_target_ip", - "bk_target_cloud_id" - ] - }, - "method": { - "description": "Method 聚合方法", - "type": "string", - "example": "mean" - }, - "without": { - "description": "Without", - "type": "boolean" - } - } - }, - "structured.ConditionField": { - "type": "object", - "properties": { - "field_name": { - "description": "DimensionName 过滤字段", - "type": "string", - "example": "bk_biz_id" - }, - "op": { - "description": "Operator 操作符,包含:eq,ne,erq,nreq,contains,ncontains", - "type": "string", - "example": "contains" - }, - "value": { - "description": "Value 查询值", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "2" - ] - } - } - }, - "structured.Conditions": { - "type": "object", - "properties": { - "condition_list": { - "description": "ConditionList 组合条件,长度 = len(FieldList) - 1的数组,支持 and,or", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "and" - ] - }, - "field_list": { - "description": "FieldList 查询条件", - "type": "array", - "items": { - "$ref": "#/definitions/structured.ConditionField" - } - } - } - }, - "structured.Query": { - "type": "object", - "properties": { - "conditions": { - "description": "Conditions 过滤条件", - "allOf": [ - { - "$ref": "#/definitions/structured.Conditions" - } - ] - }, - "dimensions": { - "description": "Dimensions promQL 使用维度", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "bk_target_ip", - "bk_target_cloud_id" - ] - }, - "field_name": { - "description": "FieldName 查询指标", - "type": "string", - "example": "usage" - }, - "function": { - "description": "AggregateMethodList 维度聚合函数", - "type": "array", - "items": { - "$ref": "#/definitions/structured.AggregateMethod" - } - }, - "limit": { - "description": "Limit 点数限制数量", - "type": "integer", - "example": 0 - }, - "offset": { - "description": "Offset 偏移量", - "type": "string", - "example": "" - }, - "offset_forward": { - "description": "OffsetForward 偏移方向,默认 false 为向前偏移", - "type": "boolean", - "example": false - }, - "reference_name": { - "description": "ReferenceName 别名,用于表达式计算", - "type": "string", - "example": "a" - }, - "slimit": { - "description": "Slimit 维度限制数量", - "type": "integer", - "example": 0 - }, - "start_or_end": { - "description": "StartOrEnd @-modifier 标记,start or end", - "type": "integer" - }, - "table_id": { - "description": "TableID 数据实体ID,容器指标可以为空", - "type": "string", - "example": "system.cpu_summary" - }, - "time_aggregation": { - "description": "TimeAggregation 时间聚合方法", - "allOf": [ - { - "$ref": "#/definitions/structured.TimeAggregation" - } - ] - }, - "timestamp": { - "description": "Timestamp @-modifier 标记", - "type": "integer" - }, - "vector_offset": { - "description": "VectorOffset", - "allOf": [ - { - "$ref": "#/definitions/time.Duration" - } - ] - } - } - }, - "structured.QueryPromQL": { - "type": "object", - "properties": { - "bk_biz_ids": { - "type": "array", - "items": { - "type": "string" - } - }, - "end": { - "type": "string" - }, - "limit": { - "type": "integer" - }, - "max_source_resolution": { - "type": "string" - }, - "not_align_influxdb": { - "description": "不与influxdb对齐", - "type": "boolean" - }, - "promql": { - "type": "string" - }, - "slimit": { - "type": "integer" - }, - "start": { - "type": "string" - }, - "step": { - "type": "string" - } - } - }, - "structured.QueryTs": { - "type": "object", - "properties": { - "down_sample_range": { - "description": "DownSampleRange 降采样:大于Step才能生效,可以为空", - "type": "string", - "example": "5m" - }, - "end_time": { - "description": "End 结束时间:单位为毫秒的时间戳", - "type": "string", - "example": "1657851600" - }, - "metric_merge": { - "description": "MetricMerge 表达式:支持所有PromQL语法", - "type": "string", - "example": "a" - }, - "query_list": { - "description": "QueryList 查询实例", - "type": "array", - "items": { - "$ref": "#/definitions/structured.Query" - } - }, - "space_uid": { - "description": "SpaceUid 空间ID", - "type": "string" - }, - "start_time": { - "description": "Start 开始时间:单位为毫秒的时间戳", - "type": "string", - "example": "1657848000" - }, - "step": { - "description": "Step 步长:最终返回的点数的时间间隔", - "type": "string", - "example": "1m" - } - } - }, - "structured.TimeAggregation": { - "type": "object", - "properties": { - "function": { - "description": "Function 时间聚合方法", - "type": "string", - "example": "avg_over_time" - }, - "window": { - "description": "Window 聚合周期", - "type": "string", - "example": "60s" - } - } - }, - "time.Duration": { - "type": "integer", - "enum": [ - -9223372036854775808, - 9223372036854775807, - 1, - 1000, - 1000000, - 1000000000, - 60000000000, - 3600000000000 - ], - "x-enum-varnames": [ - "minDuration", - "maxDuration", - "Nanosecond", - "Microsecond", - "Millisecond", - "Second", - "Minute", - "Hour" - ] - } - } -}` - -// SwaggerInfo holds exported Swagger Info so clients can modify it -var SwaggerInfo = &swag.Spec{ - Version: "", - Host: "", - BasePath: "", - Schemes: []string{}, - Title: "", - Description: "", - InfoInstanceName: "swagger", - SwaggerTemplate: docTemplate, - LeftDelim: "{{", - RightDelim: "}}", -} - -func init() { - swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) -} diff --git a/pkg/unify-query/swagger/swagger.json b/pkg/unify-query/swagger/swagger.json deleted file mode 100644 index 170e7247b..000000000 --- a/pkg/unify-query/swagger/swagger.json +++ /dev/null @@ -1,527 +0,0 @@ -{ - "swagger": "2.0", - "info": { - "contact": {} - }, - "paths": { - "/query/ts": { - "post": { - "produces": [ - "application/json" - ], - "summary": "query monitor by ts", - "operationId": "ts-query-request", - "parameters": [ - { - "type": "string", - "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", - "description": "TraceID", - "name": "traceparent", - "in": "header" - }, - { - "type": "string", - "default": "username:goodman", - "description": "来源", - "name": "Bk-Query-Source", - "in": "header" - }, - { - "type": "string", - "default": "bkcc__2", - "description": "空间UID", - "name": "X-Bk-Scope-Space-Uid", - "in": "header" - }, - { - "description": "json data", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/structured.QueryTs" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.PromData" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.ErrResponse" - } - } - } - } - }, - "/query/ts/exemplar": { - "post": { - "produces": [ - "application/json" - ], - "summary": "query monitor by ts exemplar", - "operationId": "ts-query-exemplar-request", - "parameters": [ - { - "type": "string", - "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", - "description": "TraceID", - "name": "traceparent", - "in": "header" - }, - { - "type": "string", - "default": "username:goodman", - "description": "来源", - "name": "Bk-Query-Source", - "in": "header" - }, - { - "type": "string", - "default": "bkcc__2", - "description": "空间UID", - "name": "X-Bk-Scope-Space-Uid", - "in": "header" - }, - { - "description": "json data", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/structured.QueryTs" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.PromData" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.ErrResponse" - } - } - } - } - }, - "/query/ts/promql": { - "post": { - "produces": [ - "application/json" - ], - "summary": "query monitor by promql", - "operationId": "ts-query-request-promql", - "parameters": [ - { - "type": "string", - "default": "00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01", - "description": "TraceID", - "name": "traceparent", - "in": "header" - }, - { - "type": "string", - "default": "username:goodman", - "description": "来源", - "name": "Bk-Query-Source", - "in": "header" - }, - { - "type": "string", - "default": "bkcc__2", - "description": "空间UID", - "name": "X-Bk-Scope-Space-Uid", - "in": "header" - }, - { - "description": "json data", - "name": "data", - "in": "body", - "required": true, - "schema": { - "$ref": "#/definitions/structured.QueryPromQL" - } - } - ], - "responses": { - "200": { - "description": "OK", - "schema": { - "$ref": "#/definitions/http.PromData" - } - }, - "400": { - "description": "Bad Request", - "schema": { - "$ref": "#/definitions/http.ErrResponse" - } - } - } - } - } - }, - "definitions": { - "http.ErrResponse": { - "type": "object", - "properties": { - "error": { - "type": "string" - } - } - }, - "http.PromData": { - "type": "object", - "properties": { - "series": { - "type": "array", - "items": { - "$ref": "#/definitions/http.TablesItem" - } - }, - "status": { - "$ref": "#/definitions/metadata.Status" - } - } - }, - "http.TablesItem": { - "type": "object", - "properties": { - "columns": { - "type": "array", - "items": { - "type": "string" - } - }, - "group_keys": { - "type": "array", - "items": { - "type": "string" - } - }, - "group_values": { - "type": "array", - "items": { - "type": "string" - } - }, - "metric_name": { - "type": "string" - }, - "name": { - "type": "string" - }, - "types": { - "type": "array", - "items": { - "type": "string" - } - }, - "values": { - "type": "array", - "items": { - "type": "array", - "items": {} - } - } - } - }, - "metadata.Status": { - "type": "object", - "properties": { - "code": { - "type": "string" - }, - "message": { - "type": "string" - } - } - }, - "structured.AggregateMethod": { - "type": "object", - "properties": { - "dimensions": { - "description": "Dimensions 聚合维度", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "bk_target_ip", - "bk_target_cloud_id" - ] - }, - "method": { - "description": "Method 聚合方法", - "type": "string", - "example": "mean" - }, - "without": { - "description": "Without", - "type": "boolean" - } - } - }, - "structured.ConditionField": { - "type": "object", - "properties": { - "field_name": { - "description": "DimensionName 过滤字段", - "type": "string", - "example": "bk_biz_id" - }, - "op": { - "description": "Operator 操作符,包含:eq,ne,erq,nreq,contains,ncontains", - "type": "string", - "example": "contains" - }, - "value": { - "description": "Value 查询值", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "2" - ] - } - } - }, - "structured.Conditions": { - "type": "object", - "properties": { - "condition_list": { - "description": "ConditionList 组合条件,长度 = len(FieldList) - 1的数组,支持 and,or", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "and" - ] - }, - "field_list": { - "description": "FieldList 查询条件", - "type": "array", - "items": { - "$ref": "#/definitions/structured.ConditionField" - } - } - } - }, - "structured.Query": { - "type": "object", - "properties": { - "conditions": { - "description": "Conditions 过滤条件", - "allOf": [ - { - "$ref": "#/definitions/structured.Conditions" - } - ] - }, - "dimensions": { - "description": "Dimensions promQL 使用维度", - "type": "array", - "items": { - "type": "string" - }, - "example": [ - "bk_target_ip", - "bk_target_cloud_id" - ] - }, - "field_name": { - "description": "FieldName 查询指标", - "type": "string", - "example": "usage" - }, - "function": { - "description": "AggregateMethodList 维度聚合函数", - "type": "array", - "items": { - "$ref": "#/definitions/structured.AggregateMethod" - } - }, - "limit": { - "description": "Limit 点数限制数量", - "type": "integer", - "example": 0 - }, - "offset": { - "description": "Offset 偏移量", - "type": "string", - "example": "" - }, - "offset_forward": { - "description": "OffsetForward 偏移方向,默认 false 为向前偏移", - "type": "boolean", - "example": false - }, - "reference_name": { - "description": "ReferenceName 别名,用于表达式计算", - "type": "string", - "example": "a" - }, - "slimit": { - "description": "Slimit 维度限制数量", - "type": "integer", - "example": 0 - }, - "start_or_end": { - "description": "StartOrEnd @-modifier 标记,start or end", - "type": "integer" - }, - "table_id": { - "description": "TableID 数据实体ID,容器指标可以为空", - "type": "string", - "example": "system.cpu_summary" - }, - "time_aggregation": { - "description": "TimeAggregation 时间聚合方法", - "allOf": [ - { - "$ref": "#/definitions/structured.TimeAggregation" - } - ] - }, - "timestamp": { - "description": "Timestamp @-modifier 标记", - "type": "integer" - }, - "vector_offset": { - "description": "VectorOffset", - "allOf": [ - { - "$ref": "#/definitions/time.Duration" - } - ] - } - } - }, - "structured.QueryPromQL": { - "type": "object", - "properties": { - "bk_biz_ids": { - "type": "array", - "items": { - "type": "string" - } - }, - "end": { - "type": "string" - }, - "limit": { - "type": "integer" - }, - "max_source_resolution": { - "type": "string" - }, - "not_align_influxdb": { - "description": "不与influxdb对齐", - "type": "boolean" - }, - "promql": { - "type": "string" - }, - "slimit": { - "type": "integer" - }, - "start": { - "type": "string" - }, - "step": { - "type": "string" - } - } - }, - "structured.QueryTs": { - "type": "object", - "properties": { - "down_sample_range": { - "description": "DownSampleRange 降采样:大于Step才能生效,可以为空", - "type": "string", - "example": "5m" - }, - "end_time": { - "description": "End 结束时间:单位为毫秒的时间戳", - "type": "string", - "example": "1657851600" - }, - "metric_merge": { - "description": "MetricMerge 表达式:支持所有PromQL语法", - "type": "string", - "example": "a" - }, - "query_list": { - "description": "QueryList 查询实例", - "type": "array", - "items": { - "$ref": "#/definitions/structured.Query" - } - }, - "space_uid": { - "description": "SpaceUid 空间ID", - "type": "string" - }, - "start_time": { - "description": "Start 开始时间:单位为毫秒的时间戳", - "type": "string", - "example": "1657848000" - }, - "step": { - "description": "Step 步长:最终返回的点数的时间间隔", - "type": "string", - "example": "1m" - } - } - }, - "structured.TimeAggregation": { - "type": "object", - "properties": { - "function": { - "description": "Function 时间聚合方法", - "type": "string", - "example": "avg_over_time" - }, - "window": { - "description": "Window 聚合周期", - "type": "string", - "example": "60s" - } - } - }, - "time.Duration": { - "type": "integer", - "enum": [ - -9223372036854775808, - 9223372036854775807, - 1, - 1000, - 1000000, - 1000000000, - 60000000000, - 3600000000000 - ], - "x-enum-varnames": [ - "minDuration", - "maxDuration", - "Nanosecond", - "Microsecond", - "Millisecond", - "Second", - "Minute", - "Hour" - ] - } - } -} \ No newline at end of file diff --git a/pkg/unify-query/swagger/swagger.yaml b/pkg/unify-query/swagger/swagger.yaml deleted file mode 100644 index dedef5e36..000000000 --- a/pkg/unify-query/swagger/swagger.yaml +++ /dev/null @@ -1,364 +0,0 @@ -definitions: - http.ErrResponse: - properties: - error: - type: string - type: object - http.PromData: - properties: - series: - items: - $ref: '#/definitions/http.TablesItem' - type: array - status: - $ref: '#/definitions/metadata.Status' - type: object - http.TablesItem: - properties: - columns: - items: - type: string - type: array - group_keys: - items: - type: string - type: array - group_values: - items: - type: string - type: array - metric_name: - type: string - name: - type: string - types: - items: - type: string - type: array - values: - items: - items: { } - type: array - type: array - type: object - metadata.Status: - properties: - code: - type: string - message: - type: string - type: object - structured.AggregateMethod: - properties: - dimensions: - description: Dimensions 聚合维度 - example: - - bk_target_ip - - bk_target_cloud_id - items: - type: string - type: array - method: - description: Method 聚合方法 - example: mean - type: string - without: - description: Without - type: boolean - type: object - structured.ConditionField: - properties: - field_name: - description: DimensionName 过滤字段 - example: bk_biz_id - type: string - op: - description: Operator 操作符,包含:eq,ne,erq,nreq,contains,ncontains - example: contains - type: string - value: - description: Value 查询值 - example: - - "2" - items: - type: string - type: array - type: object - structured.Conditions: - properties: - condition_list: - description: ConditionList 组合条件,长度 = len(FieldList) - 1的数组,支持 and,or - example: - - and - items: - type: string - type: array - field_list: - description: FieldList 查询条件 - items: - $ref: '#/definitions/structured.ConditionField' - type: array - type: object - structured.Query: - properties: - conditions: - allOf: - - $ref: '#/definitions/structured.Conditions' - description: Conditions 过滤条件 - dimensions: - description: Dimensions promQL 使用维度 - example: - - bk_target_ip - - bk_target_cloud_id - items: - type: string - type: array - field_name: - description: FieldName 查询指标 - example: usage - type: string - function: - description: AggregateMethodList 维度聚合函数 - items: - $ref: '#/definitions/structured.AggregateMethod' - type: array - limit: - description: Limit 点数限制数量 - example: 0 - type: integer - offset: - description: Offset 偏移量 - example: "" - type: string - offset_forward: - description: OffsetForward 偏移方向,默认 false 为向前偏移 - example: false - type: boolean - reference_name: - description: ReferenceName 别名,用于表达式计算 - example: a - type: string - slimit: - description: Slimit 维度限制数量 - example: 0 - type: integer - start_or_end: - description: StartOrEnd @-modifier 标记,start or end - type: integer - table_id: - description: TableID 数据实体ID,容器指标可以为空 - example: system.cpu_summary - type: string - time_aggregation: - allOf: - - $ref: '#/definitions/structured.TimeAggregation' - description: TimeAggregation 时间聚合方法 - timestamp: - description: Timestamp @-modifier 标记 - type: integer - vector_offset: - allOf: - - $ref: '#/definitions/time.Duration' - description: VectorOffset - type: object - structured.QueryPromQL: - properties: - bk_biz_ids: - items: - type: string - type: array - end: - type: string - limit: - type: integer - max_source_resolution: - type: string - not_align_influxdb: - description: 不与influxdb对齐 - type: boolean - promql: - type: string - slimit: - type: integer - start: - type: string - step: - type: string - type: object - structured.QueryTs: - properties: - down_sample_range: - description: DownSampleRange 降采样:大于Step才能生效,可以为空 - example: 5m - type: string - end_time: - description: End 结束时间:单位为毫秒的时间戳 - example: "1657851600" - type: string - metric_merge: - description: MetricMerge 表达式:支持所有PromQL语法 - example: a - type: string - query_list: - description: QueryList 查询实例 - items: - $ref: '#/definitions/structured.Query' - type: array - space_uid: - description: SpaceUid 空间ID - type: string - start_time: - description: Start 开始时间:单位为毫秒的时间戳 - example: "1657848000" - type: string - step: - description: Step 步长:最终返回的点数的时间间隔 - example: 1m - type: string - type: object - structured.TimeAggregation: - properties: - function: - description: Function 时间聚合方法 - example: avg_over_time - type: string - window: - description: Window 聚合周期 - example: 60s - type: string - type: object - time.Duration: - enum: - - -9223372036854775808 - - 9223372036854775807 - - 1 - - 1000 - - 1000000 - - 1000000000 - - 60000000000 - - 3600000000000 - type: integer - x-enum-varnames: - - minDuration - - maxDuration - - Nanosecond - - Microsecond - - Millisecond - - Second - - Minute - - Hour -info: - contact: {} -paths: - /query/ts: - post: - operationId: ts-query-request - parameters: - - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 - description: TraceID - in: header - name: traceparent - type: string - - default: username:goodman - description: 来源 - in: header - name: Bk-Query-Source - type: string - - default: bkcc__2 - description: 空间UID - in: header - name: X-Bk-Scope-Space-Uid - type: string - - description: json data - in: body - name: data - required: true - schema: - $ref: '#/definitions/structured.QueryTs' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/http.PromData' - "400": - description: Bad Request - schema: - $ref: '#/definitions/http.ErrResponse' - summary: query monitor by ts - /query/ts/exemplar: - post: - operationId: ts-query-exemplar-request - parameters: - - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 - description: TraceID - in: header - name: traceparent - type: string - - default: username:goodman - description: 来源 - in: header - name: Bk-Query-Source - type: string - - default: bkcc__2 - description: 空间UID - in: header - name: X-Bk-Scope-Space-Uid - type: string - - description: json data - in: body - name: data - required: true - schema: - $ref: '#/definitions/structured.QueryTs' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/http.PromData' - "400": - description: Bad Request - schema: - $ref: '#/definitions/http.ErrResponse' - summary: query monitor by ts exemplar - /query/ts/promql: - post: - operationId: ts-query-request-promql - parameters: - - default: 00-3967ac0f1648bf0216b27631730d7eb9-8e3c31d5109e78dd-01 - description: TraceID - in: header - name: traceparent - type: string - - default: username:goodman - description: 来源 - in: header - name: Bk-Query-Source - type: string - - default: bkcc__2 - description: 空间UID - in: header - name: X-Bk-Scope-Space-Uid - type: string - - description: json data - in: body - name: data - required: true - schema: - $ref: '#/definitions/structured.QueryPromQL' - produces: - - application/json - responses: - "200": - description: OK - schema: - $ref: '#/definitions/http.PromData' - "400": - description: Bad Request - schema: - $ref: '#/definitions/http.ErrResponse' - summary: query monitor by promql -swagger: "2.0"