From c13c1ae3e058ff1765ef5988b163ae082096574f Mon Sep 17 00:00:00 2001 From: Aleksey Myasnikov Date: Mon, 8 Apr 2024 11:28:27 +0300 Subject: [PATCH] mark as internals some traces --- VERSIONING.md | 2 +- trace/discovery.go | 1 + trace/sql.go | 21 ++++++++++++ trace/table.go | 49 +++++++++++++++++++++++++++- trace/trace_test.go | 76 +++++++++++++++++++++++++++++++++++++++++++ trace/traceutil.go | 78 --------------------------------------------- 6 files changed, 147 insertions(+), 80 deletions(-) delete mode 100644 trace/traceutil.go diff --git a/VERSIONING.md b/VERSIONING.md index 4c461e40a..40cb9171c 100644 --- a/VERSIONING.md +++ b/VERSIONING.md @@ -1,6 +1,6 @@ # YDB-Go-SDK Versioning Policy -By adhering to these guidelines and exceptions, we aim to provide a stable and reliable development experience for our users while still allowing for innovation and improvement. +By adhering to these guidelines and exceptions, we aim to provide a stable and reliable development experience for our users (aka [LTS](https://en.wikipedia.org/wiki/Long-term_support)) while still allowing for innovation and improvement. We endeavor to adhere to versioning guidelines as defined by [SemVer2.0.0](https://semver.org/). diff --git a/trace/discovery.go b/trace/discovery.go index 6f17f0bbf..e2888cb46 100644 --- a/trace/discovery.go +++ b/trace/discovery.go @@ -42,6 +42,7 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DiscoveryWhoAmIDoneInfo struct { User string Groups []string diff --git a/trace/sql.go b/trace/sql.go index 1aa96254c..9ee597a39 100644 --- a/trace/sql.go +++ b/trace/sql.go @@ -153,6 +153,7 @@ type ( DatabaseSQLConnQueryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnExecStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -165,9 +166,11 @@ type ( Idempotent bool IdleTime time.Duration } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnExecDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnIsTableExistsStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -177,10 +180,12 @@ type ( Call call TableName string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLConnIsTableExistsDoneInfo struct { Exists bool Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -192,9 +197,11 @@ type ( Tx tableTransactionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxQueryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxExecStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -206,9 +213,11 @@ type ( Tx tableTransactionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxExecDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxCommitStartInfo struct { // TxContext make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -218,9 +227,11 @@ type ( Call call Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxCommitDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxRollbackStartInfo struct { // TxContext make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -230,16 +241,20 @@ type ( Call call Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLTxRollbackDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtCloseStartInfo struct { StmtContext *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -250,9 +265,11 @@ type ( StmtContext context.Context Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtQueryDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtExecStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -263,9 +280,11 @@ type ( StmtContext context.Context Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLStmtExecDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLDoTxStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -276,9 +295,11 @@ type ( ID string Idempotent bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLDoTxIntermediateInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals DatabaseSQLDoTxDoneInfo struct { Attempts int Error error diff --git a/trace/table.go b/trace/table.go index 3ba766e29..6938dbd45 100644 --- a/trace/table.go +++ b/trace/table.go @@ -124,9 +124,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableKeepAliveDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableBulkUpsertStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -136,9 +138,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableBulkUpsertDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionDeleteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -148,9 +152,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionDeleteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePrepareDataQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -161,10 +167,12 @@ type ( Session tableSessionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePrepareDataQueryDoneInfo struct { Result tableDataQuery Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExecuteDataQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -177,6 +185,7 @@ type ( Parameters tableQueryParameters KeepInCache bool } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -189,6 +198,7 @@ type ( Query tableDataQuery Parameters tableQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteStatementStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -201,6 +211,7 @@ type ( StatementQuery tableDataQuery Parameters tableQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExplainQueryStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -211,25 +222,30 @@ type ( Session tableSessionInfo Query string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExplainQueryDoneInfo struct { AST string Plan string Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableExecuteDataQueryDoneInfo struct { Tx tableTransactionInfo Prepared bool Result tableResult Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteDoneInfo struct { Result tableResult Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTransactionExecuteStatementDoneInfo struct { Result tableResult Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamReadStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -239,9 +255,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamReadDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamExecuteStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -253,9 +271,11 @@ type ( Query tableDataQuery Parameters tableQueryParameters } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableSessionQueryStreamExecuteDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxBeginStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -265,10 +285,12 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxBeginDoneInfo struct { Tx tableTransactionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxCommitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -279,9 +301,11 @@ type ( Session tableSessionInfo Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxCommitDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxRollbackStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -292,9 +316,11 @@ type ( Session tableSessionInfo Tx tableTransactionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableTxRollbackDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableInitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -303,13 +329,16 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableInitDoneInfo struct { Limit int } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolStateChangeInfo struct { Size int Event string } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionNewStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -318,10 +347,12 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionNewDoneInfo struct { Session tableSessionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolGetStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -330,11 +361,13 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolGetDoneInfo struct { Session tableSessionInfo Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolWaitStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -346,10 +379,12 @@ type ( // TablePoolWaitDoneInfo means a wait iteration inside Get call is done // Warning: Session and Error may be nil at the same time. This means // that a wait iteration donned without any significant tableResultErr + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolWaitDoneInfo struct { Session tableSessionInfo Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolPutStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -359,9 +394,11 @@ type ( Call call Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolPutDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -373,12 +410,15 @@ type ( } // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionCloseDoneInfo struct{} - TablePoolSessionAddInfo struct { + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + TablePoolSessionAddInfo struct { Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TablePoolSessionRemoveInfo struct { Session tableSessionInfo } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCloseStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -387,9 +427,11 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCloseDoneInfo struct { Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -402,10 +444,12 @@ type ( Idempotent bool NestedCall bool // flag when Retry called inside head Retry } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoDoneInfo struct { Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoTxStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -418,10 +462,12 @@ type ( Idempotent bool NestedCall bool // flag when Retry called inside head Retry } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableDoTxDoneInfo struct { Attempts int Error error } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCreateSessionStartInfo struct { // Context make available context in trace callback function. // Pointer to context provide replacement of context in trace callback function. @@ -430,6 +476,7 @@ type ( Context *context.Context Call call } + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals TableCreateSessionDoneInfo struct { Session tableSessionInfo Attempts int diff --git a/trace/trace_test.go b/trace/trace_test.go index fbdf19668..b10945067 100644 --- a/trace/trace_test.go +++ b/trace/trace_test.go @@ -6,6 +6,82 @@ import ( "testing" ) +// Stub is a helper function that stubs all functional fields of x with given f. +func Stub(x interface{}, f func(name string, args ...interface{})) { + (FieldStubber{ + OnCall: f, + }).Stub(reflect.ValueOf(x)) +} + +func ClearContext(x interface{}) interface{} { + p := reflect.ValueOf(x).Index(0) + t := p.Elem().Type() + f, has := t.FieldByName("Context") + if has && f.Type.Kind() == reflect.Interface { + x := reflect.New(t) + x.Elem().Set(p.Elem()) + c := x.Elem().FieldByName(f.Name) + c.Set(reflect.Zero(c.Type())) + p.Set(x) + } + + return p.Interface() +} + +// FieldStubber contains options of filling all struct functional fields. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals +type FieldStubber struct { + // OnStub is an optional callback that is called when field getting + // stubbed. + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnStub func(name string) + + // OnCall is an optional callback that will be called for each stubbed + // field getting called. + // Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals + OnCall func(name string, args ...interface{}) +} + +// Stub fills in given x struct. +// Internals: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#internals +func (f FieldStubber) Stub(x reflect.Value) { + var ( + v = x.Elem() + t = v.Type() + ) + for i := 0; i < t.NumField(); i++ { + var ( + fx = v.Field(i) + ft = fx.Type() + ) + if ft.Kind() != reflect.Func { + continue + } + name := t.Field(i).Name + if f.OnStub != nil { + f.OnStub(name) + } + out := []reflect.Value{} + for i := 0; i < ft.NumOut(); i++ { + ti := reflect.New(ft.Out(i)).Elem() + out = append(out, ti) + } + fn := reflect.MakeFunc(ft, func(args []reflect.Value) []reflect.Value { + if f.OnCall == nil { + return out + } + params := make([]interface{}, len(args)) + for i, arg := range args { + params[i] = arg.Interface() + } + f.OnCall(name, params...) + + return out + }) + fx.Set(fn) + } +} + func TestTable(t *testing.T) { testSingleTrace(t, &Table{}, "Table") } diff --git a/trace/traceutil.go b/trace/traceutil.go deleted file mode 100644 index 8ad52bfb6..000000000 --- a/trace/traceutil.go +++ /dev/null @@ -1,78 +0,0 @@ -package trace - -import ( - "reflect" -) - -// Stub is a helper function that stubs all functional fields of x with given -// f. -func Stub(x interface{}, f func(name string, args ...interface{})) { - (FieldStubber{ - OnCall: f, - }).Stub(reflect.ValueOf(x)) -} - -func ClearContext(x interface{}) interface{} { - p := reflect.ValueOf(x).Index(0) - t := p.Elem().Type() - f, has := t.FieldByName("Context") - if has && f.Type.Kind() == reflect.Interface { - x := reflect.New(t) - x.Elem().Set(p.Elem()) - c := x.Elem().FieldByName(f.Name) - c.Set(reflect.Zero(c.Type())) - p.Set(x) - } - - return p.Interface() -} - -// FieldStubber contains options of filling all struct functional fields. -type FieldStubber struct { - // OnStub is an optional callback that is called when field getting - // stubbed. - OnStub func(name string) - - // OnCall is an optional callback that will be called for each stubbed - // field getting called. - OnCall func(name string, args ...interface{}) -} - -// Stub fills in given x struct. -func (f FieldStubber) Stub(x reflect.Value) { - var ( - v = x.Elem() - t = v.Type() - ) - for i := 0; i < t.NumField(); i++ { - var ( - fx = v.Field(i) - ft = fx.Type() - ) - if ft.Kind() != reflect.Func { - continue - } - name := t.Field(i).Name - if f.OnStub != nil { - f.OnStub(name) - } - out := []reflect.Value{} - for i := 0; i < ft.NumOut(); i++ { - ti := reflect.New(ft.Out(i)).Elem() - out = append(out, ti) - } - fn := reflect.MakeFunc(ft, func(args []reflect.Value) []reflect.Value { - if f.OnCall == nil { - return out - } - params := make([]interface{}, len(args)) - for i, arg := range args { - params[i] = arg.Interface() - } - f.OnCall(name, params...) - - return out - }) - fx.Set(fn) - } -}