feat: migrate receiver to Fuego framework with OpenAPI generation
All checks were successful
ci / ci (push) Successful in 2m2s
ci / goreleaser (push) Successful in 2m29s

Replace net/http handlers with Fuego framework for automatic OpenAPI 3.0
spec generation. Add generated Go client package, OpenAPI extraction
script, and update Makefile with separate build/run targets for both
binaries.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Manuel Ganter 2026-02-18 11:12:14 +01:00
parent 479c13f596
commit bc9d0dd8ea
No known key found for this signature in database
11 changed files with 2245 additions and 252 deletions

View file

@ -1,16 +1,17 @@
// ABOUTME: Entry point for the metrics receiver service.
// ABOUTME: HTTP service using Fuego framework with automatic OpenAPI 3.0 generation.
package main
import (
"context"
"flag"
"fmt"
"log/slog"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/getkin/kin-openapi/openapi3"
"github.com/go-fuego/fuego"
"edp.buildth.ing/DevFW-CICD/forgejo-runner-sizer/internal/receiver"
)
@ -39,42 +40,44 @@ func main() {
defer func() { _ = store.Close() }()
handler := receiver.NewHandler(store, logger, *readToken, *hmacKey, *tokenTTL)
mux := http.NewServeMux()
handler.RegisterRoutes(mux)
server := &http.Server{
Addr: *addr,
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
// Create Fuego server with OpenAPI configuration
s := fuego.NewServer(
fuego.WithAddr(*addr),
fuego.WithEngineOptions(
fuego.WithOpenAPIConfig(fuego.OpenAPIConfig{
PrettyFormatJSON: true,
JSONFilePath: "docs/openapi.json",
SwaggerURL: "/swagger",
Info: &openapi3.Info{
Title: "Forgejo Runner Resource Collector API",
Version: "1.0.0",
Description: "HTTP service that receives and stores CI/CD resource metrics from collectors, providing query and sizing recommendation APIs.",
Contact: &openapi3.Contact{
Name: "API Support",
URL: "https://edp.buildth.ing/DevFW-CICD/forgejo-runner-sizer",
},
License: &openapi3.License{
Name: "Apache 2.0",
URL: "http://www.apache.org/licenses/LICENSE-2.0.html",
},
},
}),
),
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigChan
logger.Info("received signal, shutting down", slog.String("signal", sig.String()))
cancel()
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*time.Second)
defer shutdownCancel()
_ = server.Shutdown(shutdownCtx)
}()
// Register routes
handler.RegisterRoutes(s)
logger.Info("starting metrics receiver",
slog.String("addr", *addr),
slog.String("db", *dbPath),
slog.String("swagger", fmt.Sprintf("http://localhost%s/swagger", *addr)),
)
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
// Run server (handles graceful shutdown)
if err := s.Run(); err != nil {
fmt.Fprintf(os.Stderr, "error: %v\n", err)
os.Exit(1)
}
<-ctx.Done()
logger.Info("receiver stopped gracefully")
}