Add aggregate configuration support and update documentation
Publish telemt-api gateway Docker image / test (push) Failing after 27s
Publish telemt-api gateway Docker image / build-and-push (push) Has been skipped

- 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:
Denozordec
2026-03-30 00:51:19 +07:00
parent 89638d29bb
commit 54306ec6c4
12 changed files with 1031 additions and 6 deletions
+7
View File
@@ -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