clickhouse

package
v0.0.0-...-385b71e Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// The SQL _GET_SAMPLE_ALERT_EVENT are grouped by the alarm_event name. Each group takes the record with the latest event and records the number of alarms with the same name in the returned result.
	SQL_GET_SAMPLE_ALERT_EVENT = `` /* 512-byte string literal not displayed */

	SQL_GET_GROUP_COUNTS_ALERT_EVENT = `` /* 216-byte string literal not displayed */

	// SQL _GET_PAGED_ALERT_EVENT paging out all alarm events that meet the conditions
	SQL_GET_PAGED_ALERT_EVENT = `` /* 284-byte string literal not displayed */

)
View Source
const (
	SQL_GET_APP_LOG_SOURCE = `SELECT LogAttributes['_source_'] as LogSource
		FROM ilogtail_logs
		%s %s`
	SQL_GET_APP_LOG = `SELECT toUnixTimestamp64Micro(Timestamp) as ts,Body
		FROM ilogtail_logs
		%s %s`
)
View Source
const (
	SQL_GET_PARENT_NODES = `` /* 409-byte string literal not displayed */

	SQL_GET_CHILD_NODES = `` /* 343-byte string literal not displayed */

	SQL_GET_DESCENDANT_TOPOLOGY = `` /* 869-byte string literal not displayed */

	SQL_GET_ENTRY_NODES = `
		SELECT entry_service, entry_url
		FROM service_relationship
		%s
		GROUP BY entry_service, entry_url
	`
)
View Source
const (
	TEMPLATE_COUNT_SPAN_TRACE = "SELECT count(1) as total FROM span_trace %s"
	TEMPLATE_QUERY_SPAN_TRACE = "SELECT %s FROM span_trace %s %s"

	SQL_GET_LABEL_FILTER_KEYS = `` /* 135-byte string literal not displayed */

	SQL_GET_FLAGS_FILTER_KEYS = `` /* 131-byte string literal not displayed */

	SQL_GET_FILTER_VALUES = `SELECT DISTINCT
	%s as label_value
	FROM span_trace st
	%s %s`
)
View Source
const (
	SQL_GET_INSTANCE_ERROR_PROPAGATION = `` /* 2325-byte string literal not displayed */

)
View Source
const (

	// SQL _GET_K8S_EVENTS get K8s event alarm
	SQL_GET_K8S_EVENTS = `` /* 339-byte string literal not displayed */

)

Variables

View Source
var (
	ALWAYS_TRUE = &whereSQL{
		Wheres: "TRUE",
	}

	ALWAYS_FALSE = &whereSQL{
		Wheres: "FALSE",
	}
)

Functions

func AppendToBuilder

func AppendToBuilder(builder *QueryBuilder, f *request.SpanTraceFilter) error

func Equals

func Equals(key string, value string) *whereSQL

func EqualsIfNotEmpty

func EqualsIfNotEmpty(key string, value string) *whereSQL

When the EqualsIfNotEmpty value length is 0, always true is returned

func GetAlertType

func GetAlertType(g string) string

func In

func In(key string, values clickhouse.ArraySet) *whereSQL

func InGroup

func InGroup(vgs ValueInGroups) *whereSQL

func MergeWheres

func MergeWheres(sep MergeSep, whereSQLs ...*whereSQL) *whereSQL

MergeWheres merge multiple conditions

func NewQueryCondition

func NewQueryCondition(st, et int64, timeField, query string) string

func RnLimit

func RnLimit(p *request.PageParam) string

func ValidCheckAndAdjust

func ValidCheckAndAdjust(f *request.SpanTraceFilter) bool

Types

type AlertEventSample

type AlertEventSample struct {
	model.AlertEvent

	// Record line number
	Rn         uint64 `ch:"rn" json:"-"`
	AlarmCount uint64 `ch:"alarm_count" json:"alarmCount"`

	AlertKey string `ch:"alert_key" json:"alertKey"`
}

type AlertGroup

type AlertGroup string
const (
	APP_GROUP        AlertGroup = "app"
	NETWORK_GROUP    AlertGroup = "network"
	CONTAINER_GROUP  AlertGroup = "container"
	INFRA_GROUP      AlertGroup = "infra"
	MIDDLEWARE_GROUP AlertGroup = "middleware"
)

func (AlertGroup) GetAlertType

func (g AlertGroup) GetAlertType() string

type AvailableFilters

type AvailableFilters struct {
	Filters          []request.SpanTraceFilter
	FilterUpdateTime time.Time
}

type ByLimitBuilder

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

func NewByLimitBuilder

func NewByLimitBuilder() *ByLimitBuilder

func (*ByLimitBuilder) GroupBy

func (builder *ByLimitBuilder) GroupBy(keys ...string) *ByLimitBuilder

func (*ByLimitBuilder) Limit

func (builder *ByLimitBuilder) Limit(limit int) *ByLimitBuilder

func (*ByLimitBuilder) Offset

func (builder *ByLimitBuilder) Offset(offset int) *ByLimitBuilder

func (*ByLimitBuilder) OrderBy

func (builder *ByLimitBuilder) OrderBy(key string, asc bool) *ByLimitBuilder

func (*ByLimitBuilder) String

func (builder *ByLimitBuilder) String() string

Return GroupBy, OrderBy, and Limit

type ChildNode

type ChildNode struct {
	Service     string `ch:"service"`
	Url         string `ch:"url"`
	IsTraced    bool   `ch:"traced"`
	ClientGroup string `ch:"clientGroup"`
	ClientType  string `ch:"clientType"`
	ClientPeer  string `ch:"clientPeer"`
	ClientKey   string `ch:"clientKey"`
}

type ChildRelation

type ChildRelation struct {
	ParentService string `ch:"parentService"`
	ParentUrl     string `ch:"parentUrl"`
	Service       string `ch:"service"`
	Url           string `ch:"url"`
	IsTraced      bool   `ch:"traced"`
	ClientGroup   string `ch:"clientGroup"`
	ClientType    string `ch:"clientType"`
	ClientPeer    string `ch:"clientPeer"`
	ClientKey     string `ch:"clientKey"`
}

type EntryNode

type EntryNode struct {
	Service  string `ch:"entry_service" json:"service"`
	Endpoint string `ch:"entry_url" json:"endpoint"`
}

type ErrorInstancePropagation

type ErrorInstancePropagation struct {
	Timestamp       time.Time `ch:"timestamp"`
	Service         string    `ch:"service"`
	InstanceId      string    `ch:"instance_id"`
	TraceId         string    `ch:"trace_id"`
	ErrorTypes      []string  `ch:"error_types"`
	ErrorMsgs       []string  `ch:"error_msgs"`
	ParentServices  []string  `ch:"parent_services"`
	ParentInstances []string  `ch:"parent_instances"`
	ParentTraced    []bool    `ch:"parent_traced"`
	ChildServices   []string  `ch:"child_services"`
	ChildInstances  []string  `ch:"child_instances"`
	ChildTraced     []bool    `ch:"child_traced"`
}

type FaultLogQuery

type FaultLogQuery struct {
	StartTime      int64
	EndTime        int64
	Service        string
	Instance       string
	NodeName       string
	ContainerId    string
	Pid            uint32
	EndPoint       string
	TraceId        string
	PageNum        int
	PageSize       int
	Type           int      // 0 - slow & error, 1 - error
	MultiServices  []string // Match multiple service
	MultiNamespace []string // Match multiple namespace
}

type FaultLogResult

type FaultLogResult struct {
	ServiceName string `ch:"service_name" json:"serviceName"`
	InstanceId  string `ch:"instance_id" json:"instanceId"`
	TraceId     string `ch:"trace_id" json:"traceId"`
	StartTime   uint64 `ch:"start_time_us" json:"startTime"`
	EndTime     uint64 `ch:"end_time_us" json:"endTime"`
	EndPoint    string `ch:"endpoint" json:"endpoint"`
	PodName     string `ch:"pod_name" json:"podName"`
	ContainerId string `ch:"container_id" json:"containerId"`
	NodeName    string `ch:"node_name" json:"nodeName"`
	Pid         uint32 `ch:"pid" json:"pid"`
}

type FieldBuilder

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

func NewFieldBuilder

func NewFieldBuilder() *FieldBuilder

func (*FieldBuilder) Alias

func (builder *FieldBuilder) Alias(key string, alias string) *FieldBuilder

func (*FieldBuilder) Fields

func (builder *FieldBuilder) Fields(keys ...string) *FieldBuilder

func (*FieldBuilder) String

func (builder *FieldBuilder) String() string

Return the search field

type FlameGraphData

type FlameGraphData struct {
	StartTime   int64             `ch:"start_time" json:"startTime"`
	EndTime     int64             `ch:"end_time" json:"endTime"`
	PID         uint32            `ch:"pid" json:"pid"`
	TID         uint32            `ch:"tid" json:"tid"`
	SampleType  string            `ch:"sample_type" json:"sampleType"`
	SampleRate  uint32            `ch:"sample_rate" json:"sampleRate"`
	Labels      map[string]string `ch:"labels" json:"labels"`
	FlameBearer string            `ch:"flamebearer" json:"flameBearer"`
}

type K8sEvents

type K8sEvents struct {
	Timestamp          time.Time         `ch:"Timestamp" json:"timestamp"`
	SeverityText       string            `ch:"SeverityText" json:"SeverityText"`
	Body               string            `ch:"Body" json:"body"`
	ResourceAttributes map[string]string `ch:"ResourceAttributes" json:"resourceAttributes"`
	LogAttributes      map[string]string `ch:"LogAttributes" json:"logAttributes"`
}

func (*K8sEvents) GetObjKind

func (e *K8sEvents) GetObjKind() string

func (*K8sEvents) GetObjName

func (e *K8sEvents) GetObjName() string

func (*K8sEvents) GetReason

func (e *K8sEvents) GetReason() string

type K8sEventsCount

type K8sEventsCount struct {
	TimeRange string
	Reason    string
	Severity  string
	Count     uint64
}

type LogContent

type LogContent struct {
	Timestamp int64  `ch:"ts" json:"timestamp"`
	Body      string `ch:"Body" json:"body"`
}

type Logs

type Logs struct {
	Source   string       `json:"source"`
	Contents []LogContent `json:"contents"`
}

type MergeSep

type MergeSep string
const (
	AndSep MergeSep = " AND "
	OrSep  MergeSep = " OR "
)

type NetSegments

type NetSegments struct {
	StartTime        time.Time `ch:"start_time"`
	EndTime          time.Time `ch:"end_time"`
	ResponseDuration uint64    `ch:"response_duration"`
	TapSide          string    `ch:"tap_side"`
	SpanId           string    `ch:"span_id"`
	TraceId          string    `ch:"trace_id"`
}

type PagedAlertEvent

type PagedAlertEvent struct {
	model.AlertEvent

	// Record line number
	Rn         uint64 `ch:"rn" json:"-"`
	TotalCount uint64 `ch:"total_count" json:"-"`
}

type ParentNode

type ParentNode struct {
	ParentService string `ch:"parentService"`
	ParentUrl     string `ch:"parentUrl"`
	ParentTraced  bool   `ch:"parentTraced"`
	ClientGroup   string `ch:"clientGroup"`
	ClientType    string `ch:"clientType"`
	ClientPeer    string `ch:"clientPeer"`
	ClientKey     string `ch:"clientKey"`
}

type ProfilingEvent

type ProfilingEvent struct {
	Timestamp       time.Time         `json:"timestamp" ch:"timestamp"`
	StartTime       uint64            `json:"startTime" ch:"startTime"`
	EndTime         uint64            `json:"endTime" ch:"endTime"`
	Offset          int64             `json:"offset" ch:"offset"`
	PID             uint32            `json:"pid" ch:"pid"`
	TID             uint32            `json:"tid" ch:"tid"`
	TransactionIDs  string            `json:"transactionIds" ch:"transactionIds"`
	CPUEvents       string            `json:"cpuEvents" ch:"cpuEvents"`
	InnerCalls      string            `json:"innerCalls" ch:"innerCalls"`
	JavaFutexEvents string            `json:"javaFutexEvents" ch:"javaFutexEvents"`
	Spans           string            `json:"spans" ch:"spans"`
	ThreadName      string            `json:"threadName" ch:"threadName"` // thread name table in labels
	Labels          map[string]string `json:"labels" ch:"labels"`
}

type QueryBuilder

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

func NewQueryBuilder

func NewQueryBuilder() *QueryBuilder

func (*QueryBuilder) And

func (builder *QueryBuilder) And(where *whereSQL) *QueryBuilder

And Add a series of conditional whereSQL to the QueryBuilder as And

func (*QueryBuilder) Between

func (builder *QueryBuilder) Between(key string, from interface{}, to interface{}) *QueryBuilder

func (*QueryBuilder) Contains

func (builder *QueryBuilder) Contains(key string, value any) *QueryBuilder

func (*QueryBuilder) Equals

func (builder *QueryBuilder) Equals(key string, value interface{}) *QueryBuilder

func (*QueryBuilder) EqualsNotEmpty

func (builder *QueryBuilder) EqualsNotEmpty(key string, value string) *QueryBuilder

func (*QueryBuilder) Exists

func (builder *QueryBuilder) Exists(key string) *QueryBuilder

func (*QueryBuilder) GreaterThan

func (builder *QueryBuilder) GreaterThan(key string, value any) *QueryBuilder

func (*QueryBuilder) In

func (builder *QueryBuilder) In(key string, values any) *QueryBuilder

The key in (values) statement in the SQL statement is generated by combination. The value array is inside the value array.

func (*QueryBuilder) InStrings

func (builder *QueryBuilder) InStrings(key string, values []string) *QueryBuilder

func (*QueryBuilder) LessThan

func (builder *QueryBuilder) LessThan(key string, value any) *QueryBuilder

func (*QueryBuilder) Like

func (builder *QueryBuilder) Like(key string, values any) *QueryBuilder

func (*QueryBuilder) NotContains

func (builder *QueryBuilder) NotContains(key string, value any) *QueryBuilder

func (*QueryBuilder) NotEquals

func (builder *QueryBuilder) NotEquals(key string, value interface{}) *QueryBuilder

func (*QueryBuilder) NotExists

func (builder *QueryBuilder) NotExists(key string) *QueryBuilder

func (*QueryBuilder) NotIn

func (builder *QueryBuilder) NotIn(key string, values any) *QueryBuilder

func (*QueryBuilder) NotLike

func (builder *QueryBuilder) NotLike(key string, values any) *QueryBuilder

func (*QueryBuilder) Statement

func (builder *QueryBuilder) Statement(where string) *QueryBuilder

func (*QueryBuilder) String

func (builder *QueryBuilder) String() string

Return the query condition

type QueryCount

type QueryCount struct {
	Total uint64 `ch:"total"`
}

type QueryTraceResult

type QueryTraceResult struct {
	Timestamp         int64   `ch:"ts" json:"timestamp"`
	Duration          uint64  `ch:"duration_us" json:"duration"`
	ServiceName       string  `ch:"service_name" json:"serviceName"`
	Pid               uint32  `ch:"pid" json:"pid"`
	Tid               uint32  `ch:"tid" json:"tid"`
	TraceId           string  `ch:"trace_id" json:"traceId"`
	EndPoint          string  `ch:"endpoint" json:"endpoint"`
	InstanceId        string  `ch:"instance_id" json:"instanceId"`
	SpanId            string  `ch:"span_id" json:"spanId"`
	ApmType           string  `ch:"apm_type" json:"apmType"`
	Reason            string  `ch:"reason" json:"reason"`
	IsError           bool    `ch:"is_error" json:"isError"`
	IsSlow            bool    `ch:"is_slow" json:"isSlow"`
	ThresholdValue    float64 `ch:"threshold_value" json:"thresholdValue"`
	ThresholdMultiple float64 `ch:"threshold_multiple" json:"thresholdMultiple"`

	Labels  map[string]string `ch:"labels" json:"labels"`
	Flags   map[string]bool   `ch:"flags"  json:"flags"`
	Metrics map[string]uint64 `ch:"metrics" json:"metrics"`

	MutatedValue uint64 `ch:"mutated_value" json:"mutatedValue"`
	IsMutated    uint8  `ch:"is_mutated" json:"isMutated"` // whether the delay changes abruptly
}

type Repo

type Repo interface {
	// ========== service_relationship ==========
	// Query the list of upstream nodes
	ListParentNodes(req *request.GetServiceEndpointTopologyRequest) (*model.TopologyNodes, error)
	// Query the list of downstream nodes
	ListChildNodes(req *request.GetServiceEndpointTopologyRequest) (*model.TopologyNodes, error)
	// Query the list of all descendant service nodes
	ListDescendantNodes(req *request.GetDescendantMetricsRequest) (*model.TopologyNodes, error)
	// Query the calling relationship of all descendant nodes
	ListDescendantRelations(req *request.GetServiceEndpointTopologyRequest) ([]*model.ToplogyRelation, error)
	// Query the entry node list
	ListEntryEndpoints(req *request.GetServiceEntryEndpointsRequest) ([]EntryNode, error)

	// ========== error_propagation ==========
	// Query instance-related error propagation chain
	ListErrorPropagation(req *request.GetErrorInstanceRequest) ([]ErrorInstancePropagation, error)

	// ========== span_trace ==========
	GetAvailableFilterKey(startTime, endTime time.Time, needUpdate bool) ([]request.SpanTraceFilter, error)
	UpdateFilterKey(startTime, endTime time.Time) ([]request.SpanTraceFilter, error)
	GetFieldValues(searchText string, filter *request.SpanTraceFilter, startTime, endTime time.Time) (*SpanTraceOptions, error)
	// Paging query the fault site log list
	GetFaultLogPageList(query *FaultLogQuery) ([]FaultLogResult, int64, error)
	// Paged Trace List
	GetTracePageList(req *request.GetTracePageListRequest) ([]QueryTraceResult, int64, error)

	CountK8sEvents(startTime int64, endTim int64, pods []string) ([]K8sEventsCount, error)

	// ========== application_logs ==========
	// Query the log content of the fault site. The sourceFrom can be blank. The log in the first source that can be found will be returned.
	QueryApplicationLogs(req *request.GetFaultLogContentRequest) (logContents *Logs, availableSource []string, err error)
	// Query the available source of the fault field log content
	QueryApplicationLogsAvailableSource(faultLog FaultLogResult) ([]string, error)

	CreateLogTable(req *request.LogTableRequest) ([]string, error)
	DropLogTable(req *request.LogTableRequest) ([]string, error)
	UpdateLogTable(req *request.LogTableRequest, old []request.Field) ([]string, 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)

	OtherLogTable() ([]map[string]any, error)
	OtherLogTableInfo(req *request.OtherTableInfoRequest) ([]map[string]any, error)

	InsertBatchAlertEvents(ctx context.Context, events []*model.AlertEvent) error
	ReadAlertEvent(ctx context.Context, id uuid.UUID) (*model.AlertEvent, error)
	GetConn() driver.Conn

	//config
	ModifyTableTTL(ctx context.Context, mapResult []model.ModifyTableTTLMap) error
	GetTables(tables []model.Table) ([]model.TablesQuery, error)

	// ========== alert events ==========
	// Query the alarm events sampled by group and level, and sampleCount the number of samples for each group and level.
	GetAlertEventCountGroupByInstance(startTime time.Time, endTime time.Time, filter request.AlertFilter, instances *model.RelatedInstances) ([]model.AlertEventCount, error)
	// Query alarm events sampled by labels, sampleCount the number of samples for each label.
	GetAlertEventsSample(sampleCount int, startTime time.Time, endTime time.Time, filter request.AlertFilter, instances *model.RelatedInstances) ([]AlertEventSample, error)
	// Query alarm events by pageParam
	GetAlertEvents(startTime time.Time, endTime time.Time, filter request.AlertFilter, instances *model.RelatedInstances, pageParam *request.PageParam) ([]PagedAlertEvent, int, error)
	// ========== k8s events ============
	// SeverityNumber > 9 (warning)
	GetK8sAlertEventsSample(startTime time.Time, endTime time.Time, instances []*model.ServiceInstance) ([]K8sEvents, error)

	// profiling_event
	// GetOnOffCPU get span execution consumption
	GetOnOffCPU(pid uint32, nodeName string, startTime, endTime int64) (*[]ProfilingEvent, error)

	// ========== network (deepflow) ==========
	GetNetworkSpanSegments(traceId string, spanId string) ([]NetSegments, error)

	// ========== flame graph ===========
	GetFlameGraphData(startTime, endTime int64, nodeName string, pid, tid int64, sampleType, spanId, traceId string) (*[]FlameGraphData, error)

	integration.Input
	// contains filtered or unexported methods
}

func New

func New(logger *zap.Logger, address []string, database string, username string, password string) (Repo, error)

type ServiceNode

type ServiceNode struct {
	Service  string `ch:"service" json:"service"`
	Endpoint string `ch:"url" json:"endpoint"`
	IsTraced bool   `ch:"traced" json:"isTraced"`
}

type Source

type Source struct {
	LogSource string `ch:"LogSource"`
}

type SpanTraceOptions

type SpanTraceOptions struct {
	request.SpanTraceFilter

	Options any `json:"options"`
}

type ValueInGroups

type ValueInGroups struct {
	Keys        []string
	ValueGroups []clickhouse.GroupSet
}

ValueInGroups is used to pass in multiple sets of InGroups parameters in the OrInGroups and make OR connections. Each ValueInGroups generates the following SQL, where x is each value in the EqualIfNotEmpty (keys) IN (ValueGroups)

type WrappedConn

type WrappedConn struct {
	driver.Conn
	// contains filtered or unexported fields
}

func (*WrappedConn) Exec

func (c *WrappedConn) Exec(ctx context.Context, query string, args ...any) error

func (*WrappedConn) Ping

func (c *WrappedConn) Ping(ctx context.Context) error

func (*WrappedConn) Query

func (c *WrappedConn) Query(ctx context.Context, query string, args ...any) (driver.Rows, error)

func (*WrappedConn) QueryRow

func (c *WrappedConn) QueryRow(ctx context.Context, query string, args ...any) driver.Row

func (*WrappedConn) Select

func (c *WrappedConn) Select(ctx context.Context, dest any, query string, args ...any) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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