mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: stats view/distribution improvements (#1154)
* fn: stats view/distribution improvements *) View latency distribution is now an argument in view creation functions. This allows easier override to set custom buckets. It is simplistic and assumes all latency views would use the same set, but in practice this is already the case. *) Removed API view creation to main, this should not be enabled for all node types. This is consistent with the rest of the system. * fn: Docker samples of cpu/mem/disk with specific buckets
This commit is contained in:
@@ -79,6 +79,19 @@ func traceWrap(c *gin.Context) {
|
||||
}
|
||||
|
||||
func apiMetricsWrap(s *Server) {
|
||||
pathKey, err := tag.NewKey("path")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
methodKey, err := tag.NewKey("method")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
statusKey, err := tag.NewKey("status")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
measure := func(engine *gin.Engine) func(*gin.Context) {
|
||||
var routes gin.RoutesInfo
|
||||
return func(c *gin.Context) {
|
||||
@@ -102,7 +115,7 @@ func apiMetricsWrap(s *Server) {
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
stats.Record(ctx, apiRequestCount.M(1))
|
||||
stats.Record(ctx, apiRequestCountMeasure.M(1))
|
||||
c.Next()
|
||||
|
||||
status := strconv.Itoa(c.Writer.Status())
|
||||
@@ -112,7 +125,7 @@ func apiMetricsWrap(s *Server) {
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
stats.Record(ctx, apiLatency.M(float64(time.Since(start))/float64(time.Millisecond)))
|
||||
stats.Record(ctx, apiLatencyMeasure.M(int64(time.Since(start)/time.Millisecond)))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -600,10 +600,6 @@ func WithAgentFromEnv() Option {
|
||||
placer = pool.NewNaivePlacer(&placerCfg)
|
||||
}
|
||||
|
||||
keys := []string{"fn_appname", "fn_path"}
|
||||
pool.RegisterPlacerViews(keys)
|
||||
agent.RegisterLBAgentViews(keys)
|
||||
|
||||
s.lbReadAccess = agent.NewCachedDataAccess(cl)
|
||||
s.agent, err = agent.NewLBAgent(cl, runnerPool, placer)
|
||||
if err != nil {
|
||||
@@ -758,7 +754,7 @@ func WithPrometheus() Option {
|
||||
}
|
||||
s.promExporter = exporter
|
||||
view.RegisterExporter(exporter)
|
||||
registerViews()
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,68 +1,26 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"github.com/fnproject/fn/api/common"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"go.opencensus.io/stats"
|
||||
"go.opencensus.io/stats/view"
|
||||
"go.opencensus.io/tag"
|
||||
)
|
||||
|
||||
var (
|
||||
apiRequestCount = stats.Int64("api/request_count", "Number of API requests", stats.UnitDimensionless)
|
||||
apiLatency = stats.Float64("api/latency", "API latency", stats.UnitMilliseconds)
|
||||
apiRequestCountMeasure = common.MakeMeasure("api/request_count", "Count of API requests started", stats.UnitDimensionless)
|
||||
apiResponseCountMeasure = common.MakeMeasure("api/response_count", "API response count", stats.UnitDimensionless)
|
||||
apiLatencyMeasure = common.MakeMeasure("api/latency", "Latency distribution of API requests", stats.UnitMilliseconds)
|
||||
)
|
||||
|
||||
var (
|
||||
pathKey = makeKey("path")
|
||||
methodKey = makeKey("method")
|
||||
statusKey = makeKey("status")
|
||||
)
|
||||
|
||||
var (
|
||||
defaultLatencyDistribution = view.Distribution(0, 1, 2, 3, 4, 5, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 130, 160, 200, 250, 300, 400, 500, 650, 800, 1000, 2000, 5000, 10000, 20000, 50000, 100000)
|
||||
)
|
||||
|
||||
var (
|
||||
apiRequestCountView = &view.View{
|
||||
Name: "api/request_count",
|
||||
Description: "Count of API requests started",
|
||||
Measure: apiRequestCount,
|
||||
TagKeys: []tag.Key{pathKey, methodKey},
|
||||
Aggregation: view.Count(),
|
||||
}
|
||||
|
||||
apiResponseCountView = &view.View{
|
||||
Name: "api/response_count",
|
||||
Description: "API response count",
|
||||
TagKeys: []tag.Key{pathKey, methodKey, statusKey},
|
||||
Measure: apiLatency,
|
||||
Aggregation: view.Count(),
|
||||
}
|
||||
|
||||
apiLatencyView = &view.View{
|
||||
Name: "api/latency",
|
||||
Description: "Latency distribution of API requests",
|
||||
Measure: apiLatency,
|
||||
TagKeys: []tag.Key{pathKey, methodKey, statusKey},
|
||||
Aggregation: defaultLatencyDistribution,
|
||||
}
|
||||
)
|
||||
|
||||
func registerViews() {
|
||||
func RegisterAPIViews(tagKeys []string, dist []float64) {
|
||||
err := view.Register(
|
||||
apiRequestCountView,
|
||||
apiResponseCountView,
|
||||
apiLatencyView,
|
||||
common.CreateView(apiRequestCountMeasure, view.Count(), tagKeys),
|
||||
common.CreateView(apiResponseCountMeasure, view.Count(), tagKeys),
|
||||
common.CreateView(apiLatencyMeasure, view.Distribution(dist...), tagKeys),
|
||||
)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Fatal("cannot register view")
|
||||
}
|
||||
}
|
||||
|
||||
func makeKey(name string) tag.Key {
|
||||
key, err := tag.NewKey(name)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
return key
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user