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

NOISSUE - Add traces to API Bootstraps and Certs endpoints #1851

Merged
merged 6 commits into from
Jul 11, 2023
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
21 changes: 11 additions & 10 deletions bootstrap/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
mflog "github.com/mainflux/mainflux/logger"
"github.com/mainflux/mainflux/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/contrib/instrumentation/github.com/go-kit/kit/otelkit"
)

const (
Expand All @@ -41,61 +42,61 @@ func MakeHandler(svc bootstrap.Service, reader bootstrap.ConfigReader, logger mf
r := bone.New()

r.Post("/things/configs", kithttp.NewServer(
addEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("add"))(addEndpoint(svc)),
decodeAddRequest,
encodeResponse,
opts...))

r.Get("/things/configs/:configID", kithttp.NewServer(
viewEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("view"))(viewEndpoint(svc)),
decodeEntityRequest,
encodeResponse,
opts...))

r.Put("/things/configs/:configID", kithttp.NewServer(
updateEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("update"))(updateEndpoint(svc)),
decodeUpdateRequest,
encodeResponse,
opts...))

r.Patch("/things/configs/certs/:certID", kithttp.NewServer(
updateCertEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("update_cert"))(updateCertEndpoint(svc)),
decodeUpdateCertRequest,
encodeResponse,
opts...))

r.Put("/things/configs/connections/:connID", kithttp.NewServer(
updateConnEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("update_connections"))(updateConnEndpoint(svc)),
decodeUpdateConnRequest,
encodeResponse,
opts...))

r.Get("/things/configs", kithttp.NewServer(
listEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("list"))(listEndpoint(svc)),
decodeListRequest,
encodeResponse,
opts...))

r.Get("/things/bootstrap/:externalID", kithttp.NewServer(
bootstrapEndpoint(svc, reader, false),
otelkit.EndpointMiddleware(otelkit.WithOperation("bootstrap"))(bootstrapEndpoint(svc, reader, false)),
decodeBootstrapRequest,
encodeResponse,
opts...))

r.Get("/things/bootstrap/secure/:externalID", kithttp.NewServer(
bootstrapEndpoint(svc, reader, true),
otelkit.EndpointMiddleware(otelkit.WithOperation("bootstrap_secure"))(bootstrapEndpoint(svc, reader, true)),
decodeBootstrapRequest,
encodeSecureRes,
opts...))

r.Put("/things/state/:thingID", kithttp.NewServer(
stateEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("state"))(stateEndpoint(svc)),
decodeStateRequest,
encodeResponse,
opts...))

r.Delete("/things/configs/:configID", kithttp.NewServer(
removeEndpoint(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("remove"))(removeEndpoint(svc)),
decodeEntityRequest,
encodeResponse,
opts...))
Expand Down
9 changes: 5 additions & 4 deletions certs/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/mainflux/mainflux/logger"
"github.com/mainflux/mainflux/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.opentelemetry.io/contrib/instrumentation/github.com/go-kit/kit/otelkit"
)

const (
Expand All @@ -35,28 +36,28 @@ func MakeHandler(svc certs.Service, logger logger.Logger, instanceID string) htt
r := bone.New()

r.Post("/certs", kithttp.NewServer(
issueCert(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("issue"))(issueCert(svc)),
decodeCerts,
encodeResponse,
opts...,
))

r.Get("/certs/:certID", kithttp.NewServer(
viewCert(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("view"))(viewCert(svc)),
decodeViewCert,
encodeResponse,
opts...,
))

r.Delete("/certs/:certID", kithttp.NewServer(
revokeCert(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("revoke"))(revokeCert(svc)),
decodeRevokeCerts,
encodeResponse,
opts...,
))

r.Get("/serials/:thingID", kithttp.NewServer(
listSerials(svc),
otelkit.EndpointMiddleware(otelkit.WithOperation("list_serials"))(listSerials(svc)),
decodeListCerts,
encodeResponse,
opts...,
Expand Down
1 change: 1 addition & 0 deletions cmd/bootstrap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func main() {
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}

hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger, instanceID), logger)

if cfg.SendTelemetry {
Expand Down
11 changes: 11 additions & 0 deletions cmd/certs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
vault "github.com/mainflux/mainflux/certs/pki"
certsPg "github.com/mainflux/mainflux/certs/postgres"
"github.com/mainflux/mainflux/internal"
jaegerClient "github.com/mainflux/mainflux/internal/clients/jaeger"
"github.com/mainflux/mainflux/internal/env"
"github.com/mainflux/mainflux/internal/server"
httpserver "github.com/mainflux/mainflux/internal/server/http"
Expand Down Expand Up @@ -46,6 +47,7 @@ type config struct {
ThingsURL string `env:"MF_THINGS_URL" envDefault:"http://things:9000"`
SendTelemetry bool `env:"MF_SEND_TELEMETRY" envDefault:"true"`
InstanceID string `env:"MF_CERTS_INSTANCE_ID" envDefault:""`
JaegerURL string `env:"MF_JAEGER_URL" envDefault:"http://jaeger:14268/api/traces"`

// Sign and issue certificates without 3rd party PKI
SignCAPath string `env:"MF_CERTS_SIGN_CA_PATH" envDefault:"ca.crt"`
Expand Down Expand Up @@ -112,6 +114,15 @@ func main() {
if err := env.Parse(&httpServerConfig, env.Options{Prefix: envPrefixHttp, AltPrefix: envPrefix}); err != nil {
logger.Fatal(fmt.Sprintf("failed to load %s HTTP server configuration : %s", svcName, err))
}
tp, err := jaegerClient.NewProvider(svcName, cfg.JaegerURL, instanceID)
if err != nil {
logger.Fatal(fmt.Sprintf("failed to init Jaeger: %s", err))
}
defer func() {
if err := tp.Shutdown(ctx); err != nil {
logger.Error(fmt.Sprintf("error shutting down tracer provider: %v", err))
}
}()
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, instanceID), logger)

if cfg.SendTelemetry {
Expand Down