Skip to content

Commit

Permalink
introspection: implement prometheus http
Browse files Browse the repository at this point in the history
this commit implements promethemeus metrics and removes OTEL usage for
metrics.

dogstatd metrics are now deprecated infavor of conforming on prometheus
metrics.

Signed-off-by: ldelossa <ldelossa@redhat.com>
  • Loading branch information
ldelossa authored and ldelossa committed Feb 23, 2021
1 parent 9d0a2b2 commit 84ba35f
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 335 deletions.
10 changes: 0 additions & 10 deletions Documentation/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,13 +650,3 @@ Defines distributed tracing configuration based on OpenTelemtry
```
a string value
```

### &emsp;dogstatsd: \<object\>
```
Defines distributed tracing configuration based on OpenTelemtry
```

#### &emsp;&emsp;url: ""
```
a string value
```
11 changes: 6 additions & 5 deletions config/introspection.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package config

// Configure distributed tracing via OTEL
type Trace struct {
Name string `yaml:"name" json:"name"`
Probability *float64 `yaml:"probability" json:"probability"`
Jaeger Jaeger `yaml:"jaeger" json:"jaeger"`
}

// Jager specific distributed tracing configuration.
type Jaeger struct {
Agent struct {
Endpoint string `yaml:"endpoint" json:"endpoint"`
Expand All @@ -20,16 +22,15 @@ type Jaeger struct {
BufferMax int `yaml:"buffer_max" json:"buffer_max"`
}

// Configure Metrics.
type Metrics struct {
Name string `yaml:"name" json:"name"`
Prometheus Prometheus `yaml:"prometheus" json:"prometheus"`
Dogstatsd Dogstatsd `yaml:"dogstatsd" json:"dogstatsd"`
}

// Prometheus specific metrics configuration
type Prometheus struct {
// Endpoint is a URL path where
// Prometheus metrics will be hosted.
Endpoint *string `yaml:"endpoint" json:"endpoint"`
}

type Dogstatsd struct {
URL string `yaml:"url" json:"url"`
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ require (
github.com/jackc/pgx/v4 v4.7.2
github.com/jmoiron/sqlx v1.2.0
github.com/klauspost/compress v1.10.11
github.com/ldelossa/responserecorder v1.0.1
github.com/mattn/go-sqlite3 v1.11.0 // indirect
github.com/prometheus/client_golang v1.9.0
github.com/prometheus/procfs v0.3.0 // indirect
github.com/quay/claircore v0.3.1
github.com/quay/zlog v0.0.0-20210113185248-ce16eed1dcec
Expand All @@ -21,11 +23,9 @@ require (
github.com/streadway/amqp v1.0.0
github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80
github.com/urfave/cli/v2 v2.2.0
go.opentelemetry.io/contrib/exporters/metric/dogstatsd v0.16.0
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.16.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.16.0
go.opentelemetry.io/otel v0.16.0
go.opentelemetry.io/otel/exporters/metric/prometheus v0.16.0
go.opentelemetry.io/otel/exporters/stdout v0.16.0
go.opentelemetry.io/otel/exporters/trace/jaeger v0.16.0
go.opentelemetry.io/otel/sdk v0.16.0
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,8 @@ github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/ldelossa/responserecorder v1.0.1 h1:q5dF1Io1Rn/vW0ehbqdAEjoerwD4Iv1TPGWwWuGFaIM=
github.com/ldelossa/responserecorder v1.0.1/go.mod h1:NGV7dXE6J4C7+RyXmtYcKuCafuk5dJ0FOijopdGVL9s=
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
Expand Down Expand Up @@ -730,17 +732,13 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
go.opentelemetry.io/contrib v0.16.0 h1:cScR/U3bjTjxsBv939wh4miANY/akdP644rsg9msrIA=
go.opentelemetry.io/contrib v0.16.0/go.mod h1:G/EtFaa6qaN7+LxqfIAT3GiZa7Wv5DTBUzl5H4LY0Kc=
go.opentelemetry.io/contrib/exporters/metric/dogstatsd v0.16.0 h1:GqY7aTMfQYzIC9vu7nQSl7J9wYbyTraFlIOxCXSGA+4=
go.opentelemetry.io/contrib/exporters/metric/dogstatsd v0.16.0/go.mod h1:CdcdrNPfemEBluEq9vSgxM72ya/E1j+t7aXyLUUjF8w=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.16.0 h1:4j5Pg5JoT9FGQx2zXbfKq+JabtbUpuB+bUmhPZB5hUM=
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.16.0/go.mod h1:P5mQmVnXk429V+RQnY79cRDxP7KeFqEirKBXwQkvfPA=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.16.0 h1:hPbUH5fugPACtUdBWGL5glNqzowwHvnOdnwvQOATWgM=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.16.0/go.mod h1:dNF4PMGeouMEPAWDwgEjsGFlod9hAU8oj0TU0w2J19g=
go.opentelemetry.io/otel v0.15.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA=
go.opentelemetry.io/otel v0.16.0 h1:uIWEbdeb4vpKPGITLsRVUS44L5oDbDUCZxn8lkxhmgw=
go.opentelemetry.io/otel v0.16.0/go.mod h1:e4GKElweB8W2gWUqbghw0B8t5MCTccc9212eNHnOHwA=
go.opentelemetry.io/otel/exporters/metric/prometheus v0.16.0 h1:0tB24Dht89vSfsD9JXO5HeEfan/Tb6eQk4U6s9a23qE=
go.opentelemetry.io/otel/exporters/metric/prometheus v0.16.0/go.mod h1:7G+4inqxyC+1GQGsAroJVRBFL2gNM8khsI15T5Xm4l0=
go.opentelemetry.io/otel/exporters/stdout v0.16.0 h1:lQG6ZZYLh3NxnmrHltRmqZolT/jPJ8Qfl74lWT8g69Y=
go.opentelemetry.io/otel/exporters/stdout v0.16.0/go.mod h1:bq7m22M7WIxz30KnxH9lI4RLKPajk0lnLsd5P2MsSv8=
go.opentelemetry.io/otel/exporters/trace/jaeger v0.16.0 h1:gOnjphv9uycs+AfZprppdsm/P7B0CVxPr5E1UtT2wqw=
Expand Down
40 changes: 0 additions & 40 deletions httptransport/logginghandler.go

This file was deleted.

159 changes: 36 additions & 123 deletions httptransport/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,8 @@ func New(ctx context.Context, conf config.Config, indexer indexer.Service, match
// configureDiscovery() creates a discovery handler
// for serving the v1 open api specification
func (t *Server) configureDiscovery(_ context.Context) error {
h := intromw.Handler(
othttp.NewHandler(
LoggingHandler(DiscoveryHandler()),
OpenAPIV1Path,
t.traceOpt,
),
OpenAPIV1Path,
)
t.Handle(OpenAPIV1Path, othttp.WithRouteTag(OpenAPIV1Path, h))
t.Handle(OpenAPIV1Path,
intromw.InstrumentedHandler(OpenAPIV1Path, t.traceOpt, DiscoveryHandler()))
return nil
}

Expand All @@ -141,22 +134,22 @@ func (t *Server) configureDiscovery(_ context.Context) error {
func (t *Server) configureComboMode(ctx context.Context) error {
// requires both indexer and matcher services
if t.indexer == nil || t.matcher == nil {
return clairerror.ErrNotInitialized{"Combo mode requires both indexer and macher services"}
return clairerror.ErrNotInitialized{Msg: "Combo mode requires both indexer and macher services"}
}

err := t.configureIndexerMode(ctx)
if err != nil {
return clairerror.ErrNotInitialized{"could not configure indexer: " + err.Error()}
return clairerror.ErrNotInitialized{Msg: "could not configure indexer: " + err.Error()}
}

err = t.configureMatcherMode(ctx)
if err != nil {
return clairerror.ErrNotInitialized{"could not configure matcher: " + err.Error()}
return clairerror.ErrNotInitialized{Msg: "could not configure matcher: " + err.Error()}
}

err = t.configureNotifierMode(ctx)
if err != nil {
return clairerror.ErrNotInitialized{"could not configure notifier: " + err.Error()}
return clairerror.ErrNotInitialized{Msg: "could not configure notifier: " + err.Error()}
}

return nil
Expand All @@ -168,52 +161,20 @@ func (t *Server) configureComboMode(ctx context.Context) error {
func (t *Server) configureIndexerMode(_ context.Context) error {
// requires only indexer service
if t.indexer == nil {
return clairerror.ErrNotInitialized{"IndexerMode requires an indexer service"}
return clairerror.ErrNotInitialized{Msg: "IndexerMode requires an indexer service"}
}

// affected manifest handler register
affectedH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(AffectedManifestHandler(t.indexer)),
AffectedManifestAPIPath,
t.traceOpt,
),
AffectedManifestAPIPath,
)
t.Handle(AffectedManifestAPIPath, othttp.WithRouteTag(AffectedManifestAPIPath, affectedH))

// index handler register
indexH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(IndexHandler(t.indexer)),
IndexAPIPath,
t.traceOpt,
),
IndexAPIPath,
)
t.Handle(IndexAPIPath, othttp.WithRouteTag(IndexAPIPath, indexH))

// index report handler register
indexReportH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(IndexReportHandler(t.indexer)),
IndexReportAPIPath,
t.traceOpt,
),
IndexReportAPIPath,
)
t.Handle(IndexReportAPIPath, othttp.WithRouteTag(IndexReportAPIPath, indexReportH))

// index state handler register
stateH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(IndexStateHandler(t.indexer)),
IndexStateAPIPath,
t.traceOpt,
),
IndexStateAPIPath,
)
t.Handle(IndexStateAPIPath, othttp.WithRouteTag(IndexStateAPIPath, stateH))
t.Handle(AffectedManifestAPIPath,
intromw.InstrumentedHandler(AffectedManifestAPIPath, t.traceOpt, AffectedManifestHandler(t.indexer)))

t.Handle(IndexAPIPath,
intromw.InstrumentedHandler(IndexAPIPath, t.traceOpt, IndexHandler(t.indexer)))

t.Handle(IndexReportAPIPath,
intromw.InstrumentedHandler(IndexReportAPIPath+"GET", t.traceOpt, IndexReportHandler(t.indexer)))

t.Handle(IndexStateAPIPath,
intromw.InstrumentedHandler(IndexStateAPIPath, t.traceOpt, IndexReportHandler(t.indexer)))

return nil
}
Expand All @@ -223,41 +184,17 @@ func (t *Server) configureMatcherMode(_ context.Context) error {
// requires both an indexer and matcher service. indexer service
// is assumed to be a remote call over the network
if t.indexer == nil || t.matcher == nil {
return clairerror.ErrNotInitialized{"MatcherMode requires both indexer and matcher services"}
return clairerror.ErrNotInitialized{Msg: "MatcherMode requires both indexer and matcher services"}
}

// vulnerability report handler register
vulnReportH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(VulnerabilityReportHandler(t.matcher, t.indexer)),
VulnerabilityReportPath,
t.traceOpt,
),
VulnerabilityReportPath,
)
t.Handle(VulnerabilityReportPath, othttp.WithRouteTag(VulnerabilityReportPath, vulnReportH))

// update operation handler register
opH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(UpdateOperationHandler(t.matcher)),
UpdateOperationAPIPath,
t.traceOpt,
),
UpdateOperationAPIPath,
)
t.Handle(UpdateOperationAPIPath, othttp.WithRouteTag(UpdateOperationAPIPath, opH))

// update diff handler register
diffH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(UpdateDiffHandler(t.matcher)),
UpdateDiffAPIPath,
t.traceOpt,
),
UpdateDiffAPIPath,
)
t.Handle(UpdateDiffAPIPath, othttp.WithRouteTag(UpdateDiffAPIPath, diffH))
t.Handle(VulnerabilityReportPath,
intromw.InstrumentedHandler(VulnerabilityReportPath, t.traceOpt, VulnerabilityReportHandler(t.matcher, t.indexer)))

t.Handle(UpdateOperationAPIPath,
intromw.InstrumentedHandler(UpdateOperationAPIPath, t.traceOpt, UpdateOperationHandler(t.matcher)))

t.Handle(UpdateDiffAPIPath,
intromw.InstrumentedHandler(UpdateDiffAPIPath, t.traceOpt, UpdateDiffHandler(t.matcher)))

return nil
}
Expand All @@ -267,46 +204,22 @@ func (t *Server) configureNotifierMode(ctx context.Context) error {
// requires both an indexer and matcher service. indexer service
// is assumed to be a remote call over the network
if t.notifier == nil {
return clairerror.ErrNotInitialized{"NotifierMode requires a notifier service"}
return clairerror.ErrNotInitialized{Msg: "NotifierMode requires a notifier service"}
}

// notifications callback handler
callbackH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(NotificationHandler(t.notifier)),
NotificationAPIPath,
t.traceOpt,
),
NotificationAPIPath,
)
t.Handle(NotificationAPIPath, othttp.WithRouteTag(NotificationAPIPath, callbackH))
t.Handle(NotificationAPIPath,
intromw.InstrumentedHandler(NotificationAPIPath, t.traceOpt, NotificationHandler(t.notifier)))

ks := t.notifier.KeyStore(ctx)
if ks == nil {
return clairerror.ErrNotInitialized{"NotifierMode requires the notifier to provide a non-nil key store"}
return clairerror.ErrNotInitialized{Msg: "NotifierMode requires the notifier to provide a non-nil key store"}
}

// keys handler
keysH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(KeysHandler(ks)),
KeysAPIPath,
t.traceOpt,
),
KeysAPIPath,
)
t.Handle(KeysAPIPath, othttp.WithRouteTag(KeysAPIPath, keysH))

// key by ID handler
keyByIDH := intromw.Handler(
othttp.NewHandler(
LoggingHandler(KeyByIDHandler(ks)),
KeyByIDAPIPath,
t.traceOpt,
),
KeyByIDAPIPath,
)
t.Handle(KeyByIDAPIPath, othttp.WithRouteTag(KeyByIDAPIPath, keyByIDH))
t.Handle(KeysAPIPath,
intromw.InstrumentedHandler(KeysAPIPath, t.traceOpt, KeysHandler(ks)))

t.Handle(KeyByIDAPIPath,
intromw.InstrumentedHandler(KeyByIDAPIPath, t.traceOpt, KeyByIDHandler(ks)))

return nil
}
Expand Down
5 changes: 4 additions & 1 deletion httptransport/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package httptransport

import (
"context"
"net"
"net/http"
"net/http/httptest"
"net/url"
Expand Down Expand Up @@ -51,8 +52,10 @@ func TestUpdateEndpoints(t *testing.T) {
if err := s.configureMatcherMode(ctx); err != nil {
t.Error(err)
}

srv := httptest.NewServer(s)
srv.Config.BaseContext = func(_ net.Listener) context.Context {
return ctx
}
defer srv.Close()
u, err := url.Parse(srv.URL)
if err != nil {
Expand Down

0 comments on commit 84ba35f

Please sign in to comment.