Skip to content

Commit 73f2450

Browse files
committed
deduped metrics registration
1 parent 23573c9 commit 73f2450

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

gateway/route_metric.go

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package gateway
22

33
import (
44
"context"
5+
"fmt"
56
"github.com/viant/datly/repository/contract"
67
"github.com/viant/gmetric"
78
"net/http"
@@ -17,6 +18,7 @@ func (r *Router) NewMetricRoute(URI string) *Route {
1718
pathURI += "*"
1819
}
1920
return &Route{
21+
2022
Path: contract.NewPath(http.MethodGet, pathURI),
2123
Handler: func(ctx context.Context, response http.ResponseWriter, req *http.Request) {
2224
r.handleMetrics(response, req, URI)

gateway/router.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ func (r *Router) newMatcher(ctx context.Context) (*matcher.Matcher, []*contract.
313313
paths := make([]*contract.Path, 0, len(routes))
314314
container := r.repository.Container()
315315

316+
unique := map[string]bool{}
316317
var openAPIs = map[string][]*repository.Provider{}
317318
var optionsPaths = map[string][]*path.Path{}
318319
for _, anItem := range container.Items {
@@ -340,14 +341,16 @@ func (r *Router) newMatcher(ctx context.Context) (*matcher.Matcher, []*contract.
340341
optionsPaths[aPath.URI] = append(optionsPaths[aPath.URI], aPath)
341342
}
342343
routes = append(routes, r.NewViewMetaHandler(r.routeURL(r.config.Meta.ViewURI, aPath.URI), provider))
343-
344344
key := r.routeURL(r.config.Meta.OpenApiURI, aPath.URI)
345345
openAPIs[key] = append(openAPIs[key], provider)
346-
// //routes = append(routes, r.NewOpenAPIRoute(r.routeURL(r.config.Meta.OpenApiURI, aPath.URI), r.repository, provider))
347346

348-
routes = append(routes, r.NewStructRoute(r.routeURL(r.config.Meta.StructURI, aPath.URI), provider))
349-
routes = append(routes, r.NewStateRoute(r.routeURL(r.config.Meta.StateURI, aPath.URI), provider))
350-
routes = append(routes, r.NewMetricRoute(r.metricURL(r.config.Meta.MetricURI, aPath.URI)))
347+
if !unique[aPath.URI] {
348+
unique[aPath.URI] = true
349+
// //routes = append(routes, r.NewOpenAPIRoute(r.routeURL(r.config.Meta.OpenApiURI, aPath.URI), r.repository, provider))
350+
routes = append(routes, r.NewStructRoute(r.routeURL(r.config.Meta.StructURI, aPath.URI), provider))
351+
routes = append(routes, r.NewStateRoute(r.routeURL(r.config.Meta.StateURI, aPath.URI), provider))
352+
routes = append(routes, r.NewMetricRoute(r.metricURL(r.config.Meta.MetricURI, aPath.URI)))
353+
}
351354

352355
//TODO extend path.Path with cache info to pre exract cacheable view
353356
//if views := router.ExtractCacheableViews(route); len(views) > 0 {

internal/plugin/info.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ const (
3535

3636
type (
3737
Info struct {
38-
fs afs.Service
39-
38+
fs afs.Service
4039
URL string
4140
Mod *modfile.File
4241
ModLocation string

0 commit comments

Comments
 (0)