коммит произвёл
GitHub
родитель
565c8aa42d
Коммит
f1acdce42c
@@ -19,8 +19,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
OpenTracingParamsMarker = "@openTracingParams"
|
||||
ErrorType = "error"
|
||||
ErrorType = "error"
|
||||
)
|
||||
|
||||
func isError(typeName string) bool {
|
||||
@@ -31,9 +30,6 @@ func main() {
|
||||
if err := buildTimerLayer(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := buildOpenTracingLayer(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if err := buildRetryLayer(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -65,28 +61,14 @@ func buildTimerLayer() error {
|
||||
return os.WriteFile(path.Join("timerlayer", "timerlayer.go"), formatedCode, 0644)
|
||||
}
|
||||
|
||||
func buildOpenTracingLayer() error {
|
||||
code, err := generateLayer("OpenTracingLayer", "opentracing_layer.go.tmpl")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
formatedCode, err := format.Source(code)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return os.WriteFile(path.Join("opentracinglayer", "opentracinglayer.go"), formatedCode, 0644)
|
||||
}
|
||||
|
||||
type methodParam struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
type methodData struct {
|
||||
Params []methodParam
|
||||
Results []string
|
||||
ParamsToTrace map[string]bool
|
||||
Params []methodParam
|
||||
Results []string
|
||||
}
|
||||
|
||||
type subStore struct {
|
||||
@@ -102,20 +84,9 @@ type storeMetadata struct {
|
||||
func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
params := []methodParam{}
|
||||
results := []string{}
|
||||
paramsToTrace := map[string]bool{}
|
||||
ast.Inspect(method.Type, func(expr ast.Node) bool {
|
||||
switch e := expr.(type) {
|
||||
case *ast.FuncType:
|
||||
if method.Doc != nil {
|
||||
for _, comment := range method.Doc.List {
|
||||
s := comment.Text
|
||||
if idx := strings.Index(s, OpenTracingParamsMarker); idx != -1 {
|
||||
for _, p := range strings.Split(s[idx+len(OpenTracingParamsMarker):], ",") {
|
||||
paramsToTrace[strings.TrimSpace(p)] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if e.Params != nil {
|
||||
for _, param := range e.Params.List {
|
||||
for _, paramName := range param.Names {
|
||||
@@ -128,23 +99,10 @@ func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
results = append(results, string(src[result.Type.Pos()-1:result.Type.End()-1]))
|
||||
}
|
||||
}
|
||||
|
||||
for paramName := range paramsToTrace {
|
||||
found := false
|
||||
for _, param := range params {
|
||||
if param.Name == paramName {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
log.Fatalf("Unable to find a parameter called '%s' (method '%s') that is mentioned in the '%s' comment. Maybe it was renamed?", paramName, method.Names[0].Name, OpenTracingParamsMarker)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
return methodData{Params: params, Results: results, ParamsToTrace: paramsToTrace}
|
||||
return methodData{Params: params, Results: results}
|
||||
}
|
||||
|
||||
func extractStoreMetadata() (*storeMetadata, error) {
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// Code generated by "make store-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package opentracinglayer
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/mattermost/mattermost/server/public/model"
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/tracing"
|
||||
"github.com/mattermost/mattermost/server/v8/channels/store"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
spanlog "github.com/opentracing/opentracing-go/log"
|
||||
)
|
||||
|
||||
type {{.Name}} struct {
|
||||
store.Store
|
||||
{{range $index, $element := .SubStores}} {{$index}}Store store.{{$index}}Store
|
||||
{{end}}
|
||||
}
|
||||
|
||||
{{range $index, $element := .SubStores}}func (s *{{$.Name}}) {{$index}}() store.{{$index}}Store {
|
||||
return s.{{$index}}Store
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
{{range $index, $element := .SubStores}}type {{$.Name}}{{$index}}Store struct {
|
||||
store.{{$index}}Store
|
||||
Root *{{$.Name}}
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
{{range $substoreName, $substore := .SubStores}}
|
||||
{{range $index, $element := $substore.Methods}}
|
||||
func (s *{{$.Name}}{{$substoreName}}Store) {{$index}}({{$element.Params | joinParamsWithType}}) {{$element.Results | joinResultsForSignature}} {
|
||||
origCtx := s.Root.Store.Context()
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(s.Root.Store.Context(), "{{$substoreName}}Store.{{$index}}")
|
||||
s.Root.Store.SetContext(newCtx)
|
||||
defer func(){
|
||||
s.Root.Store.SetContext(origCtx)
|
||||
}()
|
||||
{{range $paramName, $param := $element.Params}}
|
||||
{{if index $element.ParamsToTrace $param.Name }}
|
||||
span.SetTag("{{$param.Name}}", {{$param.Name}})
|
||||
{{end}}
|
||||
{{end}}
|
||||
defer span.Finish()
|
||||
{{- if $element.Results | len | eq 0}}
|
||||
s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{else}}
|
||||
{{genResultsVars $element.Results false }} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{- if $element.Results | errorPresent }}
|
||||
if {{$element.Results | errorVar}} != nil {
|
||||
span.LogFields(spanlog.Error({{$element.Results | errorVar}}))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
{{end}}
|
||||
return {{ genResultsVars $element.Results false -}}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{range $index, $element := .Methods}}
|
||||
func (s *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$element.Results | joinResultsForSignature}} {
|
||||
{{if $element.Results | len | eq 0}}s.Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{else}}return s.Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{end}}}
|
||||
{{end}}
|
||||
|
||||
func New(childStore store.Store, ctx context.Context) *{{.Name}} {
|
||||
newStore := {{.Name}}{
|
||||
Store: childStore,
|
||||
}
|
||||
{{range $substoreName, $substore := .SubStores}}
|
||||
newStore.{{$substoreName}}Store = &{{$.Name}}{{$substoreName}}Store{{"{"}}{{$substoreName}}Store: childStore.{{$substoreName}}(), Root: &newStore}{{end}}
|
||||
return &newStore
|
||||
}
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -373,7 +373,6 @@ type PostStore interface {
|
||||
PermanentDeleteByChannel(rctx request.CTX, channelID string) error
|
||||
GetPosts(options model.GetPostsOptions, allowFromCache bool, sanitizeOptions map[string]bool) (*model.PostList, error)
|
||||
GetFlaggedPosts(userID string, offset int, limit int) (*model.PostList, error)
|
||||
// @openTracingParams userID, teamID, offset, limit
|
||||
GetFlaggedPostsForTeam(userID, teamID string, offset int, limit int) (*model.PostList, error)
|
||||
GetFlaggedPostsForChannel(userID, channelID string, offset int, limit int) (*model.PostList, error)
|
||||
GetPostsBefore(options model.GetPostsOptions, sanitizeOptions map[string]bool) (*model.PostList, error)
|
||||
|
||||
Ссылка в новой задаче
Block a user