Documentation ¶
Index ¶
- Constants
- Variables
- func ContextWithStatement(parent context.Context, s *StatementInfo) context.Context
- func DebugMode(debug bool) tracerProviderOption
- func DefaultContext() context.Context
- func DefaultSpanContext() *trace.SpanContext
- func DisableLogErrorReport(disable bool)
- func EnableTracer(enable bool) tracerProviderOption
- func GetNodeResource() *trace.MONodeResource
- func GetSchemaForAccount(ctx context.Context, account string) []string
- func Init(ctx context.Context, opts ...TracerProviderOption) error
- func InitSchema(ctx context.Context, sqlExecutor func() ie.InternalExecutor) error
- func InitSchemaByInnerExecutor(ctx context.Context, ieFactory func() ie.InternalExecutor) error
- func InitWithConfig(ctx context.Context, SV *config.ObservabilityParameters, ...) error
- func NewBatchSpanProcessor(exporter BatchProcessor) trace.SpanProcessor
- func NewBufferPipe2CSVWorker(opt ...BufferOption) bp.PipeImpl[bp.HasName, any]
- func ReportError(ctx context.Context, err error, depth int)
- func ReportZap(jsonEncoder zapcore.Encoder, entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
- func SetDefaultContext(ctx context.Context)
- func SetDefaultSerializeExecPlan(f SerializeExecPlanFunc)
- func SetDefaultSpanContext(sc *trace.SpanContext)
- func SetTracerProvider(p *MOTracerProvider)
- func Shutdown(ctx context.Context) error
- func Time2DatetimeString(t time.Time) string
- func WithBatchProcessMode(mode string) tracerProviderOption
- func WithBatchProcessor(p BatchProcessor) tracerProviderOption
- func WithExportInterval(secs int) tracerProviderOption
- func WithFSWriterFactory(f table.WriterFactory) tracerProviderOption
- func WithInitAction(init bool) tracerProviderOption
- func WithLongQueryTime(secs float64) tracerProviderOption
- func WithNode(uuid string, t string) tracerProviderOption
- func WithSQLExecutor(f func() ie.InternalExecutor) tracerProviderOption
- type BatchProcessor
- type BufferOption
- type IBuffer2SqlItem
- type MOErrorHolder
- type MOSpan
- func (s *MOSpan) End(options ...trace.SpanEndOption)
- func (s *MOSpan) FillRow(ctx context.Context, row *table.Row)
- func (s *MOSpan) Free()
- func (s *MOSpan) GetName() string
- func (s *MOSpan) GetTable() *table.Table
- func (s *MOSpan) ParentSpanContext() trace.SpanContext
- func (s *MOSpan) Size() int64
- func (s *MOSpan) SpanContext() trace.SpanContext
- type MOTracer
- type MOTracerProvider
- type MOZapLog
- type NoopBatchProcessor
- type PipeImpl
- type SerializeExecPlanFunc
- type StatementInfo
- func (s *StatementInfo) ExecPlan2Json(ctx context.Context) (string, string)
- func (s *StatementInfo) FillRow(ctx context.Context, row *table.Row)
- func (s *StatementInfo) Free()
- func (s *StatementInfo) GetName() string
- func (s *StatementInfo) GetTable() *table.Table
- func (s *StatementInfo) IsZeroTxnID() bool
- func (s *StatementInfo) Report(ctx context.Context)
- func (s *StatementInfo) SetExecPlan(execPlan any, SerializeFunc SerializeExecPlanFunc)
- func (s *StatementInfo) SetTxnID(id []byte)
- func (s *StatementInfo) Size() int64
- type StatementInfoStatus
- type StatementOption
- type StatementOptionFunc
- type Statistic
- type TracerProviderOption
- type WriteFactoryConfig
Constants ¶
const ( InternalExecutor = "InternalExecutor" FileService = "FileService" )
const ( MOStatementType = "statement" MOSpanType = "span" MOLogType = "log" MOErrorType = "error" MORawLogType = "rawlog" )
const ( SystemDBConst = "system" StatsDatabase = SystemDBConst )
Variables ¶
var ( SingleStatementTable = &table.Table{ Account: table.AccountAll, Database: StatsDatabase, Table: statementInfoTbl, Columns: []table.Column{ stmtIDCol, txnIDCol, sesIDCol, accountCol, userCol, hostCol, dbCol, stmtCol, stmtTagCol, stmtFgCol, nodeUUIDCol, nodeTypeCol, reqAtCol, respAtCol, durationCol, statusCol, errCodeCol, errorCol, execPlanCol, rowsReadCol, bytesScanCol, statsCol, stmtTypeCol, queryTypeCol, roleIdCol, sqlTypeCol, }, PrimaryKeyColumn: []table.Column{stmtIDCol}, Engine: table.ExternalTableEngine, Comment: "record each statement and stats info", PathBuilder: table.NewAccountDatePathBuilder(), AccountColumn: &accountCol, SupportUserAccess: true, } SingleRowLogTable = &table.Table{ Account: table.AccountAll, Database: StatsDatabase, Table: rawLogTbl, Columns: []table.Column{ rawItemCol, nodeUUIDCol, nodeTypeCol, spanIDCol, traceIDCol, loggerNameCol, timestampCol, levelCol, callerCol, messageCol, extraCol, errCodeCol, errorCol, stackCol, spanNameCol, parentSpanIDCol, startTimeCol, endTimeCol, durationCol, resourceCol, spanKindCol, }, PrimaryKeyColumn: nil, Engine: table.ExternalTableEngine, Comment: "read merge data from log, error, span", PathBuilder: table.NewAccountDatePathBuilder(), AccountColumn: nil, SupportUserAccess: false, } )
var EndStatement = func(ctx context.Context, err error) { if !GetTracerProvider().IsEnable() { return } s := StatementFromContext(ctx) if s == nil { panic(moerr.NewInternalError(ctx, "no statement info in context")) } s.mux.Lock() defer s.mux.Unlock() if !s.end { s.end = true s.ResponseAt = time.Now() s.Duration = s.ResponseAt.Sub(s.RequestAt) s.Status = StatementStatusSuccess if err != nil { s.Error = err s.Status = StatementStatusFailed } if !s.reported || s.exported { s.Report(ctx) } } }
var ReportStatement = func(ctx context.Context, s *StatementInfo) error { if !GetTracerProvider().IsEnable() { return nil } return GetGlobalBatchProcessor().Collect(ctx, s) }
Functions ¶
func ContextWithStatement ¶
func ContextWithStatement(parent context.Context, s *StatementInfo) context.Context
func DefaultContext ¶
func DefaultSpanContext ¶
func DefaultSpanContext() *trace.SpanContext
func DisableLogErrorReport ¶
func DisableLogErrorReport(disable bool)
func EnableTracer ¶
func EnableTracer(enable bool) tracerProviderOption
func GetNodeResource ¶
func GetNodeResource() *trace.MONodeResource
func GetSchemaForAccount ¶
GetSchemaForAccount return account's table, and view's schema
func InitSchema ¶
func InitSchema(ctx context.Context, sqlExecutor func() ie.InternalExecutor) error
InitSchema PS: only in standalone or CN node can init schema
func InitSchemaByInnerExecutor ¶
func InitSchemaByInnerExecutor(ctx context.Context, ieFactory func() ie.InternalExecutor) error
InitSchemaByInnerExecutor init schema, which can access db by io.InternalExecutor on any Node.
func InitWithConfig ¶
func InitWithConfig(ctx context.Context, SV *config.ObservabilityParameters, opts ...TracerProviderOption) error
func NewBatchSpanProcessor ¶
func NewBatchSpanProcessor(exporter BatchProcessor) trace.SpanProcessor
func NewBufferPipe2CSVWorker ¶
func ReportError ¶
ReportError send to BatchProcessor
func SetDefaultContext ¶
func SetDefaultSerializeExecPlan ¶
func SetDefaultSerializeExecPlan(f SerializeExecPlanFunc)
func SetDefaultSpanContext ¶
func SetDefaultSpanContext(sc *trace.SpanContext)
func SetTracerProvider ¶
func SetTracerProvider(p *MOTracerProvider)
func Time2DatetimeString ¶
func WithBatchProcessMode ¶
func WithBatchProcessMode(mode string) tracerProviderOption
func WithBatchProcessor ¶
func WithBatchProcessor(p BatchProcessor) tracerProviderOption
func WithExportInterval ¶
func WithExportInterval(secs int) tracerProviderOption
func WithFSWriterFactory ¶
func WithFSWriterFactory(f table.WriterFactory) tracerProviderOption
func WithInitAction ¶
func WithInitAction(init bool) tracerProviderOption
func WithLongQueryTime ¶
func WithLongQueryTime(secs float64) tracerProviderOption
func WithSQLExecutor ¶
func WithSQLExecutor(f func() ie.InternalExecutor) tracerProviderOption
Types ¶
type BatchProcessor ¶
type BatchProcessor interface { Collect(context.Context, batchpipe.HasName) error Start() bool Stop(graceful bool) error Register(name batchpipe.HasName, impl PipeImpl) }
func GetGlobalBatchProcessor ¶
func GetGlobalBatchProcessor() BatchProcessor
type BufferOption ¶
type BufferOption interface {
// contains filtered or unexported methods
}
func BufferWithFilterItemFunc ¶
func BufferWithFilterItemFunc(f filterItemFunc) BufferOption
func BufferWithGenBatchFunc ¶
func BufferWithGenBatchFunc(f genBatchFunc) BufferOption
func BufferWithReminder ¶
func BufferWithReminder(reminder bp.Reminder) BufferOption
func BufferWithSizeThreshold ¶
func BufferWithSizeThreshold(size int64) BufferOption
func BufferWithType ¶
func BufferWithType(name string) BufferOption
type IBuffer2SqlItem ¶
type MOErrorHolder ¶
MOErrorHolder implement export.IBuffer2SqlItem and export.CsvFields
func (*MOErrorHolder) FillRow ¶
func (h *MOErrorHolder) FillRow(ctx context.Context, row *table.Row)
func (*MOErrorHolder) Free ¶
func (h *MOErrorHolder) Free()
func (*MOErrorHolder) GetName ¶
func (h *MOErrorHolder) GetName() string
func (*MOErrorHolder) GetTable ¶
func (h *MOErrorHolder) GetTable() *table.Table
func (*MOErrorHolder) Size ¶
func (h *MOErrorHolder) Size() int64
type MOSpan ¶
type MOSpan struct { trace.SpanConfig Name string `json:"name"` StartTime time.Time `json:"start_time"` EndTime time.Time `jons:"end_time"` Duration uint64 `json:"duration"` // contains filtered or unexported fields }
MOSpan implement export.IBuffer2SqlItem and export.CsvFields
func (*MOSpan) End ¶
func (s *MOSpan) End(options ...trace.SpanEndOption)
func (*MOSpan) ParentSpanContext ¶
func (s *MOSpan) ParentSpanContext() trace.SpanContext
func (*MOSpan) SpanContext ¶
func (s *MOSpan) SpanContext() trace.SpanContext
type MOTracer ¶
type MOTracer struct { trace.TracerConfig // contains filtered or unexported fields }
MOTracer is the creator of Spans.
type MOTracerProvider ¶
type MOTracerProvider struct {
// contains filtered or unexported fields
}
func GetTracerProvider ¶
func GetTracerProvider() *MOTracerProvider
func (*MOTracerProvider) GetSqlExecutor ¶
func (cfg *MOTracerProvider) GetSqlExecutor() func() ie.InternalExecutor
func (*MOTracerProvider) Tracer ¶
func (p *MOTracerProvider) Tracer(instrumentationName string, opts ...trace.TracerOption) trace.Tracer
type MOZapLog ¶
type MOZapLog struct { Level zapcore.Level `json:"Level"` SpanContext *trace.SpanContext `json:"span"` Timestamp time.Time `json:"timestamp"` LoggerName string Caller string `json:"caller"` // like "util/trace/trace.go:666" Message string `json:"message"` Extra string `json:"extra"` // like json text Stack string `json:"stack"` }
MOZapLog implement export.IBuffer2SqlItem and export.CsvFields
type NoopBatchProcessor ¶
type NoopBatchProcessor struct { }
func (NoopBatchProcessor) Register ¶
func (n NoopBatchProcessor) Register(batchpipe.HasName, PipeImpl)
func (NoopBatchProcessor) Start ¶
func (n NoopBatchProcessor) Start() bool
func (NoopBatchProcessor) Stop ¶
func (n NoopBatchProcessor) Stop(bool) error
type SerializeExecPlanFunc ¶
type StatementInfo ¶
type StatementInfo struct { StatementID [16]byte `json:"statement_id"` TransactionID [16]byte `json:"transaction_id"` SessionID [16]byte `jons:"session_id"` Account string `json:"account"` User string `json:"user"` Host string `json:"host"` RoleId uint32 `json:"role_id"` Database string `json:"database"` Statement string `json:"statement"` StatementFingerprint string `json:"statement_fingerprint"` StatementTag string `json:"statement_tag"` SqlSourceType string `json:"sql_source_type"` RequestAt time.Time `json:"request_at"` // see WithRequestAt StatementType string `json:"statement_type"` QueryType string `json:"query_type"` // after Status StatementInfoStatus `json:"status"` Error error `json:"error"` ResponseAt time.Time `json:"response_at"` Duration time.Duration `json:"duration"` // unit: ns ExecPlan any `json:"exec_plan"` // RowsRead, BytesScan generated from ExecPlan RowsRead int64 `json:"rows_read"` // see ExecPlan2Json BytesScan int64 `json:"bytes_scan"` // see ExecPlan2Json // SerializeExecPlan SerializeExecPlan SerializeExecPlanFunc // see SetExecPlan, ExecPlan2Json // contains filtered or unexported fields }
StatementInfo implement export.IBuffer2SqlItem and export.CsvFields
func StatementFromContext ¶
func StatementFromContext(ctx context.Context) *StatementInfo
func (*StatementInfo) ExecPlan2Json ¶
func (s *StatementInfo) ExecPlan2Json(ctx context.Context) (string, string)
ExecPlan2Json return ExecPlan Serialized json-str and set RowsRead, BytesScan from ExecPlan
please used in s.mux.Lock()
func (*StatementInfo) FillRow ¶
func (s *StatementInfo) FillRow(ctx context.Context, row *table.Row)
func (*StatementInfo) Free ¶
func (s *StatementInfo) Free()
func (*StatementInfo) GetName ¶
func (s *StatementInfo) GetName() string
func (*StatementInfo) GetTable ¶
func (s *StatementInfo) GetTable() *table.Table
func (*StatementInfo) IsZeroTxnID ¶
func (s *StatementInfo) IsZeroTxnID() bool
func (*StatementInfo) Report ¶
func (s *StatementInfo) Report(ctx context.Context)
func (*StatementInfo) SetExecPlan ¶
func (s *StatementInfo) SetExecPlan(execPlan any, SerializeFunc SerializeExecPlanFunc)
SetExecPlan record execPlan should be TxnComputationWrapper.plan obj, which support 2json.
func (*StatementInfo) SetTxnID ¶
func (s *StatementInfo) SetTxnID(id []byte)
func (*StatementInfo) Size ¶
func (s *StatementInfo) Size() int64
type StatementInfoStatus ¶
type StatementInfoStatus int
const ( StatementStatusRunning StatementInfoStatus = iota StatementStatusSuccess StatementStatusFailed )
func (StatementInfoStatus) String ¶
func (s StatementInfoStatus) String() string
type StatementOption ¶
type StatementOption interface {
Apply(*StatementInfo)
}
type StatementOptionFunc ¶
type StatementOptionFunc func(*StatementInfo)
type TracerProviderOption ¶
type TracerProviderOption interface {
// contains filtered or unexported methods
}
TracerProviderOption configures a TracerProvider.
type WriteFactoryConfig ¶
type WriteFactoryConfig struct { Account string Ts time.Time PathBuilder table.PathBuilder }