MM-26834 - Move opentracing into a separate package (#15011)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ef63afac21
Коммит
b15c0484c6
2
Makefile
2
Makefile
@@ -208,7 +208,7 @@ endif
|
||||
app-layers: ## Extract interface from App struct
|
||||
$(GO) get -modfile=go.tools.mod github.com/reflog/struct2interface
|
||||
$(GOBIN)/struct2interface -f "app" -o "app/app_iface.go" -p "app" -s "App" -i "AppIface" -t ./app/layer_generators/app_iface.go.tmpl
|
||||
$(GO) run ./app/layer_generators -in ./app/app_iface.go -out ./app/opentracing_layer.go -template ./app/layer_generators/opentracing_layer.go.tmpl
|
||||
$(GO) run ./app/layer_generators -in ./app/app_iface.go -out ./app/opentracing/opentracing_layer.go -template ./app/layer_generators/opentracing_layer.go.tmpl
|
||||
|
||||
i18n-extract: ## Extract strings for translation from the source code
|
||||
$(GO) get -modfile=go.tools.mod github.com/mattermost/mattermost-utilities/mmgotool
|
||||
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
@@ -25,6 +26,8 @@ var (
|
||||
outputFile string
|
||||
inputFile string
|
||||
outputFileTemplate string
|
||||
basicTypes = map[string]bool{"int": true, "string": true, "float": true, "bool": true, "byte": true, "int64": true, "error": true}
|
||||
textRegexp = regexp.MustCompile(`\w+$`)
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -77,6 +80,22 @@ type storeMetadata struct {
|
||||
Methods map[string]methodData
|
||||
}
|
||||
|
||||
func fixTypeName(t string) string {
|
||||
// don't want to dive into AST to parse this, add exception
|
||||
if t == "...func(*UploadFileTask)" {
|
||||
t = "...func(*app.UploadFileTask)"
|
||||
}
|
||||
if strings.Contains(t, ".") || strings.Contains(t, "{}") {
|
||||
return t
|
||||
}
|
||||
typeOnly := textRegexp.FindString(t)
|
||||
|
||||
if _, basicType := basicTypes[typeOnly]; !basicType {
|
||||
t = t[:len(t)-len(typeOnly)] + "app." + typeOnly
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func formatNode(src []byte, node ast.Expr) string {
|
||||
return string(src[node.Pos()-1 : node.End()-1])
|
||||
}
|
||||
@@ -100,7 +119,7 @@ func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
if e.Params != nil {
|
||||
for _, param := range e.Params.List {
|
||||
for _, paramName := range param.Names {
|
||||
paramType := (formatNode(src, param.Type))
|
||||
paramType := fixTypeName(formatNode(src, param.Type))
|
||||
params = append(params, methodParam{Name: paramName.Name, Type: paramType})
|
||||
}
|
||||
}
|
||||
@@ -108,7 +127,8 @@ func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
|
||||
if e.Results != nil {
|
||||
for _, r := range e.Results.List {
|
||||
typeStr := formatNode(src, r.Type)
|
||||
typeStr := fixTypeName(formatNode(src, r.Type))
|
||||
|
||||
if len(r.Names) > 0 {
|
||||
for _, k := range r.Names {
|
||||
results = append(results, fmt.Sprintf("%s %s", k.Name, typeStr))
|
||||
|
||||
@@ -4,22 +4,23 @@
|
||||
// Code generated by "make app-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package app
|
||||
package opentracing
|
||||
|
||||
import (
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
spanlog "github.com/opentracing/opentracing-go/log"
|
||||
goi18n "github.com/mattermost/go-i18n/i18n"
|
||||
)
|
||||
|
||||
type {{.Name}} struct {
|
||||
app AppIface
|
||||
app app.AppIface
|
||||
|
||||
srv *Server
|
||||
srv *app.Server
|
||||
|
||||
log *mlog.Logger
|
||||
notificationsLog *mlog.Logger
|
||||
|
||||
t goi18n.TranslateFunc
|
||||
t i18n.TranslateFunc
|
||||
session model.Session
|
||||
requestId string
|
||||
ipAddress string
|
||||
@@ -53,9 +54,9 @@ func (a *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$ele
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store.SetContext(newCtx)
|
||||
defer func() {
|
||||
defer func() {
|
||||
a.app.Srv().Store.SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
{{range $paramIdx, $param := $element.Params}}
|
||||
{{ shouldTrace $element.ParamsToTrace $param.Name }}
|
||||
@@ -70,12 +71,12 @@ func (a *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$ele
|
||||
span.LogFields(spanlog.Error({{$element.Results | errorVar}}))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
{{end}}
|
||||
{{end}}
|
||||
return {{$element.Results | genResultsVars -}}
|
||||
{{end}}}
|
||||
{{end}}
|
||||
|
||||
func NewOpenTracingAppLayer(childApp AppIface, ctx context.Context) *{{.Name}} {
|
||||
func NewOpenTracingAppLayer(childApp app.AppIface, ctx context.Context) *{{.Name}} {
|
||||
newApp := {{.Name}}{
|
||||
app: childApp,
|
||||
ctx: ctx,
|
||||
@@ -112,7 +113,7 @@ func NewOpenTracingAppLayer(childApp AppIface, ctx context.Context) *{{.Name}} {
|
||||
}
|
||||
|
||||
|
||||
func (a *{{.Name}}) Srv() *Server {
|
||||
func (a *{{.Name}}) Srv() *app.Server {
|
||||
return a.srv
|
||||
}
|
||||
func (a *{{.Name}}) Log() *mlog.Logger {
|
||||
@@ -184,7 +185,7 @@ func (a *{{.Name}}) Context() context.Context {
|
||||
func (a *{{.Name}}) SetSession(sess *model.Session) {
|
||||
a.session = *sess
|
||||
}
|
||||
func (a *{{.Name}}) SetT(t goi18n.TranslateFunc){
|
||||
func (a *{{.Name}}) SetT(t i18n.TranslateFunc){
|
||||
a.t = t
|
||||
}
|
||||
func (a *{{.Name}}) SetRequestId(str string){
|
||||
@@ -205,9 +206,9 @@ func (a *{{.Name}}) SetPath(str string){
|
||||
func (a *{{.Name}}) SetContext(c context.Context){
|
||||
a.context = c
|
||||
}
|
||||
func (a *{{.Name}}) SetServer(srv *Server) {
|
||||
func (a *{{.Name}}) SetServer(srv *app.Server) {
|
||||
a.srv = srv
|
||||
}
|
||||
func (a *{{.Name}}) GetT() goi18n.TranslateFunc {
|
||||
func (a *{{.Name}}) GetT() i18n.TranslateFunc {
|
||||
return a.t
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// Code generated by "make app-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package app
|
||||
package opentracing
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/mattermost/go-i18n/i18n"
|
||||
goi18n "github.com/mattermost/go-i18n/i18n"
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
"github.com/mattermost/mattermost-server/v5/audit"
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
@@ -38,14 +39,14 @@ import (
|
||||
)
|
||||
|
||||
type OpenTracingAppLayer struct {
|
||||
app AppIface
|
||||
app app.AppIface
|
||||
|
||||
srv *Server
|
||||
srv *app.Server
|
||||
|
||||
log *mlog.Logger
|
||||
notificationsLog *mlog.Logger
|
||||
|
||||
t goi18n.TranslateFunc
|
||||
t i18n.TranslateFunc
|
||||
session model.Session
|
||||
requestId string
|
||||
ipAddress string
|
||||
@@ -746,7 +747,7 @@ func (a *OpenTracingAppLayer) BroadcastStatus(status *model.Status) {
|
||||
a.app.BroadcastStatus(status)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) BuildPostReactions(postId string) (*[]ReactionImportData, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) BuildPostReactions(postId string) (*[]app.ReactionImportData, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.BuildPostReactions")
|
||||
|
||||
@@ -5575,7 +5576,7 @@ func (a *OpenTracingAppLayer) GetGroupsByUserId(userId string) ([]*model.Group,
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) GetHubForUserId(userId string) *Hub {
|
||||
func (a *OpenTracingAppLayer) GetHubForUserId(userId string) *app.Hub {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.GetHubForUserId")
|
||||
|
||||
@@ -9113,7 +9114,7 @@ func (a *OpenTracingAppLayer) HasPermissionToUser(askingUserId string, userId st
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) HubRegister(webConn *WebConn) {
|
||||
func (a *OpenTracingAppLayer) HubRegister(webConn *app.WebConn) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.HubRegister")
|
||||
|
||||
@@ -9158,7 +9159,7 @@ func (a *OpenTracingAppLayer) HubStop() {
|
||||
a.app.HubStop()
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) HubUnregister(webConn *WebConn) {
|
||||
func (a *OpenTracingAppLayer) HubUnregister(webConn *app.WebConn) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.HubUnregister")
|
||||
|
||||
@@ -10142,7 +10143,7 @@ func (a *OpenTracingAppLayer) MoveFile(oldPath string, newPath string) *model.Ap
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) NewClusterDiscoveryService() *ClusterDiscoveryService {
|
||||
func (a *OpenTracingAppLayer) NewClusterDiscoveryService() *app.ClusterDiscoveryService {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.NewClusterDiscoveryService")
|
||||
|
||||
@@ -10176,7 +10177,7 @@ func (a *OpenTracingAppLayer) NewPluginAPI(manifest *model.Manifest) plugin.API
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *WebConn {
|
||||
func (a *OpenTracingAppLayer) NewWebConn(ws *websocket.Conn, session model.Session, t goi18n.TranslateFunc, locale string) *app.WebConn {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.NewWebConn")
|
||||
|
||||
@@ -10193,7 +10194,7 @@ func (a *OpenTracingAppLayer) NewWebConn(ws *websocket.Conn, session model.Sessi
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) NewWebHub() *Hub {
|
||||
func (a *OpenTracingAppLayer) NewWebHub() *app.Hub {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.NewWebHub")
|
||||
|
||||
@@ -13295,7 +13296,7 @@ func (a *OpenTracingAppLayer) SlackAddBotUser(teamId string, log *bytes.Buffer)
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel {
|
||||
func (a *OpenTracingAppLayer) SlackAddChannels(teamId string, slackchannels []app.SlackChannel, posts map[string][]app.SlackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User, importerLog *bytes.Buffer) map[string]*model.Channel {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SlackAddChannels")
|
||||
|
||||
@@ -13312,7 +13313,7 @@ func (a *OpenTracingAppLayer) SlackAddChannels(teamId string, slackchannels []Sl
|
||||
return resultVar0
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SlackAddPosts(teamId string, channel *model.Channel, posts []SlackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User) {
|
||||
func (a *OpenTracingAppLayer) SlackAddPosts(teamId string, channel *model.Channel, posts []app.SlackPost, users map[string]*model.User, uploads map[string]*zip.File, botUser *model.User) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SlackAddPosts")
|
||||
|
||||
@@ -13327,7 +13328,7 @@ func (a *OpenTracingAppLayer) SlackAddPosts(teamId string, channel *model.Channe
|
||||
a.app.SlackAddPosts(teamId, channel, posts, users, uploads, botUser)
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SlackAddUsers(teamId string, slackusers []SlackUser, importerLog *bytes.Buffer) map[string]*model.User {
|
||||
func (a *OpenTracingAppLayer) SlackAddUsers(teamId string, slackusers []app.SlackUser, importerLog *bytes.Buffer) map[string]*model.User {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SlackAddUsers")
|
||||
|
||||
@@ -13366,7 +13367,7 @@ func (a *OpenTracingAppLayer) SlackImport(fileData multipart.File, fileSize int6
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) SlackUploadFile(slackPostFile *SlackFile, uploads map[string]*zip.File, teamId string, channelId string, userId string, slackTimestamp string) (*model.FileInfo, bool) {
|
||||
func (a *OpenTracingAppLayer) SlackUploadFile(slackPostFile *app.SlackFile, uploads map[string]*zip.File, teamId string, channelId string, userId string, slackTimestamp string) (*model.FileInfo, bool) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.SlackUploadFile")
|
||||
|
||||
@@ -14831,7 +14832,7 @@ func (a *OpenTracingAppLayer) UploadFile(data []byte, channelId string, filename
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) UploadFileX(channelId string, name string, input io.Reader, opts ...func(*UploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||
func (a *OpenTracingAppLayer) UploadFileX(channelId string, name string, input io.Reader, opts ...func(*app.UploadFileTask)) (*model.FileInfo, *model.AppError) {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.UploadFileX")
|
||||
|
||||
@@ -15110,7 +15111,7 @@ func (a *OpenTracingAppLayer) WriteFile(fr io.Reader, path string) (int64, *mode
|
||||
return resultVar0, resultVar1
|
||||
}
|
||||
|
||||
func NewOpenTracingAppLayer(childApp AppIface, ctx context.Context) *OpenTracingAppLayer {
|
||||
func NewOpenTracingAppLayer(childApp app.AppIface, ctx context.Context) *OpenTracingAppLayer {
|
||||
newApp := OpenTracingAppLayer{
|
||||
app: childApp,
|
||||
ctx: ctx,
|
||||
@@ -15146,7 +15147,7 @@ func NewOpenTracingAppLayer(childApp AppIface, ctx context.Context) *OpenTracing
|
||||
return &newApp
|
||||
}
|
||||
|
||||
func (a *OpenTracingAppLayer) Srv() *Server {
|
||||
func (a *OpenTracingAppLayer) Srv() *app.Server {
|
||||
return a.srv
|
||||
}
|
||||
func (a *OpenTracingAppLayer) Log() *mlog.Logger {
|
||||
@@ -15218,7 +15219,7 @@ func (a *OpenTracingAppLayer) Context() context.Context {
|
||||
func (a *OpenTracingAppLayer) SetSession(sess *model.Session) {
|
||||
a.session = *sess
|
||||
}
|
||||
func (a *OpenTracingAppLayer) SetT(t goi18n.TranslateFunc) {
|
||||
func (a *OpenTracingAppLayer) SetT(t i18n.TranslateFunc) {
|
||||
a.t = t
|
||||
}
|
||||
func (a *OpenTracingAppLayer) SetRequestId(str string) {
|
||||
@@ -15239,9 +15240,9 @@ func (a *OpenTracingAppLayer) SetPath(str string) {
|
||||
func (a *OpenTracingAppLayer) SetContext(c context.Context) {
|
||||
a.context = c
|
||||
}
|
||||
func (a *OpenTracingAppLayer) SetServer(srv *Server) {
|
||||
func (a *OpenTracingAppLayer) SetServer(srv *app.Server) {
|
||||
a.srv = srv
|
||||
}
|
||||
func (a *OpenTracingAppLayer) GetT() goi18n.TranslateFunc {
|
||||
func (a *OpenTracingAppLayer) GetT() i18n.TranslateFunc {
|
||||
return a.t
|
||||
}
|
||||
@@ -15,16 +15,16 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/NYTimes/gziphandler"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
spanlog "github.com/opentracing/opentracing-go/log"
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/app"
|
||||
app_opentracing "github.com/mattermost/mattermost-server/v5/app/opentracing"
|
||||
"github.com/mattermost/mattermost-server/v5/mlog"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/services/tracing"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
"github.com/mattermost/mattermost-server/v5/utils"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
spanlog "github.com/opentracing/opentracing-go/log"
|
||||
)
|
||||
|
||||
func GetHandlerName(h func(*Context, http.ResponseWriter, *http.Request)) string {
|
||||
@@ -140,7 +140,7 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
tmpSrv = *c.App.Srv()
|
||||
tmpSrv.Store = store.NewOpenTracingLayer(c.App.Srv().Store, ctx)
|
||||
c.App.SetServer(&tmpSrv)
|
||||
c.App = app.NewOpenTracingAppLayer(c.App, ctx)
|
||||
c.App = app_opentracing.NewOpenTracingAppLayer(c.App, ctx)
|
||||
}
|
||||
|
||||
// Set the max request body size to be equal to MaxFileSize.
|
||||
|
||||
Ссылка в новой задаче
Block a user