Skip to content

Commit

Permalink
add query context
Browse files Browse the repository at this point in the history
  • Loading branch information
fuwx295 committed Oct 18, 2024
1 parent 9ce7ee1 commit f89ac34
Show file tree
Hide file tree
Showing 18 changed files with 414 additions and 14 deletions.
77 changes: 77 additions & 0 deletions backend/docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,46 @@ const docTemplate = `{
}
}
},
"/api/log/context": {
"post": {
"description": "获取日志上下文",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"API.log"
],
"summary": "获取日志上下文",
"parameters": [
{
"description": "请求信息",
"name": "Request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.LogQueryContextRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.LogQueryContextResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/code.Failure"
}
}
}
}
},
"/api/log/fault/content": {
"post": {
"description": "获取故障现场日志内容",
Expand Down Expand Up @@ -4904,6 +4944,26 @@ const docTemplate = `{
}
}
},
"request.LogQueryContextRequest": {
"type": "object",
"properties": {
"dataBase": {
"type": "string"
},
"tableName": {
"type": "string"
},
"tags": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"timestamp": {
"type": "integer"
}
}
},
"request.LogQueryRequest": {
"type": "object",
"required": [
Expand Down Expand Up @@ -6151,6 +6211,23 @@ const docTemplate = `{
}
}
},
"response.LogQueryContextResponse": {
"type": "object",
"properties": {
"back": {
"type": "array",
"items": {
"$ref": "#/definitions/response.LogItem"
}
},
"front": {
"type": "array",
"items": {
"$ref": "#/definitions/response.LogItem"
}
}
}
},
"response.LogQueryResponse": {
"type": "object",
"properties": {
Expand Down
77 changes: 77 additions & 0 deletions backend/docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,46 @@
}
}
},
"/api/log/context": {
"post": {
"description": "获取日志上下文",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"API.log"
],
"summary": "获取日志上下文",
"parameters": [
{
"description": "请求信息",
"name": "Request",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/request.LogQueryContextRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/response.LogQueryContextResponse"
}
},
"400": {
"description": "Bad Request",
"schema": {
"$ref": "#/definitions/code.Failure"
}
}
}
}
},
"/api/log/fault/content": {
"post": {
"description": "获取故障现场日志内容",
Expand Down Expand Up @@ -4896,6 +4936,26 @@
}
}
},
"request.LogQueryContextRequest": {
"type": "object",
"properties": {
"dataBase": {
"type": "string"
},
"tableName": {
"type": "string"
},
"tags": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"timestamp": {
"type": "integer"
}
}
},
"request.LogQueryRequest": {
"type": "object",
"required": [
Expand Down Expand Up @@ -6143,6 +6203,23 @@
}
}
},
"response.LogQueryContextResponse": {
"type": "object",
"properties": {
"back": {
"type": "array",
"items": {
"$ref": "#/definitions/response.LogItem"
}
},
"front": {
"type": "array",
"items": {
"$ref": "#/definitions/response.LogItem"
}
}
}
},
"response.LogQueryResponse": {
"type": "object",
"properties": {
Expand Down
50 changes: 50 additions & 0 deletions backend/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,19 @@ definitions:
required:
- endTime
type: object
request.LogQueryContextRequest:
properties:
dataBase:
type: string
tableName:
type: string
tags:
additionalProperties:
type: string
type: object
timestamp:
type: integer
type: object
request.LogQueryRequest:
properties:
dataBase:
Expand Down Expand Up @@ -1813,6 +1826,17 @@ definitions:
type: string
type: array
type: object
response.LogQueryContextResponse:
properties:
back:
items:
$ref: '#/definitions/response.LogItem'
type: array
front:
items:
$ref: '#/definitions/response.LogItem'
type: array
type: object
response.LogQueryResponse:
properties:
cost:
Expand Down Expand Up @@ -2518,6 +2542,32 @@ paths:
summary: 获取日志趋势图
tags:
- API.log
/api/log/context:
post:
consumes:
- application/json
description: 获取日志上下文
parameters:
- description: 请求信息
in: body
name: Request
required: true
schema:
$ref: '#/definitions/request.LogQueryContextRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/response.LogQueryContextResponse'
"400":
description: Bad Request
schema:
$ref: '#/definitions/code.Failure'
summary: 获取日志上下文
tags:
- API.log
/api/log/fault/content:
post:
description: 获取故障现场日志内容
Expand Down
43 changes: 43 additions & 0 deletions backend/pkg/api/log/func_querylogcontext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package log

import (
"net/http"

"github.com/CloudDetail/apo/backend/pkg/code"
"github.com/CloudDetail/apo/backend/pkg/core"
"github.com/CloudDetail/apo/backend/pkg/model/request"
)

// QueryLogContext 获取日志上下文
// @Summary 获取日志上下文
// @Description 获取日志上下文
// @Tags API.log
// @Accept json
// @Produce json
// @Param Request body request.LogQueryContextRequest true "请求信息"
// @Success 200 {object} response.LogQueryContextResponse
// @Failure 400 {object} code.Failure
// @Router /api/log/context [post]
func (h *handler) QueryLogContext() core.HandlerFunc {
return func(c core.Context) {
req := new(request.LogQueryContextRequest)
if err := c.ShouldBindJSON(req); err != nil {
c.AbortWithError(core.Error(
http.StatusBadRequest,
code.ParamBindError,
code.Text(code.ParamBindError)).WithError(err),
)
return
}
resp, err := h.logService.QueryLogContext(req)
if err != nil {
c.AbortWithError(core.Error(
http.StatusBadRequest,
code.QueryLogContextError,
code.Text(code.QueryLogContextError)).WithError(err),
)
return
}
c.Payload(resp)
}
}
5 changes: 5 additions & 0 deletions backend/pkg/api/log/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ type Handler interface {
// @Tags API.log
// @Router /api/log/other/delete [delete]
DeleteOtherTable() core.HandlerFunc

// QueryLogContext 获取日志上下文
// @Tags API.log
// @Router /api/log/context [post]
QueryLogContext() core.HandlerFunc
}

type handler struct {
Expand Down
7 changes: 4 additions & 3 deletions backend/pkg/code/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ const (
GetFaultLogPageListError = "B0401"
GetFaultLogContentError = "B0402"

QueryLogError = "B0406"
GetLogChartError = "B0407"
GetLogIndexError = "B0408"
QueryLogContextError = "B0405"
QueryLogError = "B0406"
GetLogChartError = "B0407"
GetLogIndexError = "B0408"

GetLogTableInfoError = "B0409"

Expand Down
7 changes: 4 additions & 3 deletions backend/pkg/code/en.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ var enText = map[string]string{
GetFaultLogContentError: "Failed to get fault log content",
GetMonitorStatusError: "Failed to get monitor status",

QueryLogError: "Failed to query all logs",
GetLogChartError: "Failed to get log chart",
GetLogIndexError: "Failed to get log index",
QueryLogContextError: "Failed to query log context",
QueryLogError: "Failed to query all logs",
GetLogChartError: "Failed to get log chart",
GetLogIndexError: "Failed to get log index",

GetLogTableInfoError: "Failed to get log table info",
GetLogParseRuleError: "Failed to get log parse rule",
Expand Down
7 changes: 4 additions & 3 deletions backend/pkg/code/zh-cn.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ var zhCnText = map[string]string{
GetFaultLogPageListError: "获取故障现场日志分页列表失败",
GetFaultLogContentError: "获取故障现场日志内容失败",

QueryLogError: "查询全量日志失败",
GetLogChartError: "获取全量日志图表数据失败",
GetLogIndexError: "获取全量日志索引失败",
QueryLogContextError: "查询日志上下文失败",
QueryLogError: "查询全量日志失败",
GetLogChartError: "获取全量日志图表数据失败",
GetLogIndexError: "获取全量日志索引失败",

GetLogTableInfoError: "获取日志表信息失败",
GetLogParseRuleError: "获取日志表解析规则失败",
Expand Down
7 changes: 7 additions & 0 deletions backend/pkg/model/request/log_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ type LogIndexRequest struct {
LogField string `json:"logField"`
Query string `json:"query"`
}

type LogQueryContextRequest struct {
TableName string `json:"tableName"`
DataBase string `json:"dataBase"`
Tags map[string]string `json:"tags"`
Time int64 `json:"timestamp"`
}
5 changes: 5 additions & 0 deletions backend/pkg/model/response/log_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ type LogItem struct {
Tags map[string]interface{} `json:"tags"`
Time int64 `json:"timestamp"`
}

type LogQueryContextResponse struct {
Front []LogItem `json:"front"`
Back []LogItem `json:"back"`
}
1 change: 1 addition & 0 deletions backend/pkg/repository/clickhouse/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Repo interface {
queryRowsData(sql string) ([]map[string]any, error)

QueryAllLogs(req *request.LogQueryRequest) ([]map[string]any, string, error)
QueryLogContext(req *request.LogQueryContextRequest) ([]map[string]any, []map[string]any, error)
GetLogChart(req *request.LogQueryRequest) ([]map[string]any, int64, error)
GetLogIndex(req *request.LogIndexRequest) (map[string]uint64, uint64, error)

Expand Down
Loading

0 comments on commit f89ac34

Please sign in to comment.