logsearch

package
v0.0.0-...-47e18b9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2021 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TaskMaxPreviewLines      = 500
	TaskGroupMaxPreviewLines = 5000
)

Variables

View Source
var MaxRecvMsgSize = math.MaxInt64

MaxRecvMsgSize set max gRPC receive message size received from server. If any message size is larger than current value, an error will be reported from gRPC.

Functions

func RegisterRouter

func RegisterRouter(r *gin.RouterGroup, auth *user.AuthService, s *Service)

Types

type CreateTaskGroupRequest

type CreateTaskGroupRequest struct {
	Request SearchLogRequest          `json:"request" binding:"required"`
	Targets []model.RequestTargetNode `json:"targets" binding:"required"`
}

type LogLevel

type LogLevel int32
const (
	LogLevelUnknown  LogLevel = 0
	LogLevelDebug    LogLevel = 1
	LogLevelInfo     LogLevel = 2
	LogLevelWarn     LogLevel = 3
	LogLevelTrace    LogLevel = 4
	LogLevelCritical LogLevel = 5
	LogLevelError    LogLevel = 6
)

type PreviewModel

type PreviewModel struct {
	ID          uint                   `json:"id" grom:"primary_key"`
	TaskID      uint                   `json:"task_id" gorm:"index:task"`
	TaskGroupID uint                   `json:"task_group_id" gorm:"index:task_group"`
	Time        int64                  `json:"time" gorm:"index:task,task_group"`
	Level       diagnosticspb.LogLevel `json:"level" gorm:"type:integer"`
	Message     string                 `json:"message" gorm:"type:text"`
}

func (PreviewModel) TableName

func (PreviewModel) TableName() string

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

func NewScheduler

func NewScheduler(service *Service) *Scheduler

func (*Scheduler) AsyncAbort

func (s *Scheduler) AsyncAbort(taskGroupID uint) bool

func (*Scheduler) AsyncStart

func (s *Scheduler) AsyncStart(taskGroupModel *TaskGroupModel, tasksModel []*TaskModel) bool

type SearchLogRequest

type SearchLogRequest struct {
	StartTime int64    `json:"start_time"`
	EndTime   int64    `json:"end_time"`
	MinLevel  LogLevel `json:"min_level"`
	// We use a string array to represent multiple CNF pattern sceniaor like:
	// SELECT * FROM t WHERE c LIKE '%s%' and c REGEXP '.*a.*' because
	// Golang and Rust don't support perl-like (?=re1)(?=re2)
	Patterns []string `json:"patterns"`
}

func (*SearchLogRequest) ConvertToPB

func (*SearchLogRequest) Scan

func (r *SearchLogRequest) Scan(src interface{}) error

func (*SearchLogRequest) Value

func (r *SearchLogRequest) Value() (driver.Value, error)

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(lc fx.Lifecycle, config *config.Config, db *dbstore.DB) *Service

func (*Service) CancelTask

func (s *Service) CancelTask(c *gin.Context)

@Summary Cancel running tasks in a log search task group @Param id path string true "task group id" @Security JwtAuth @Success 200 {object} utils.APIEmptyResponse @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 400 {object} utils.APIError @Router /logs/taskgroups/{id}/cancel [post]

func (*Service) CreateTaskGroup

func (s *Service) CreateTaskGroup(c *gin.Context)

@Summary Create and run a new log search task group @Param request body CreateTaskGroupRequest true "Request body" @Security JwtAuth @Success 200 {object} TaskGroupResponse @Failure 400 {object} utils.APIError "Bad request" @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 500 {object} utils.APIError @Router /logs/taskgroup [put]

func (*Service) DeleteTaskGroup

func (s *Service) DeleteTaskGroup(c *gin.Context)

@Summary Delete a log search task group @Param id path string true "task group id" @Security JwtAuth @Success 200 {object} utils.APIEmptyResponse @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 500 {object} utils.APIError @Router /logs/taskgroups/{id} [delete]

func (*Service) DownloadLogs

func (s *Service) DownloadLogs(c *gin.Context)

@Summary Download logs @Produce application/x-tar,application/zip @Param token query string true "download token" @Failure 400 {object} utils.APIError @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 500 {object} utils.APIError @Router /logs/download [get]

func (*Service) GetAllTaskGroups

func (s *Service) GetAllTaskGroups(c *gin.Context)

@Summary List all log search task groups @Security JwtAuth @Success 200 {array} TaskGroupModel @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 500 {object} utils.APIError @Router /logs/taskgroups [get]

func (*Service) GetDownloadToken

func (s *Service) GetDownloadToken(c *gin.Context)

@Summary Generate a download token for downloading logs @Produce plain @Param id query []string false "task id" collectionFormat(csv) @Security JwtAuth @Success 200 {string} string "xxx" @Failure 400 {object} utils.APIError @Failure 401 {object} utils.APIError "Unauthorized failure" @Router /logs/download/acquire_token [get]

func (*Service) GetTaskGroup

func (s *Service) GetTaskGroup(c *gin.Context)

@Summary List tasks in a log search task group @Param id path string true "Task Group ID" @Security JwtAuth @Success 200 {object} TaskGroupResponse @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 500 {object} utils.APIError @Router /logs/taskgroups/{id} [get]

func (*Service) GetTaskGroupPreview

func (s *Service) GetTaskGroupPreview(c *gin.Context)

@Summary Preview a log search task group @Param id path string true "task group id" @Security JwtAuth @Success 200 {array} PreviewModel @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 500 {object} utils.APIError @Router /logs/taskgroups/{id}/preview [get]

func (*Service) RetryTask

func (s *Service) RetryTask(c *gin.Context)

@Summary Retry failed tasks in a log search task group @Param id path string true "task group id" @Security JwtAuth @Success 200 {object} utils.APIEmptyResponse @Failure 400 {object} utils.APIError @Failure 401 {object} utils.APIError "Unauthorized failure" @Failure 500 {object} utils.APIError @Router /logs/taskgroups/{id}/retry [post]

type Task

type Task struct {
	// contains filtered or unexported fields
}

func (*Task) Abort

func (t *Task) Abort()

This function is multi-thread safe.

func (*Task) String

func (t *Task) String() string

func (*Task) SyncRun

func (t *Task) SyncRun()

type TaskGroup

type TaskGroup struct {
	// contains filtered or unexported fields
}

func (*TaskGroup) AbortAll

func (tg *TaskGroup) AbortAll()

This function is multi-thread safe.

func (*TaskGroup) InitTasks

func (tg *TaskGroup) InitTasks(ctx context.Context, taskModels []*TaskModel)

func (*TaskGroup) SyncRun

func (tg *TaskGroup) SyncRun()

type TaskGroupModel

type TaskGroupModel struct {
	ID            uint                          `json:"id" gorm:"primary_key"`
	SearchRequest *SearchLogRequest             `json:"search_request" gorm:"type:text"`
	State         TaskGroupState                `json:"state" gorm:"index"`
	TargetStats   model.RequestTargetStatistics `json:"target_stats" gorm:"embedded;embedded_prefix:target_stats_"`
	LogStoreDir   *string                       `json:"log_store_dir" gorm:"type:text"`
}

func (*TaskGroupModel) Delete

func (tg *TaskGroupModel) Delete(db *dbstore.DB)

func (TaskGroupModel) TableName

func (TaskGroupModel) TableName() string

type TaskGroupResponse

type TaskGroupResponse struct {
	TaskGroup TaskGroupModel `json:"task_group"`
	Tasks     []*TaskModel   `json:"tasks"`
}

type TaskGroupState

type TaskGroupState int
const (
	TaskGroupStateRunning  TaskGroupState = 1
	TaskGroupStateFinished TaskGroupState = 2
)

type TaskModel

type TaskModel struct {
	ID               uint                     `json:"id" gorm:"primary_key"`
	TaskGroupID      uint                     `json:"task_group_id" gorm:"index"`
	Target           *model.RequestTargetNode `json:"target" gorm:"embedded;embedded_prefix:target_"`
	State            TaskState                `json:"state" gorm:"index"`
	LogStorePath     *string                  `json:"log_store_path" gorm:"type:text"`
	SlowLogStorePath *string                  `json:"slow_log_store_path" gorm:"type:text"`
	Size             int64                    `json:"size" gorm:"index"`
	Error            *string                  `json:"error" gorm:"type:text"`
}

func (*TaskModel) RemoveDataAndPreview

func (task *TaskModel) RemoveDataAndPreview(db *dbstore.DB)

Note: this function does not save model itself.

func (TaskModel) TableName

func (TaskModel) TableName() string

type TaskState

type TaskState int
const (
	TaskStateRunning  TaskState = 1
	TaskStateFinished TaskState = 2
	TaskStateError    TaskState = 3
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL