mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-04-19 02:03:39 +00:00
linting, remove some unnecessary code
This commit is contained in:
parent
6649f77076
commit
5177a384f8
5 changed files with 20 additions and 38 deletions
|
@ -31,13 +31,6 @@ func main() {
|
||||||
|
|
||||||
federation := base.CreateFederationClient()
|
federation := base.CreateFederationClient()
|
||||||
|
|
||||||
/* TODO delete
|
|
||||||
err = tracers.InitGlobalTracer("Dendrite - Federation Sender")
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Fatalf("Failed to start tracer")
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
_, _, query := base.CreateHTTPRoomserverAPIs()
|
_, _, query := base.CreateHTTPRoomserverAPIs()
|
||||||
|
|
||||||
federationsender.SetupFederationSenderComponent(
|
federationsender.SetupFederationSenderComponent(
|
||||||
|
|
|
@ -18,7 +18,7 @@ type statusCodeResponseWriter struct {
|
||||||
statusCode int
|
statusCode int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStatusCodeResponseWriter(w http.ResponseWriter) *statusCodeResponseWriter {
|
func newStatusCodeResponseWriter(w http.ResponseWriter) *statusCodeResponseWriter {
|
||||||
return &statusCodeResponseWriter{w, http.StatusOK}
|
return &statusCodeResponseWriter{w, http.StatusOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ func MakeExternalAPI(tracer opentracing.Tracer, metricsName string, f func(*http
|
||||||
ext.HTTPMethod.Set(span, req.Method)
|
ext.HTTPMethod.Set(span, req.Method)
|
||||||
|
|
||||||
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span))
|
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span))
|
||||||
rw := NewStatusCodeResponseWriter(w)
|
rw := newStatusCodeResponseWriter(w)
|
||||||
|
|
||||||
h.ServeHTTP(w, req)
|
h.ServeHTTP(w, req)
|
||||||
ext.HTTPStatusCode.Set(span, uint16(rw.statusCode))
|
ext.HTTPStatusCode.Set(span, uint16(rw.statusCode))
|
||||||
|
@ -91,7 +91,7 @@ func MakeInternalAPI(tracer opentracing.Tracer, metricsName string, f func(*http
|
||||||
ext.HTTPUrl.Set(span, req.URL.String())
|
ext.HTTPUrl.Set(span, req.URL.String())
|
||||||
ext.HTTPMethod.Set(span, req.Method)
|
ext.HTTPMethod.Set(span, req.Method)
|
||||||
|
|
||||||
// TODO: Do we need to do the NewStatusCodeResponseWriter stuff?
|
// TODO: Do we need to do the newStatusCodeResponseWriter stuff?
|
||||||
|
|
||||||
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span))
|
req = req.WithContext(opentracing.ContextWithSpan(req.Context(), span))
|
||||||
h.ServeHTTP(w, req)
|
h.ServeHTTP(w, req)
|
||||||
|
|
|
@ -24,43 +24,29 @@ import (
|
||||||
jaegermetrics "github.com/uber/jaeger-lib/metrics"
|
jaegermetrics "github.com/uber/jaeger-lib/metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Tracers is a collection of Jaeger OpenTracing tracers. There is one tracer
|
||||||
|
// per Dendrite component, and each is kept track of with a single Tracers
|
||||||
|
// object. Upon shutdown, each tracer is closed by calling the Tracers' Close()
|
||||||
|
// method.
|
||||||
type Tracers struct {
|
type Tracers struct {
|
||||||
cfg *config.Dendrite
|
cfg *config.Dendrite
|
||||||
closers []io.Closer
|
closers []io.Closer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoopTracers is a Tracers object that will never contain any tracers. Disables tracing.
|
||||||
func NoopTracers() *Tracers {
|
func NoopTracers() *Tracers {
|
||||||
return &Tracers{}
|
return &Tracers{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewTracers creates a new Tracers object with the given Dendrite config.
|
||||||
func NewTracers(cfg *config.Dendrite) *Tracers {
|
func NewTracers(cfg *config.Dendrite) *Tracers {
|
||||||
return &Tracers{
|
return &Tracers{
|
||||||
cfg: cfg,
|
cfg: cfg,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tracers) InitGlobalTracer(serviceName string) error {
|
// SetupNewTracer creates a new tracer and adds it to those being kept track of
|
||||||
if t.cfg == nil {
|
// on the linked Tracers object.
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set up GlobalTracer
|
|
||||||
closer, err := t.cfg.Tracing.Jaeger.InitGlobalTracer(
|
|
||||||
serviceName,
|
|
||||||
jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}),
|
|
||||||
jaegerconfig.Metrics(jaegermetrics.NullFactory),
|
|
||||||
)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
t.closers = append(t.closers, closer)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetupTracing configures the opentracing using the supplied configuration.
|
|
||||||
func (t *Tracers) SetupNewTracer(serviceName string) opentracing.Tracer {
|
func (t *Tracers) SetupNewTracer(serviceName string) opentracing.Tracer {
|
||||||
if t.cfg == nil {
|
if t.cfg == nil {
|
||||||
return opentracing.NoopTracer{}
|
return opentracing.NoopTracer{}
|
||||||
|
@ -81,6 +67,7 @@ func (t *Tracers) SetupNewTracer(serviceName string) opentracing.Tracer {
|
||||||
return tracer
|
return tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close will close all Jaeger OpenTracing tracers associated with the Tracers object.
|
||||||
func (t *Tracers) Close() error {
|
func (t *Tracers) Close() error {
|
||||||
for _, c := range t.closers {
|
for _, c := range t.closers {
|
||||||
c.Close() // nolint: errcheck
|
c.Close() // nolint: errcheck
|
||||||
|
@ -94,10 +81,12 @@ type logrusLogger struct {
|
||||||
l *logrus.Logger
|
l *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Error prints an error message to the logger
|
||||||
func (l logrusLogger) Error(msg string) {
|
func (l logrusLogger) Error(msg string) {
|
||||||
l.l.Error(msg)
|
l.l.Error(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Infof prints an info message with printf formatting to the logger
|
||||||
func (l logrusLogger) Infof(msg string, args ...interface{}) {
|
func (l logrusLogger) Infof(msg string, args ...interface{}) {
|
||||||
l.l.Infof(msg, args...)
|
l.l.Infof(msg, args...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,17 +95,14 @@ func (r *RoomserverInputAPI) SetupHTTP(servMux *http.ServeMux, tracer opentracin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InProcessRoomServerInput is a RoomserverInput database linked with a
|
||||||
|
// OpenTracing tracer, providing metrics
|
||||||
type InProcessRoomServerInput struct {
|
type InProcessRoomServerInput struct {
|
||||||
db RoomserverInputAPI
|
db RoomserverInputAPI
|
||||||
tracer opentracing.Tracer
|
tracer opentracing.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewInProcessRoomServerInput(db RoomserverInputAPI, tracer opentracing.Tracer) *InProcessRoomServerInput {
|
// InputRoomEvents is a wrapper providing opentracing metrics data around room events
|
||||||
return &InProcessRoomServerInput{
|
|
||||||
db: db, tracer: tracer,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (r *InProcessRoomServerInput) InputRoomEvents(
|
func (r *InProcessRoomServerInput) InputRoomEvents(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
request *api.InputRoomEventsRequest,
|
request *api.InputRoomEventsRequest,
|
||||||
|
|
|
@ -711,11 +711,14 @@ func (r *RoomserverQueryAPI) SetupHTTP(servMux *http.ServeMux, tracer opentracin
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InProcessRoomServerQueryAPI is a RoomserverQueryAPI database linked with a
|
||||||
|
// OpenTracing tracer, providing metrics
|
||||||
type InProcessRoomServerQueryAPI struct {
|
type InProcessRoomServerQueryAPI struct {
|
||||||
db RoomserverQueryAPI
|
db RoomserverQueryAPI
|
||||||
tracer opentracing.Tracer
|
tracer opentracing.Tracer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewInProcessRoomServerQueryAPI creates a new InProcessRoomServerQueryAPI
|
||||||
func NewInProcessRoomServerQueryAPI(db RoomserverQueryAPI, tracer opentracing.Tracer) InProcessRoomServerQueryAPI {
|
func NewInProcessRoomServerQueryAPI(db RoomserverQueryAPI, tracer opentracing.Tracer) InProcessRoomServerQueryAPI {
|
||||||
return InProcessRoomServerQueryAPI{
|
return InProcessRoomServerQueryAPI{
|
||||||
db: db,
|
db: db,
|
||||||
|
|
Loading…
Reference in a new issue