Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: Remove tracing code #2420

Merged
merged 4 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions alert/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/target/goalert/validation/validate"

"github.com/pkg/errors"
"go.opencensus.io/trace"
)

const maxBatch = 500
Expand Down Expand Up @@ -497,19 +496,13 @@ func (s *Store) Create(ctx context.Context, a *Alert) (*Alert, error) {
return nil, err
}

trace.FromContext(ctx).Annotate(
[]trace.Attribute{
trace.StringAttribute("service.id", n.ServiceID),
trace.Int64Attribute("alert.id", int64(n.ID)),
},
"Alert created.",
)
ctx = log.WithFields(ctx, log.Fields{"AlertID": n.ID, "ServiceID": n.ServiceID})
log.Logf(ctx, "Alert created.")
metricCreatedTotal.Inc()

return n, nil
}

func (s *Store) _create(ctx context.Context, tx *sql.Tx, a Alert) (*Alert, *alertlog.CreatedMetaData, error) {
var meta alertlog.CreatedMetaData
row := tx.StmtContext(ctx, s.insert).QueryRowContext(ctx, a.Summary, a.Details, a.ServiceID, a.Source, a.Status, a.DedupKey())
Expand Down Expand Up @@ -641,13 +634,6 @@ func (s *Store) CreateOrUpdate(ctx context.Context, a *Alert) (*Alert, error) {
return nil, nil
}
if isNew {
trace.FromContext(ctx).Annotate(
[]trace.Attribute{
trace.StringAttribute("service.id", n.ServiceID),
trace.Int64Attribute("alert.id", int64(n.ID)),
},
"Alert created.",
)
ctx = log.WithFields(ctx, log.Fields{"AlertID": n.ID, "ServiceID": n.ServiceID})
log.Logf(ctx, "Alert created.")
metricCreatedTotal.Inc()
Expand Down
38 changes: 0 additions & 38 deletions app/clusterexporter.go

This file was deleted.

62 changes: 20 additions & 42 deletions app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"github.com/target/goalert/validation"
"github.com/target/goalert/version"
"github.com/target/goalert/web"
"go.opencensus.io/trace"
"golang.org/x/term"
)

Expand Down Expand Up @@ -85,22 +84,6 @@ var RootCmd = &cobra.Command{
if err != nil {
return err
}
exporters, err := configTracing(ctx, cfg)
if err != nil {
return errors.Wrap(err, "config tracing")
}

defer func() {
// flush exporters
type flusher interface {
Flush()
}
for _, e := range exporters {
if f, ok := e.(flusher); ok {
f.Flush()
}
}
}()

wrappedDriver := sqldrv.NewRetryDriver(&stdlib.Driver{}, 10)

Expand Down Expand Up @@ -197,18 +180,16 @@ func handleShutdown(ctx context.Context, fn func(ctx context.Context) error) {
log.Logf(ctx, "Application attempting graceful shutdown.")
sCtx, cancel := context.WithTimeout(ctx, shutdownTimeout)
defer cancel()
sCtx, sp := trace.StartSpan(sCtx, "Shutdown")
defer sp.End()

go func() {
<-shutdownSignalCh
log.Logf(ctx, "Second signal received, terminating immediately")
sp.Annotate([]trace.Attribute{trace.BoolAttribute("shutdown.force", true)}, "Second signal received.")
cancel()
}()

err := fn(sCtx)
if err != nil {
sp.Annotate([]trace.Attribute{trace.BoolAttribute("error", true)}, err.Error())
log.Log(ctx, err)
}
}

Expand Down Expand Up @@ -664,18 +645,6 @@ func getConfig(ctx context.Context) (Config, error) {
DBURL: viper.GetString("db-url"),
DBURLNext: viper.GetString("db-url-next"),

JaegerEndpoint: viper.GetString("jaeger-endpoint"),
JaegerAgentEndpoint: viper.GetString("jaeger-agent-endpoint"),

StackdriverProjectID: viper.GetString("stackdriver-project-id"),

TracingClusterName: viper.GetString("tracing-cluster-name"),
TracingPodNamespace: viper.GetString("tracing-pod-namespace"),
TracingPodName: viper.GetString("tracing-pod-name"),
TracingContainerName: viper.GetString("tracing-container-name"),
TracingNodeName: viper.GetString("tracing-node-name"),
TraceProbability: viper.GetFloat64("tracing-probability"),

KubernetesCooldown: viper.GetDuration("kubernetes-cooldown"),
StatusAddr: viper.GetString("status-addr"),

Expand Down Expand Up @@ -744,15 +713,24 @@ func init() {
RootCmd.PersistentFlags().String("db-url", def.DBURL, "Connection string for Postgres.")
RootCmd.PersistentFlags().String("db-url-next", def.DBURLNext, "Connection string for the *next* Postgres server (enables DB switch-over mode).")

RootCmd.Flags().String("jaeger-endpoint", def.JaegerEndpoint, "Jaeger HTTP Thrift endpoint")
RootCmd.Flags().String("jaeger-agent-endpoint", def.JaegerAgentEndpoint, "Instructs Jaeger exporter to send spans to jaeger-agent at this address.")
RootCmd.Flags().String("stackdriver-project-id", def.StackdriverProjectID, "Project ID for Stackdriver. Enables tracing output to Stackdriver.")
RootCmd.Flags().String("tracing-cluster-name", def.TracingClusterName, "Cluster name to use for tracing (i.e. kubernetes, Stackdriver/GKE environment).")
RootCmd.Flags().String("tracing-pod-namespace", def.TracingPodNamespace, "Pod namespace to use for tracing.")
RootCmd.Flags().String("tracing-pod-name", def.TracingPodName, "Pod name to use for tracing.")
RootCmd.Flags().String("tracing-container-name", def.TracingContainerName, "Container name to use for tracing.")
RootCmd.Flags().String("tracing-node-name", def.TracingNodeName, "Node name to use for tracing.")
RootCmd.Flags().Float64("tracing-probability", def.TraceProbability, "Probability of a new trace to be recorded.")
RootCmd.Flags().String("jaeger-endpoint", "", "Jaeger HTTP Thrift endpoint")
RootCmd.Flags().String("jaeger-agent-endpoint", "", "Instructs Jaeger exporter to send spans to jaeger-agent at this address.")
RootCmd.Flags().MarkDeprecated("jaeger-endpoint", "Jaeger support has been removed.")
RootCmd.Flags().MarkDeprecated("jaeger-agent-endpoint", "Jaeger support has been removed.")
RootCmd.Flags().String("stackdriver-project-id", "", "Project ID for Stackdriver. Enables tracing output to Stackdriver.")
RootCmd.Flags().MarkDeprecated("stackdriver-project-id", "Stackdriver support has been removed.")
RootCmd.Flags().String("tracing-cluster-name", "", "Cluster name to use for tracing (i.e. kubernetes, Stackdriver/GKE environment).")
RootCmd.Flags().MarkDeprecated("tracing-cluster-name", "Tracing support has been removed.")
RootCmd.Flags().String("tracing-pod-namespace", "", "Pod namespace to use for tracing.")
RootCmd.Flags().MarkDeprecated("tracing-pod-namespace", "Tracing support has been removed.")
RootCmd.Flags().String("tracing-pod-name", "", "Pod name to use for tracing.")
RootCmd.Flags().MarkDeprecated("tracing-pod-name", "Tracing support has been removed.")
RootCmd.Flags().String("tracing-container-name", "", "Container name to use for tracing.")
RootCmd.Flags().MarkDeprecated("tracing-container-name", "Tracing support has been removed.")
RootCmd.Flags().String("tracing-node-name", "", "Node name to use for tracing.")
RootCmd.Flags().MarkDeprecated("tracing-node-name", "Tracing support has been removed.")
RootCmd.Flags().Float64("tracing-probability", 0, "Probability of a new trace to be recorded.")
RootCmd.Flags().MarkDeprecated("tracing-probability", "Tracing support has been removed.")

RootCmd.Flags().Duration("kubernetes-cooldown", def.KubernetesCooldown, "Cooldown period, from the last TCP connection, before terminating the listener when receiving a shutdown signal.")
RootCmd.Flags().String("status-addr", def.StatusAddr, "Open a port to emit status updates. Connections are closed when the server shuts down. Can be used to keep containers running until GoAlert has exited.")
Expand Down
14 changes: 0 additions & 14 deletions app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,9 @@ type Config struct {
DBURL string
DBURLNext string

JaegerEndpoint string
JaegerAgentEndpoint string

StackdriverProjectID string

TracingClusterName string
TracingPodNamespace string
TracingPodName string
TracingContainerName string
TracingNodeName string

KubernetesCooldown time.Duration
StatusAddr string

LogTraces bool
TraceProbability float64

EncryptionKeys keyring.Keys

RegionName string
Expand Down
1 change: 0 additions & 1 deletion app/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ func Defaults() Config {
MaxReqBodyBytes: 256 * 1024,
MaxReqHeaderBytes: 4096,
RegionName: "default",
TraceProbability: 0.01,
}
}
21 changes: 0 additions & 21 deletions app/inithttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"

"contrib.go.opencensus.io/exporter/stackdriver/propagation"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/target/goalert/config"
"github.com/target/goalert/genericapi"
Expand All @@ -20,36 +19,16 @@ import (
"github.com/target/goalert/util/log"
"github.com/target/goalert/util/sqlutil"
"github.com/target/goalert/web"
"go.opencensus.io/plugin/ochttp"
)

func (app *App) initHTTP(ctx context.Context) error {
var traceMiddleware func(next http.Handler) http.Handler
if app.cfg.StackdriverProjectID != "" {
traceMiddleware = func(next http.Handler) http.Handler {
return &ochttp.Handler{
IsPublicEndpoint: true,
Propagation: &propagation.HTTPFormat{},
Handler: next,
}
}
} else {
traceMiddleware = func(next http.Handler) http.Handler {
return &ochttp.Handler{
IsPublicEndpoint: true,
Handler: next,
}
}
}

middleware := []func(http.Handler) http.Handler{
func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
next.ServeHTTP(w, req.WithContext(log.WithLogger(req.Context(), app.cfg.Logger)))
})
},

traceMiddleware,
// add app config to request context
func(next http.Handler) http.Handler { return config.Handler(next, app.ConfigStore) },

Expand Down
3 changes: 0 additions & 3 deletions app/inittwilio.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ package app

import (
"context"
"net/http"

"github.com/target/goalert/notification"
"github.com/target/goalert/notification/twilio"

"github.com/pkg/errors"
"go.opencensus.io/plugin/ochttp"
)

func (app *App) initTwilio(ctx context.Context) error {
app.twilioConfig = &twilio.Config{
BaseURL: app.cfg.TwilioBaseURL,
Client: &http.Client{Transport: &ochttp.Transport{}},
CMStore: app.ContactMethodStore,
}

Expand Down
19 changes: 0 additions & 19 deletions app/logexporter.go

This file was deleted.

7 changes: 3 additions & 4 deletions app/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (

"github.com/target/goalert/switchover"
"github.com/target/goalert/util/log"

"go.opencensus.io/trace"
)

func (app *App) pauseHandler(next http.Handler) http.Handler {
Expand All @@ -28,8 +26,6 @@ func (app *App) LogBackgroundContext() context.Context { return app.cfg.Logger.B

func (app *App) Pause(ctx context.Context) error {
ctx = log.WithLogger(ctx, app.cfg.Logger)
ctx, sp := trace.StartSpan(ctx, "App.Pause")
defer sp.End()

err := app.mgr.Pause(ctx)
if err != nil {
Expand All @@ -38,10 +34,12 @@ func (app *App) Pause(ctx context.Context) error {
app.db.SetMaxIdleConns(0)
return nil
}

func (app *App) Resume() {
app.db.SetMaxIdleConns(app.cfg.DBMaxIdle)
app.mgr.Resume(app.LogBackgroundContext())
}

func (app *App) _pause(ctx context.Context) error {
app.events.Stop()

Expand All @@ -56,6 +54,7 @@ func (app *App) _pause(ctx context.Context) error {
}
return nil
}

func (app *App) _resume(ctx context.Context) error {
app.events.Start()
app.requestLock.Unlock()
Expand Down
41 changes: 0 additions & 41 deletions app/recoverexporter.go

This file was deleted.

Loading