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

feat: replace opentracing with opentelemetry #1053

Merged
merged 6 commits into from
Oct 4, 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
39 changes: 39 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
ARG GO_VERSION=1.18

FROM golang:${GO_VERSION}

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && \
apt-get -y install --no-install-recommends \
curl \
gnupg \
silversearcher-ag \
sudo \
openssh-server \
postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# install nodejs
RUN curl -sSL https://deb.nodesource.com/setup_18.x | bash && \
apt-get update && \
apt-get install -y --no-install-recommends \
nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# install task
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin

WORKDIR /flipt

COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

COPY . .

EXPOSE 8080
EXPOSE 8081
EXPOSE 9000
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Flipt",
"build": {
"context": "..",
"dockerfile": "../Dockerfile"
"dockerfile": "Dockerfile"
},
// Set *default* container specific settings.json values on container create.
"settings": {
Expand Down
77 changes: 43 additions & 34 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,48 @@
ARG GO_VERSION=1.18

FROM golang:${GO_VERSION}

SHELL ["/bin/bash", "-o", "pipefail", "-c"]

RUN apt-get update && \
apt-get -y install --no-install-recommends \
curl \
gnupg \
silversearcher-ag \
sudo \
openssh-server \
postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# install nodejs
RUN curl -sSL https://deb.nodesource.com/setup_18.x | bash && \
apt-get update && \
apt-get install -y --no-install-recommends \
nodejs && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# install task
RUN sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b /usr/local/bin

WORKDIR /flipt

COPY go.mod go.mod
COPY go.sum go.sum
# https://goreleaser.com/docker/

FROM golang:1.18-alpine3.16 AS build

WORKDIR /home/flipt

RUN apk add npm git bash gcc build-base binutils-gold

RUN npm install -g @go-task/cli

COPY go.mod .
COPY go.sum .

RUN go mod download

COPY . .
COPY . /home/flipt

ENV CGO_ENABLED=1

RUN task

FROM alpine:3.16.2

LABEL maintainer="[email protected]"
LABEL org.opencontainers.image.name="flipt"
LABEL org.opencontainers.image.source="https://github.com/flipt-io/flipt"

RUN apk add --no-cache postgresql-client \
openssl \
ca-certificates

RUN mkdir -p /etc/flipt && \
mkdir -p /var/opt/flipt

COPY --from=build /home/flipt/bin/flipt /
COPY config/migrations/ /etc/flipt/config/migrations/
COPY config/*.yml /etc/flipt/config/

RUN addgroup flipt && \
adduser -S -D -g '' -G flipt -s /bin/sh flipt && \
chown -R flipt:flipt /etc/flipt /var/opt/flipt

EXPOSE 8080
EXPOSE 8081
EXPOSE 9000

USER flipt

CMD ["./flipt"]
53 changes: 27 additions & 26 deletions cmd/flipt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"crypto/tls"
"errors"
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
Expand All @@ -16,6 +15,7 @@ import (
"os/signal"
"path/filepath"
"runtime"
"strconv"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -46,6 +46,13 @@ import (
"go.flipt.io/flipt/storage/sql/sqlite"
"go.flipt.io/flipt/swagger"
"go.flipt.io/flipt/ui"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/jaeger"
"go.opentelemetry.io/otel/sdk/resource"
tracesdk "go.opentelemetry.io/otel/sdk/trace"
semconv "go.opentelemetry.io/otel/semconv/v1.4.0"
"go.opentelemetry.io/otel/trace"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/sync/errgroup"
Expand All @@ -67,10 +74,6 @@ import (

goredis_cache "github.com/go-redis/cache/v8"
goredis "github.com/go-redis/redis/v8"
otgrpc "github.com/opentracing-contrib/go-grpc"
"github.com/opentracing/opentracing-go"
jaeger_config "github.com/uber/jaeger-client-go/config"
jaeger_zap "github.com/uber/jaeger-client-go/log/zap"
)

const devVersion = "dev"
Expand Down Expand Up @@ -433,33 +436,31 @@ func run(ctx context.Context, logger *zap.Logger) error {

logger.Debug("store enabled", zap.Stringer("driver", store))

var tracer opentracing.Tracer = &opentracing.NoopTracer{}
var tracingProvider = trace.NewNoopTracerProvider()

if cfg.Tracing.Jaeger.Enabled {
jaegerCfg := jaeger_config.Configuration{
ServiceName: "flipt",
Sampler: &jaeger_config.SamplerConfig{
Type: "const",
Param: 1,
},
Reporter: &jaeger_config.ReporterConfig{
LocalAgentHostPort: fmt.Sprintf("%s:%d", cfg.Tracing.Jaeger.Host, cfg.Tracing.Jaeger.Port),
LogSpans: true,
BufferFlushInterval: 1 * time.Second,
},
}

var closer io.Closer

tracer, closer, err = jaegerCfg.NewTracer(jaeger_config.Logger(jaeger_zap.NewLogger(logger)))
exp, err := jaeger.New(jaeger.WithAgentEndpoint(
jaeger.WithAgentHost(cfg.Tracing.Jaeger.Host),
jaeger.WithAgentPort(strconv.FormatInt(int64(cfg.Tracing.Jaeger.Port), 10)),
))
if err != nil {
return fmt.Errorf("configuring tracing: %w", err)
return err
}

defer closer.Close()
tracingProvider = tracesdk.NewTracerProvider(
tracesdk.WithBatcher(
exp,
tracesdk.WithBatchTimeout(1*time.Second),
),
tracesdk.WithResource(resource.NewWithAttributes(
semconv.SchemaURL,
semconv.ServiceNameKey.String("flipt"),
)),
tracesdk.WithSampler(tracesdk.AlwaysSample()),
)
}

opentracing.SetGlobalTracer(tracer)
otel.SetTracerProvider(tracingProvider)

{
// forward internal gRPC logging to zap
Expand All @@ -476,7 +477,7 @@ func run(ctx context.Context, logger *zap.Logger) error {
grpc_ctxtags.UnaryServerInterceptor(),
grpc_zap.UnaryServerInterceptor(logger),
grpc_prometheus.UnaryServerInterceptor,
otgrpc.OpenTracingServerInterceptor(tracer),
otelgrpc.UnaryServerInterceptor(),
server.ErrorUnaryInterceptor,
server.ValidationUnaryInterceptor,
server.EvaluationUnaryInterceptor,
Expand Down
12 changes: 10 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ require (
github.com/luna-duclos/instrumentedsql v1.1.3
github.com/luna-duclos/instrumentedsql/opentracing v0.0.0-20200611091901-487c5ec83473
github.com/mattn/go-sqlite3 v1.14.15
github.com/opentracing-contrib/go-grpc v0.0.0-20210225150812-73cb765af46e
github.com/opentracing/opentracing-go v1.2.0
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/phyber/negroni-gzip v1.0.0
github.com/prometheus/client_golang v1.13.0
Expand All @@ -35,6 +33,11 @@ require (
github.com/uber/jaeger-client-go v2.30.0+incompatible
github.com/xo/dburl v0.0.0-20200124232849-e9ec94f52bc3
go.flipt.io/flipt-grpc v1.0.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.28.0
go.opentelemetry.io/otel v1.10.0
go.opentelemetry.io/otel/exporters/jaeger v1.10.0
go.opentelemetry.io/otel/sdk v1.10.0
go.opentelemetry.io/otel/trace v1.10.0
go.uber.org/zap v1.23.0
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f
google.golang.org/grpc v1.49.0
Expand All @@ -47,6 +50,7 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Microsoft/hcsshim v0.9.4 // indirect
github.com/XSAM/otelsql v0.16.0 // indirect
github.com/benbjohnson/clock v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
Expand All @@ -59,6 +63,8 @@ require (
github.com/docker/docker v20.10.17+incompatible // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
Expand All @@ -81,6 +87,7 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
github.com/opencontainers/runc v1.1.3 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand All @@ -103,6 +110,7 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/xtgo/uuid v0.0.0-20140804021211-a0b114877d4c // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/otel/metric v0.31.0 // indirect
go.uber.org/atomic v1.7.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4 // indirect
Expand Down
Loading