motrace

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InternalExecutor = "InternalExecutor"
	FileService      = "FileService"
)
View Source
const (
	MOStatementType = "statement"
	MOSpanType      = "span"
	MOLogType       = "log"
	MOErrorType     = "error"
	MORawLogType    = "rawlog"
)
View Source
const (
	SystemDBConst = "system"
	StatsDatabase = SystemDBConst
)

Variables

View Source
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,
	}
)
View Source
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)
		}
	}
}
View Source
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 DebugMode

func DebugMode(debug bool) tracerProviderOption

func DefaultContext

func DefaultContext() context.Context

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

func GetSchemaForAccount(ctx context.Context, account string) []string

GetSchemaForAccount return account's table, and view's schema

func Init

func Init(ctx context.Context, opts ...TracerProviderOption) error

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 NewBatchSpanProcessor

func NewBatchSpanProcessor(exporter BatchProcessor) trace.SpanProcessor

func NewBufferPipe2CSVWorker

func NewBufferPipe2CSVWorker(opt ...BufferOption) bp.PipeImpl[bp.HasName, any]

func ReportError

func ReportError(ctx context.Context, err error, depth int)

ReportError send to BatchProcessor

func ReportZap

func ReportZap(jsonEncoder zapcore.Encoder, entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)

func SetDefaultContext

func SetDefaultContext(ctx context.Context)

func SetDefaultSerializeExecPlan

func SetDefaultSerializeExecPlan(f SerializeExecPlanFunc)

func SetDefaultSpanContext

func SetDefaultSpanContext(sc *trace.SpanContext)

func SetTracerProvider

func SetTracerProvider(p *MOTracerProvider)

func Shutdown

func Shutdown(ctx context.Context) error

func Time2DatetimeString

func Time2DatetimeString(t time.Time) string

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 WithNode

func WithNode(uuid string, t string) tracerProviderOption

WithNode give id as NodeId, t as NodeType

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 IBuffer2SqlItem interface {
	bp.HasName
	Size() int64
	Free()
}

type MOErrorHolder

type MOErrorHolder struct {
	Error     error     `json:"error"`
	Timestamp time.Time `json:"timestamp"`
}

MOErrorHolder implement export.IBuffer2SqlItem and export.CsvFields

func (*MOErrorHolder) FillRow

func (h *MOErrorHolder) FillRow(ctx context.Context, row *table.Row)

func (*MOErrorHolder) Format

func (h *MOErrorHolder) Format(s fmt.State, verb rune)

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) FillRow

func (s *MOSpan) FillRow(ctx context.Context, row *table.Row)

func (*MOSpan) Free

func (s *MOSpan) Free()

func (*MOSpan) GetName

func (s *MOSpan) GetName() string

func (*MOSpan) GetTable

func (s *MOSpan) GetTable() *table.Table

func (*MOSpan) ParentSpanContext

func (s *MOSpan) ParentSpanContext() trace.SpanContext

func (*MOSpan) Size

func (s *MOSpan) Size() int64

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.

func (*MOTracer) Debug

func (t *MOTracer) Debug(ctx context.Context, name string, opts ...trace.SpanOption) (context.Context, trace.Span)

func (*MOTracer) IsEnable

func (t *MOTracer) IsEnable() bool

func (*MOTracer) Start

func (t *MOTracer) Start(ctx context.Context, name string, opts ...trace.SpanOption) (context.Context, trace.Span)

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) IsEnable

func (cfg *MOTracerProvider) IsEnable() bool

func (*MOTracerProvider) SetEnable

func (cfg *MOTracerProvider) SetEnable(enable bool)

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

func (*MOZapLog) FillRow

func (m *MOZapLog) FillRow(ctx context.Context, row *table.Row)

func (*MOZapLog) Free

func (m *MOZapLog) Free()

func (*MOZapLog) GetName

func (m *MOZapLog) GetName() string

func (*MOZapLog) GetTable

func (m *MOZapLog) GetTable() *table.Table

func (*MOZapLog) Size

func (m *MOZapLog) Size() int64

Size 计算近似值

type NoopBatchProcessor

type NoopBatchProcessor struct {
}

func (NoopBatchProcessor) Collect

func (NoopBatchProcessor) Register

func (NoopBatchProcessor) Start

func (n NoopBatchProcessor) Start() bool

func (NoopBatchProcessor) Stop

func (n NoopBatchProcessor) Stop(bool) error

type SerializeExecPlanFunc

type SerializeExecPlanFunc func(ctx context.Context, plan any, uuid2 uuid.UUID) (jsonByte []byte, statsJson []byte, stats Statistic)

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 Statistic

type Statistic struct {
	RowsRead  int64
	BytesScan int64
}

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
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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