коммит произвёл
GitHub
родитель
565c8aa42d
Коммит
f1acdce42c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -51,7 +51,6 @@ func GetCommandProvider(name string) CommandProvider {
|
||||
return nil
|
||||
}
|
||||
|
||||
// @openTracingParams teamID, skipSlackParsing
|
||||
func (a *App) CreateCommandPost(c request.CTX, post *model.Post, teamID string, response *model.CommandResponse, skipSlackParsing bool) (*model.Post, *model.AppError) {
|
||||
if skipSlackParsing {
|
||||
post.Message = response.Text
|
||||
@@ -81,7 +80,6 @@ func (a *App) CreateCommandPost(c request.CTX, post *model.Post, teamID string,
|
||||
return post, nil
|
||||
}
|
||||
|
||||
// @openTracingParams teamID
|
||||
// previous ListCommands now ListAutocompleteCommands
|
||||
func (a *App) ListAutocompleteCommands(teamID string, T i18n.TranslateFunc) ([]*model.Command, *model.AppError) {
|
||||
commands := make([]*model.Command, 0, 32)
|
||||
@@ -179,7 +177,6 @@ func (a *App) ListAllCommands(teamID string, T i18n.TranslateFunc) ([]*model.Com
|
||||
return commands, nil
|
||||
}
|
||||
|
||||
// @openTracingParams args
|
||||
func (a *App) ExecuteCommand(c request.CTX, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
|
||||
trigger := ""
|
||||
message := ""
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// Code generated by "make app-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package app
|
||||
|
||||
// AppIface is extracted from App struct and contains all it's exported methods. It's provided to allow partial interface passing and app layers creation.
|
||||
type AppIface interface {
|
||||
{{.Content}}
|
||||
}
|
||||
@@ -1,285 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"golang.org/x/tools/imports"
|
||||
)
|
||||
|
||||
var (
|
||||
reserved = []string{"AcceptLanguage", "AccountMigration", "Cluster", "Compliance", "Context", "DataRetention", "Elasticsearch", "HTTPService", "ImageProxy", "IpAddress", "Ldap", "Log", "MessageExport", "Metrics", "Notification", "NotificationsLog", "Path", "RequestId", "Saml", "Session", "SetIpAddress", "SetRequestId", "SetSession", "SetStore", "SetT", "Srv", "Store", "T", "Timezones", "UserAgent", "SetUserAgent", "SetAcceptLanguage", "SetPath", "SetContext", "SetServer", "GetT"}
|
||||
outputFile string
|
||||
inputFile string
|
||||
outputFileTemplate string
|
||||
basicTypes = map[string]bool{"int": true, "uint": true, "string": true, "float": true, "bool": true, "byte": true, "int64": true, "uint64": true, "error": true}
|
||||
textRegexp = regexp.MustCompile(`\w+$`)
|
||||
)
|
||||
|
||||
const (
|
||||
OpenTracingParamsMarker = "@openTracingParams"
|
||||
AppErrorType = "*model.AppError"
|
||||
ErrorType = "error"
|
||||
)
|
||||
|
||||
func isError(typeName string) bool {
|
||||
return strings.Contains(typeName, AppErrorType) || strings.Contains(typeName, ErrorType)
|
||||
}
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&inputFile, "in", path.Join("..", "app_iface.go"), "App interface file")
|
||||
flag.StringVar(&outputFile, "out", path.Join("..", "opentracing_layer.go"), "Output file")
|
||||
flag.StringVar(&outputFileTemplate, "template", "opentracing_layer.go.tmpl", "Output template file")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
code, err := generateLayer("OpenTracingAppLayer", outputFileTemplate)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
formattedCode, err := imports.Process(outputFile, code, &imports.Options{Comments: true})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = os.WriteFile(outputFile, formattedCode, 0644)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type methodParam struct {
|
||||
Name string
|
||||
Type string
|
||||
}
|
||||
|
||||
type methodData struct {
|
||||
ParamsToTrace map[string]bool
|
||||
Params []methodParam
|
||||
Results []string
|
||||
}
|
||||
|
||||
type storeMetadata struct {
|
||||
Name string
|
||||
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, "{}") || t == "map[string]any" {
|
||||
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])
|
||||
}
|
||||
|
||||
func extractMethodMetadata(method *ast.Field, src []byte) methodData {
|
||||
params := []methodParam{}
|
||||
paramsToTrace := map[string]bool{}
|
||||
results := []string{}
|
||||
e := method.Type.(*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 {
|
||||
paramType := fixTypeName(formatNode(src, param.Type))
|
||||
params = append(params, methodParam{Name: paramName.Name, Type: paramType})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if e.Results != nil {
|
||||
for _, r := range e.Results.List {
|
||||
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))
|
||||
}
|
||||
} else {
|
||||
results = append(results, typeStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for paramName := range paramsToTrace {
|
||||
found := false
|
||||
for _, param := range params {
|
||||
if param.Name == paramName || strings.HasPrefix(paramName, param.Name+".") {
|
||||
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 methodData{Params: params, Results: results, ParamsToTrace: paramsToTrace}
|
||||
}
|
||||
|
||||
func extractStoreMetadata() (*storeMetadata, error) {
|
||||
// Create the AST by parsing src.
|
||||
fset := token.NewFileSet() // positions are relative to fset
|
||||
|
||||
file, err := os.Open(inputFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to open %s file: %w", inputFile, err)
|
||||
}
|
||||
src, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer file.Close()
|
||||
f, err := parser.ParseFile(fset, "../app_iface.go", src, parser.AllErrors|parser.ParseComments)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
metadata := storeMetadata{Methods: map[string]methodData{}}
|
||||
|
||||
ast.Inspect(f, func(n ast.Node) bool {
|
||||
switch x := n.(type) {
|
||||
case *ast.TypeSpec:
|
||||
if x.Name.Name == "AppIface" {
|
||||
for _, method := range x.Type.(*ast.InterfaceType).Methods.List {
|
||||
methodName := method.Names[0].Name
|
||||
found := false
|
||||
for _, reservedMethod := range reserved {
|
||||
if methodName == reservedMethod {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
continue
|
||||
}
|
||||
metadata.Methods[methodName] = extractMethodMetadata(method, src)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
return &metadata, err
|
||||
}
|
||||
|
||||
func generateLayer(name, templateFile string) ([]byte, error) {
|
||||
out := bytes.NewBufferString("")
|
||||
metadata, err := extractStoreMetadata()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
metadata.Name = name
|
||||
|
||||
myFuncs := template.FuncMap{
|
||||
"joinResults": func(results []string) string {
|
||||
return strings.Join(results, ", ")
|
||||
},
|
||||
"joinResultsForSignature": func(results []string) string {
|
||||
return fmt.Sprintf("(%s)", strings.Join(results, ", "))
|
||||
},
|
||||
"genResultsVars": func(results []string) string {
|
||||
vars := make([]string, 0, len(results))
|
||||
for i := range results {
|
||||
vars = append(vars, fmt.Sprintf("resultVar%d", i))
|
||||
}
|
||||
return strings.Join(vars, ", ")
|
||||
},
|
||||
"errorToBoolean": func(results []string) string {
|
||||
for i, typeName := range results {
|
||||
if isError(typeName) {
|
||||
return fmt.Sprintf("resultVar%d == nil", i)
|
||||
}
|
||||
}
|
||||
return "true"
|
||||
},
|
||||
"errorPresent": func(results []string) bool {
|
||||
for _, typeName := range results {
|
||||
if isError(typeName) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
},
|
||||
"errorVar": func(results []string) string {
|
||||
for i, typeName := range results {
|
||||
if isError(typeName) {
|
||||
return fmt.Sprintf("resultVar%d", i)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"shouldTrace": func(params map[string]bool, param string) string {
|
||||
if _, ok := params[param]; ok {
|
||||
return fmt.Sprintf(`span.SetTag("%s", %s)`, param, param)
|
||||
}
|
||||
for pName := range params {
|
||||
if strings.HasPrefix(pName, param+".") {
|
||||
return fmt.Sprintf(`span.SetTag("%s", %s)`, pName, pName)
|
||||
}
|
||||
}
|
||||
return ""
|
||||
},
|
||||
"joinParams": func(params []methodParam) string {
|
||||
paramsNames := []string{}
|
||||
for _, param := range params {
|
||||
s := param.Name
|
||||
if strings.HasPrefix(param.Type, "...") {
|
||||
s += "..."
|
||||
}
|
||||
paramsNames = append(paramsNames, s)
|
||||
}
|
||||
return strings.Join(paramsNames, ", ")
|
||||
},
|
||||
"joinParamsWithType": func(params []methodParam) string {
|
||||
paramsWithType := []string{}
|
||||
for _, param := range params {
|
||||
paramsWithType = append(paramsWithType, fmt.Sprintf("%s %s", param.Name, param.Type))
|
||||
}
|
||||
return strings.Join(paramsWithType, ", ")
|
||||
},
|
||||
}
|
||||
|
||||
t := template.Must(template.New("opentracing_layer.go.tmpl").Funcs(myFuncs).ParseFiles(templateFile))
|
||||
err = t.Execute(out, metadata)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out.Bytes(), nil
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
// Code generated by "make app-layers"
|
||||
// DO NOT EDIT
|
||||
|
||||
package opentracing
|
||||
|
||||
import (
|
||||
"github.com/opentracing/opentracing-go/ext"
|
||||
|
||||
spanlog "github.com/opentracing/opentracing-go/log"
|
||||
)
|
||||
|
||||
type {{.Name}} struct {
|
||||
app app.AppIface
|
||||
|
||||
srv *app.Server
|
||||
|
||||
log *mlog.Logger
|
||||
notificationsLog *mlog.Logger
|
||||
|
||||
accountMigration einterfaces.AccountMigrationInterface
|
||||
cluster einterfaces.ClusterInterface
|
||||
compliance einterfaces.ComplianceInterface
|
||||
dataRetention einterfaces.DataRetentionInterface
|
||||
searchEngine *searchengine.Broker
|
||||
ldap einterfaces.LdapInterface
|
||||
messageExport einterfaces.MessageExportInterface
|
||||
metrics einterfaces.MetricsInterface
|
||||
notification einterfaces.NotificationInterface
|
||||
saml einterfaces.SamlInterface
|
||||
|
||||
httpService httpservice.HTTPService
|
||||
imageProxy *imageproxy.ImageProxy
|
||||
timezones *timezones.Timezones
|
||||
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
{{range $index, $element := .Methods}}
|
||||
func (a *{{$.Name}}) {{$index}}({{$element.Params | joinParamsWithType}}) {{$element.Results | joinResultsForSignature}} {
|
||||
origCtx := a.ctx
|
||||
span, newCtx := tracing.StartSpanWithParentByContext(a.ctx, "app.{{$index}}")
|
||||
|
||||
a.ctx = newCtx
|
||||
a.app.Srv().Store().SetContext(newCtx)
|
||||
defer func() {
|
||||
a.app.Srv().Store().SetContext(origCtx)
|
||||
a.ctx = origCtx
|
||||
}()
|
||||
{{range $paramIdx, $param := $element.Params}}
|
||||
{{ shouldTrace $element.ParamsToTrace $param.Name }}
|
||||
{{end}}
|
||||
defer span.Finish()
|
||||
{{- if $element.Results | len | eq 0}}
|
||||
a.app.{{$index}}({{$element.Params | joinParams}})
|
||||
{{else}}
|
||||
{{$element.Results | genResultsVars}} := a.app.{{$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 {{$element.Results | genResultsVars -}}
|
||||
{{end}}}
|
||||
{{end}}
|
||||
|
||||
func NewOpenTracingAppLayer(childApp app.AppIface, ctx context.Context) *{{.Name}} {
|
||||
newApp := {{.Name}}{
|
||||
app: childApp,
|
||||
ctx: ctx,
|
||||
}
|
||||
|
||||
newApp.srv = childApp.Srv()
|
||||
newApp.log = childApp.Log()
|
||||
newApp.notificationsLog = childApp.NotificationsLog()
|
||||
newApp.accountMigration = childApp.AccountMigration()
|
||||
newApp.cluster = childApp.Cluster()
|
||||
newApp.compliance = childApp.Compliance()
|
||||
newApp.dataRetention = childApp.DataRetention()
|
||||
newApp.searchEngine = childApp.SearchEngine()
|
||||
newApp.ldap = childApp.Ldap()
|
||||
newApp.messageExport = childApp.MessageExport()
|
||||
newApp.metrics = childApp.Metrics()
|
||||
newApp.notification = childApp.Notification()
|
||||
newApp.saml = childApp.Saml()
|
||||
newApp.httpService = childApp.HTTPService()
|
||||
newApp.imageProxy = childApp.ImageProxy()
|
||||
newApp.timezones = childApp.Timezones()
|
||||
|
||||
return &newApp
|
||||
}
|
||||
|
||||
|
||||
func (a *{{.Name}}) Srv() *app.Server {
|
||||
return a.srv
|
||||
}
|
||||
func (a *{{.Name}}) Log() *mlog.Logger {
|
||||
return a.log
|
||||
}
|
||||
func (a *{{.Name}}) NotificationsLog() *mlog.Logger {
|
||||
return a.notificationsLog
|
||||
}
|
||||
func (a *{{.Name}}) AccountMigration() einterfaces.AccountMigrationInterface {
|
||||
return a.accountMigration
|
||||
}
|
||||
func (a *{{.Name}}) Cluster() einterfaces.ClusterInterface {
|
||||
return a.cluster
|
||||
}
|
||||
func (a *{{.Name}}) Compliance() einterfaces.ComplianceInterface {
|
||||
return a.compliance
|
||||
}
|
||||
func (a *{{.Name}}) DataRetention() einterfaces.DataRetentionInterface {
|
||||
return a.dataRetention
|
||||
}
|
||||
func (a *{{.Name}}) Ldap() einterfaces.LdapInterface {
|
||||
return a.ldap
|
||||
}
|
||||
func (a *{{.Name}}) MessageExport() einterfaces.MessageExportInterface {
|
||||
return a.messageExport
|
||||
}
|
||||
func (a *{{.Name}}) Metrics() einterfaces.MetricsInterface {
|
||||
return a.metrics
|
||||
}
|
||||
func (a *{{.Name}}) Notification() einterfaces.NotificationInterface {
|
||||
return a.notification
|
||||
}
|
||||
func (a *{{.Name}}) Saml() einterfaces.SamlInterface {
|
||||
return a.saml
|
||||
}
|
||||
func (a *{{.Name}}) HTTPService() httpservice.HTTPService {
|
||||
return a.httpService
|
||||
}
|
||||
func (a *{{.Name}}) ImageProxy() *imageproxy.ImageProxy {
|
||||
return a.imageProxy
|
||||
}
|
||||
func (a *{{.Name}}) Timezones() *timezones.Timezones {
|
||||
return a.timezones
|
||||
}
|
||||
func (a *{{.Name}}) SetServer(srv *app.Server) {
|
||||
a.srv = srv
|
||||
}
|
||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/mattermost/mattermost/server/public/shared/request"
|
||||
)
|
||||
|
||||
func PostPriorityCheckWithApp(where string, a AppIface, userId string, priority *model.PostPriority, rootId string) *model.AppError {
|
||||
func PostPriorityCheckWithApp(where string, a *App, userId string, priority *model.PostPriority, rootId string) *model.AppError {
|
||||
user, appErr := a.GetUser(userId)
|
||||
if appErr != nil {
|
||||
return appErr
|
||||
@@ -84,7 +84,7 @@ func postPriorityCheck(
|
||||
return nil
|
||||
}
|
||||
|
||||
func PostHardenedModeCheckWithApp(a AppIface, isIntegration bool, props model.StringInterface) *model.AppError {
|
||||
func PostHardenedModeCheckWithApp(a *App, isIntegration bool, props model.StringInterface) *model.AppError {
|
||||
hardenedModeEnabled := *a.Config().ServiceSettings.ExperimentalEnableHardenedMode
|
||||
return postHardenedModeCheck(hardenedModeEnabled, isIntegration, props)
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func postHardenedModeCheck(hardenedModeEnabled, isIntegration bool, props model.
|
||||
return nil
|
||||
}
|
||||
|
||||
func userCreatePostPermissionCheckWithApp(c request.CTX, a AppIface, userId, channelId string) *model.AppError {
|
||||
func userCreatePostPermissionCheckWithApp(c request.CTX, a *App, userId, channelId string) *model.AppError {
|
||||
hasPermission := false
|
||||
if a.HasPermissionToChannel(c, userId, channelId, model.PermissionCreatePost) {
|
||||
hasPermission = true
|
||||
|
||||
@@ -74,7 +74,6 @@ import (
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/searchengine/bleveengine/indexer"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/sharedchannel"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/telemetry"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/tracing"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/services/upgrader"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/shared/filestore"
|
||||
"github.com/mattermost/mattermost/server/v8/platform/shared/mail"
|
||||
@@ -153,8 +152,6 @@ type Server struct {
|
||||
IPFiltering einterfaces.IPFilteringInterface
|
||||
OutgoingOAuthConnection einterfaces.OutgoingOAuthConnectionInterface
|
||||
|
||||
tracer *tracing.Tracer
|
||||
|
||||
ch *Channels
|
||||
}
|
||||
|
||||
@@ -306,14 +303,6 @@ func NewServer(options ...Option) (*Server, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if *s.platform.Config().ServiceSettings.EnableOpenTracing {
|
||||
tracer, err2 := tracing.New()
|
||||
if err2 != nil {
|
||||
return nil, err2
|
||||
}
|
||||
s.tracer = tracer
|
||||
}
|
||||
|
||||
s.pushNotificationClient = s.httpService.MakeClient(true)
|
||||
s.outgoingWebhookClient = s.httpService.MakeClient(false)
|
||||
|
||||
@@ -689,12 +678,6 @@ func (s *Server) Shutdown() {
|
||||
s.RemoveLicenseListener(s.loggerLicenseListenerId)
|
||||
s.RemoveClusterLeaderChangedListener(s.clusterLeaderListenerId)
|
||||
|
||||
if s.tracer != nil {
|
||||
if err := s.tracer.Close(); err != nil {
|
||||
s.Log().Warn("Unable to cleanly shutdown opentracing client", mlog.Err(err))
|
||||
}
|
||||
}
|
||||
|
||||
err := s.telemetryService.Shutdown()
|
||||
if err != nil {
|
||||
s.Log().Warn("Unable to cleanly shutdown telemetry client", mlog.Err(err))
|
||||
|
||||
Ссылка в новой задаче
Block a user