Skip to content
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
7 changes: 7 additions & 0 deletions .github/workflows/ko-build-branch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ jobs:
container_tag=$(echo "$HEAD_REF" | sed 's/[^_0-9a-zA-Z]/-/g' | cut -c -127)
echo tag="$container_tag" >> "$GITHUB_OUTPUT"
- name: Build mailing-list-api for PR
env:
VERSION: ${{ steps.container_tag.outputs.tag }}
GIT_COMMIT: ${{ github.sha }}
run: |
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
export BUILD_TIME
GIT_COMMIT=${GIT_COMMIT:0:7}
export GIT_COMMIT
ko build github.com/linuxfoundation/lfx-v2-mailing-list-service/cmd/mailing-list-api \
-B \
--platform linux/amd64,linux/arm64 \
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/ko-build-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ jobs:
- uses: ko-build/setup-ko@v0.8
with:
version: v0.17.1
- run: |
- name: Build and publish mailing-list-api image
env:
VERSION: development
GIT_COMMIT: ${{ github.sha }}
run: |
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
export BUILD_TIME
GIT_COMMIT=${GIT_COMMIT:0:7}
export GIT_COMMIT
ko build github.com/linuxfoundation/lfx-v2-mailing-list-service/cmd/mailing-list-api \
-B \
--platform linux/amd64,linux/arm64 \
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ko-build-tag.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ jobs:
version: v0.17.1

- name: Build and publish mailing-list-api image
env:
VERSION: ${{ steps.prepare.outputs.app_version }}
GIT_COMMIT: ${{ github.sha }}
run: |
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
export BUILD_TIME
GIT_COMMIT=${GIT_COMMIT:0:7}
export GIT_COMMIT
ko build github.com/linuxfoundation/lfx-v2-mailing-list-service/cmd/mailing-list-api \
-B \
--platform linux/amd64,linux/arm64 \
Expand Down
9 changes: 9 additions & 0 deletions .ko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright The Linux Foundation and each contributor to LFX.
# SPDX-License-Identifier: MIT
builds:
- id: mailing-list-api
dir: ./cmd/mailing-list-api
ldflags:
- -X=main.Version={{.Env.VERSION}}
- -X=main.BuildTime={{.Env.BUILD_TIME}}
- -X=main.GitCommit={{.Env.GIT_COMMIT}}
50 changes: 50 additions & 0 deletions charts/lfx-v2-mailing-list-service/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,56 @@ spec:
{{- toYaml $config.valueFrom | nindent 16 }}
{{- end }}
{{- end }}
{{- $otelServiceName := .Values.app.otel.serviceName | toString | trim }}
{{- if ne $otelServiceName "" }}
- name: OTEL_SERVICE_NAME
value: {{ $otelServiceName | quote }}
{{- end }}
{{- $otelServiceVersion := .Values.app.otel.serviceVersion | toString | trim }}
{{- if ne $otelServiceVersion "" }}
- name: OTEL_SERVICE_VERSION
value: {{ $otelServiceVersion | quote }}
{{- end }}
{{- $otelEndpoint := .Values.app.otel.endpoint | toString | trim }}
{{- if ne $otelEndpoint "" }}
- name: OTEL_EXPORTER_OTLP_ENDPOINT
value: {{ $otelEndpoint | quote }}
{{- end }}
{{- $otelProtocol := .Values.app.otel.protocol | toString | trim }}
{{- if ne $otelProtocol "" }}
- name: OTEL_EXPORTER_OTLP_PROTOCOL
value: {{ $otelProtocol | quote }}
{{- end }}
{{- $otelInsecure := .Values.app.otel.insecure | toString | trim }}
{{- if ne $otelInsecure "" }}
- name: OTEL_EXPORTER_OTLP_INSECURE
value: {{ $otelInsecure | quote }}
{{- end }}
{{- $otelTracesExporter := .Values.app.otel.tracesExporter | toString | trim }}
{{- if ne $otelTracesExporter "" }}
- name: OTEL_TRACES_EXPORTER
value: {{ $otelTracesExporter | quote }}
{{- end }}
{{- $otelTracesSampleRatio := .Values.app.otel.tracesSampleRatio | toString | trim }}
{{- if ne $otelTracesSampleRatio "" }}
- name: OTEL_TRACES_SAMPLE_RATIO
value: {{ $otelTracesSampleRatio | quote }}
{{- end }}
{{- $otelMetricsExporter := .Values.app.otel.metricsExporter | toString | trim }}
{{- if ne $otelMetricsExporter "" }}
- name: OTEL_METRICS_EXPORTER
value: {{ $otelMetricsExporter | quote }}
{{- end }}
{{- $otelLogsExporter := .Values.app.otel.logsExporter | toString | trim }}
{{- if ne $otelLogsExporter "" }}
- name: OTEL_LOGS_EXPORTER
value: {{ $otelLogsExporter | quote }}
{{- end }}
{{- $otelPropagators := .Values.app.otel.propagators | toString | trim }}
{{- if ne $otelPropagators "" }}
- name: OTEL_PROPAGATORS
value: {{ $otelPropagators | quote }}
{{- end }}
{{- if .Values.externalSecretsOperator.enabled }}
envFrom:
- secretRef:
Expand Down
35 changes: 35 additions & 0 deletions charts/lfx-v2-mailing-list-service/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,41 @@ app:
# use_oidc_contextualizer is a boolean to determine if the OIDC contextualizer should be used
use_oidc_contextualizer: true

# otel is the configuration for OpenTelemetry tracing
otel:
# serviceName is the service name for OpenTelemetry resource identification
# (default: "lfx-v2-mailing-list-service")
serviceName: ""
# serviceVersion is the service version for OpenTelemetry resource identification
# (default: build-time version from ldflags)
serviceVersion: ""
# protocol specifies the OTLP protocol: "grpc" or "http"
# (default: "grpc")
protocol: "grpc"
# endpoint is the OTLP collector endpoint
# For gRPC: typically "host:4317", for HTTP: typically "host:4318"
endpoint: ""
# insecure disables TLS for the OTLP connection
# Set to "true" for in-cluster communication without TLS
insecure: "false"
# tracesExporter specifies the traces exporter: "otlp" or "none"
# (default: "none")
tracesExporter: "none"
# tracesSampleRatio specifies the sampling ratio for traces (0.0 to 1.0)
# A value of 1.0 means all traces are sampled, 0.5 means 50% are sampled
# (default: "1.0")
tracesSampleRatio: "1.0"
# metricsExporter specifies the metrics exporter: "otlp" or "none"
# (default: "none")
metricsExporter: "none"
# logsExporter specifies the logs exporter: "otlp" or "none"
# (default: "none")
logsExporter: "none"
# propagators specifies the propagators to use, comma-separated
# Supported values: "tracecontext", "baggage", "jaeger"
# (default: "tracecontext,baggage,jaeger")
propagators: "tracecontext,baggage,jaeger"

# environment contains all application environment variables
# Each variable can have either a 'value' (for direct values) or 'valueFrom' (for secret references)
environment:
Expand Down
3 changes: 3 additions & 0 deletions cmd/mailing-list-api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
mailinglistservice "github.com/linuxfoundation/lfx-v2-mailing-list-service/gen/mailing_list"
"github.com/linuxfoundation/lfx-v2-mailing-list-service/internal/middleware"

"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"goa.design/clue/debug"
goahttp "goa.design/goa/v3/http"
)
Expand Down Expand Up @@ -71,6 +72,8 @@ func handleHTTPServer(ctx context.Context, host string, mailingListServiceEndpoi
// Log query and response bodies if debug logs are enabled.
handler = debug.HTTP()(handler)
}
// Add OpenTelemetry HTTP instrumentation (outermost to capture full request lifecycle)
handler = otelhttp.NewHandler(handler, "mailing-list-api")

// Start HTTP server using default configuration, change the code to
// configure the server as required by your service.
Expand Down
35 changes: 34 additions & 1 deletion cmd/mailing-list-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ import (
"github.com/linuxfoundation/lfx-v2-mailing-list-service/cmd/mailing-list-api/service"
mailinglistservice "github.com/linuxfoundation/lfx-v2-mailing-list-service/gen/mailing_list"
logging "github.com/linuxfoundation/lfx-v2-mailing-list-service/pkg/log"
"github.com/linuxfoundation/lfx-v2-mailing-list-service/pkg/utils"

"goa.design/clue/debug"
)

// Build-time variables set via ldflags
var (
Version = "dev"
BuildTime = "unknown"
GitCommit = "unknown"
)

const (
defaultPort = "8080"
// gracefulShutdownSeconds should be higher than NATS client
Expand Down Expand Up @@ -49,10 +57,35 @@ func main() {
flag.Parse()

ctx := context.Background()
slog.InfoContext(ctx, "Starting query service",

// Set up OpenTelemetry SDK.
// Command-line/environment OTEL_SERVICE_VERSION takes precedence over
// the build-time Version variable.
otelConfig := utils.OTelConfigFromEnv()
if otelConfig.ServiceVersion == "" {
otelConfig.ServiceVersion = Version
}
otelShutdown, err := utils.SetupOTelSDKWithConfig(ctx, otelConfig)
if err != nil {
slog.ErrorContext(ctx, "error setting up OpenTelemetry SDK", "error", err)
os.Exit(1)
}
// Handle shutdown properly so nothing leaks.
defer func() {
shutdownCtx, cancel := context.WithTimeout(context.Background(), gracefulShutdownSeconds*time.Second)
defer cancel()
if shutdownErr := otelShutdown(shutdownCtx); shutdownErr != nil {
slog.ErrorContext(ctx, "error shutting down OpenTelemetry SDK", "error", shutdownErr)
}
}()

slog.InfoContext(ctx, "Starting mailing list service",
"bind", *bind,
"http-port", *port,
"graceful-shutdown-seconds", gracefulShutdownSeconds,
"version", Version,
"build-time", BuildTime,
"git-commit", GitCommit,
)

// Validate provider configuration before initializing dependencies
Expand Down
55 changes: 38 additions & 17 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,61 @@ require (
github.com/google/go-querystring v1.1.0
github.com/google/uuid v1.6.0
github.com/nats-io/nats.go v1.31.0
github.com/stretchr/testify v1.10.0
github.com/remychantenay/slog-otel v1.3.4
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.65.0
go.opentelemetry.io/contrib/propagators/jaeger v1.40.0
go.opentelemetry.io/otel v1.40.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.15.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.15.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.40.0
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.40.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.40.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.40.0
go.opentelemetry.io/otel/log v0.15.0
go.opentelemetry.io/otel/sdk v1.40.0
go.opentelemetry.io/otel/sdk/log v0.15.0
go.opentelemetry.io/otel/sdk/metric v1.40.0
goa.design/clue v1.2.2
goa.design/goa/v3 v3.21.5
golang.org/x/sync v0.16.0
golang.org/x/text v0.27.0
golang.org/x/sync v0.19.0
golang.org/x/text v0.33.0
)

require (
github.com/aws/smithy-go v1.22.5 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-chi/chi/v5 v5.2.2 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gohugoio/hashstructure v0.5.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.7 // indirect
github.com/klauspost/compress v1.17.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/manveru/faker v0.0.0-20171103152722-9fbc68a78c4d // indirect
github.com/nats-io/nkeys v0.4.5 // indirect
github.com/nats-io/nkeys v0.4.15 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
go.opentelemetry.io/otel v1.37.0 // indirect
go.opentelemetry.io/otel/trace v1.37.0 // indirect
golang.org/x/crypto v0.40.0 // indirect
golang.org/x/mod v0.26.0 // indirect
golang.org/x/net v0.42.0 // indirect
golang.org/x/sys v0.34.0 // indirect
golang.org/x/term v0.33.0 // indirect
golang.org/x/tools v0.35.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250721164621-a45f3dfb1074 // indirect
google.golang.org/grpc v1.74.2 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.40.0 // indirect
go.opentelemetry.io/otel/metric v1.40.0 // indirect
go.opentelemetry.io/otel/trace v1.40.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/mod v0.31.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/tools v0.40.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260128011058-8636f8732409 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260128011058-8636f8732409 // indirect
google.golang.org/grpc v1.78.0 // indirect
google.golang.org/protobuf v1.36.11 // indirect
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading