Add aggregate configuration support and update documentation
- Introduced AggregateConfig to manage aggregation settings in the gateway configuration. - Added validation for reserved alias 'agg' and included tests for aggregate alias handling. - Updated config.example.yaml to demonstrate aggregate configuration options. - Enhanced README.md to include information about the new aggregation endpoint and its usage. - Modified gateway.go to integrate the new aggregate handler for processing aggregation requests.
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
|
||||
"github.com/telemt/telemt-api/internal/aggregate"
|
||||
"github.com/telemt/telemt-api/internal/config"
|
||||
"github.com/telemt/telemt-api/internal/proxy"
|
||||
)
|
||||
@@ -21,6 +22,7 @@ import (
|
||||
type Gateway struct {
|
||||
parsed *config.Parsed
|
||||
proxies map[string]*httputil.ReverseProxy
|
||||
agg *aggregate.Handler
|
||||
log *slog.Logger
|
||||
transport *http.Transport
|
||||
promHandler http.Handler
|
||||
@@ -63,6 +65,7 @@ func NewGateway(p *config.Parsed, log *slog.Logger) (*Gateway, error) {
|
||||
}
|
||||
g.proxies[s.Alias] = rp
|
||||
}
|
||||
g.agg = aggregate.NewHandler(p, &http.Client{Transport: t})
|
||||
return g, nil
|
||||
}
|
||||
|
||||
@@ -170,6 +173,10 @@ func (g *Gateway) serve(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
const prefix = "/api/"
|
||||
if r.URL.Path == "/api/agg" || strings.HasPrefix(r.URL.Path, "/api/agg/") {
|
||||
g.agg.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
if !strings.HasPrefix(r.URL.Path, prefix) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user