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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ require (
github.com/prometheus/client_golang v1.23.2
github.com/rabbitmq/amqp091-go v1.11.0
github.com/stretchr/testify v1.11.1
go.opentelemetry.io/contrib/bridges/otelslog v0.14.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0
go.opentelemetry.io/contrib/bridges/otelslog v0.18.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.68.0
go.opentelemetry.io/otel v1.43.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.19.0
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.19.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
go.opentelemetry.io/contrib/bridges/otelslog v0.14.0 h1:eypSOd+0txRKCXPNyqLPsbSfA0jULgJcGmSAdFAnrCM=
go.opentelemetry.io/contrib/bridges/otelslog v0.14.0/go.mod h1:CRGvIBL/aAxpQU34ZxyQVFlovVcp67s4cAmQu8Jh9mc=
go.opentelemetry.io/contrib/bridges/otelslog v0.18.0 h1:hhPGP3zvvy1xWT9RTy970wlniSxFttBIsAK1gvMguJM=
go.opentelemetry.io/contrib/bridges/otelslog v0.18.0/go.mod h1:twJF7inoMza6kxMcF8JOdL3mPmtOZu7GEr34CUNE6Dg=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 h1:ssfIgGNANqpVFCndZvcuyKbl0g+UAVcbBcqGkG28H0Y=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0/go.mod h1:GQ/474YrbE4Jx8gZ4q5I4hrhUzM6UPzyrqJYV2AqPoQ=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.68.0 h1:CqXxU8VOmDefoh0+ztfGaymYbhdB/tT3zs79QaZTNGY=
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.68.0/go.mod h1:BuhAPThV8PBHBvg8ZzZ/Ok3idOdhWIodywz2xEcRbJo=
go.opentelemetry.io/otel v1.42.0 h1:lSQGzTgVR3+sgJDAU/7/ZMjN9Z+vUip7leaqBKy4sho=
go.opentelemetry.io/otel v1.42.0/go.mod h1:lJNsdRMxCUIWuMlVJWzecSMuNjE7dOYyWlqOXWkdqCc=
go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I=
Expand Down
37 changes: 24 additions & 13 deletions internal/planner/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/canonical/github-runner-operators/internal/database"
"github.com/canonical/github-runner-operators/internal/server"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel/attribute"
)

const (
Expand Down Expand Up @@ -83,19 +84,19 @@ func NewServer(store FlavorStore, auth AuthStore, metrics *Metrics, adminToken s

// Register routes
// General endpoints require either a valid general token or the admin token
s.mux.Handle("GET "+flavorsPattern, otelhttp.WithRouteTag(flavorsPattern, s.adminProtected(http.HandlerFunc(s.listFlavors))))
s.mux.Handle("POST "+flavorPattern, otelhttp.WithRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.createFlavor))))
s.mux.Handle("GET "+flavorPattern, otelhttp.WithRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.getFlavor))))
s.mux.Handle("PATCH "+flavorPattern, otelhttp.WithRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.updateFlavor))))
s.mux.Handle("DELETE "+flavorPattern, otelhttp.WithRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.deleteFlavor))))
s.mux.Handle("GET "+getFlavorPressurePattern, otelhttp.WithRouteTag(getFlavorPressurePattern, s.tokenProtected(http.HandlerFunc(s.getFlavorPressure))))
s.mux.Handle("POST "+createAuthTokenPattern, otelhttp.WithRouteTag(createAuthTokenPattern, s.adminProtected(http.HandlerFunc(s.createAuthToken))))
s.mux.Handle("GET "+authTokenBasePattern, otelhttp.WithRouteTag(authTokenBasePattern, s.adminProtected(http.HandlerFunc(s.listAuthTokens))))
s.mux.Handle("DELETE "+deleteAuthTokenPattern, otelhttp.WithRouteTag(deleteAuthTokenPattern, s.adminProtected(http.HandlerFunc(s.deleteAuthToken))))
s.mux.Handle("GET "+jobsPattern, otelhttp.WithRouteTag(jobsPattern, s.tokenProtected(http.HandlerFunc(s.listJobs))))
s.mux.Handle("GET "+jobPattern, otelhttp.WithRouteTag(jobPattern, s.tokenProtected(http.HandlerFunc(s.getJob))))
s.mux.Handle("PATCH "+jobPattern, otelhttp.WithRouteTag(jobPattern, s.tokenProtected(http.HandlerFunc(s.updateJob))))
s.mux.Handle("GET "+healthPattern, otelhttp.WithRouteTag(healthPattern, http.HandlerFunc(s.health)))
s.mux.Handle("GET "+flavorsPattern, withRouteTag(flavorsPattern, s.adminProtected(http.HandlerFunc(s.listFlavors))))
s.mux.Handle("POST "+flavorPattern, withRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.createFlavor))))
s.mux.Handle("GET "+flavorPattern, withRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.getFlavor))))
s.mux.Handle("PATCH "+flavorPattern, withRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.updateFlavor))))
s.mux.Handle("DELETE "+flavorPattern, withRouteTag(flavorPattern, s.tokenProtected(http.HandlerFunc(s.deleteFlavor))))
s.mux.Handle("GET "+getFlavorPressurePattern, withRouteTag(getFlavorPressurePattern, s.tokenProtected(http.HandlerFunc(s.getFlavorPressure))))
s.mux.Handle("POST "+createAuthTokenPattern, withRouteTag(createAuthTokenPattern, s.adminProtected(http.HandlerFunc(s.createAuthToken))))
s.mux.Handle("GET "+authTokenBasePattern, withRouteTag(authTokenBasePattern, s.adminProtected(http.HandlerFunc(s.listAuthTokens))))
s.mux.Handle("DELETE "+deleteAuthTokenPattern, withRouteTag(deleteAuthTokenPattern, s.adminProtected(http.HandlerFunc(s.deleteAuthToken))))
s.mux.Handle("GET "+jobsPattern, withRouteTag(jobsPattern, s.tokenProtected(http.HandlerFunc(s.listJobs))))
s.mux.Handle("GET "+jobPattern, withRouteTag(jobPattern, s.tokenProtected(http.HandlerFunc(s.getJob))))
s.mux.Handle("PATCH "+jobPattern, withRouteTag(jobPattern, s.tokenProtected(http.HandlerFunc(s.updateJob))))
s.mux.Handle("GET "+healthPattern, withRouteTag(healthPattern, http.HandlerFunc(s.health)))
s.handler = server.LoggingHandler(logger, s.mux)

return s
Expand Down Expand Up @@ -572,6 +573,16 @@ func flushJSONToStream(w http.ResponseWriter, flusher http.Flusher, payload any)
return nil
}

// withRouteTag annotates the current OTel span with the http.route attribute.
// otelhttp.WithRouteTag was removed in otelhttp v0.65.0; use LabelerFromContext instead.
func withRouteTag(route string, h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
labeler, _ := otelhttp.LabelerFromContext(r.Context())
labeler.Add(attribute.String("http.route", route))
h.ServeHTTP(w, r)
})
}

func decodeFlavorInRequestBody(r *http.Request) (*flavorRequest, error) {
decoder := json.NewDecoder(r.Body)
defer r.Body.Close()
Expand Down
Loading