mirror of
https://github.com/openfaas/faas.git
synced 2025-06-22 14:53:25 +00:00
Record metrics for invocations when they start
* This experimental patch records metrics as invocations start so that the metrics can be used to make better scale to zero decisions in faas-idler. Tested with Kubernetes on a single-node cluster, metrics reported as expected. Existing metrics still report. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
This commit is contained in:
committed by
Alex Ellis
parent
1eea381dd5
commit
96812d2cd8
@ -41,6 +41,7 @@ func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
|
||||
e.metricOptions.GatewayFunctionInvocation.Describe(ch)
|
||||
e.metricOptions.GatewayFunctionsHistogram.Describe(ch)
|
||||
e.metricOptions.ServiceReplicasGauge.Describe(ch)
|
||||
e.metricOptions.StartedCounter.Describe(ch)
|
||||
|
||||
e.metricOptions.ServiceMetrics.Counter.Describe(ch)
|
||||
e.metricOptions.ServiceMetrics.Histogram.Describe(ch)
|
||||
@ -51,6 +52,8 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
|
||||
e.metricOptions.GatewayFunctionInvocation.Collect(ch)
|
||||
e.metricOptions.GatewayFunctionsHistogram.Collect(ch)
|
||||
|
||||
e.metricOptions.StartedCounter.Collect(ch)
|
||||
|
||||
e.metricOptions.ServiceReplicasGauge.Reset()
|
||||
for _, service := range e.services {
|
||||
e.metricOptions.ServiceReplicasGauge.
|
||||
|
@ -17,6 +17,7 @@ type MetricOptions struct {
|
||||
GatewayFunctionsHistogram *prometheus.HistogramVec
|
||||
ServiceReplicasGauge *prometheus.GaugeVec
|
||||
ServiceMetrics *ServiceMetricOptions
|
||||
StartedCounter *prometheus.CounterVec
|
||||
}
|
||||
|
||||
// ServiceMetricOptions provides RED metrics
|
||||
@ -81,6 +82,16 @@ func BuildMetricsOptions() MetricOptions {
|
||||
[]string{"method", "path", "status"},
|
||||
)
|
||||
|
||||
startedCounter := prometheus.NewCounterVec(
|
||||
prometheus.CounterOpts{
|
||||
Namespace: "gateway",
|
||||
Subsystem: "function",
|
||||
Name: "invocation_started",
|
||||
Help: "The total number of function HTTP requests started.",
|
||||
},
|
||||
[]string{"function_name"},
|
||||
)
|
||||
|
||||
serviceMetricOptions := &ServiceMetricOptions{
|
||||
Counter: counter,
|
||||
Histogram: histogram,
|
||||
@ -91,6 +102,7 @@ func BuildMetricsOptions() MetricOptions {
|
||||
GatewayFunctionInvocation: gatewayFunctionInvocation,
|
||||
ServiceReplicasGauge: serviceReplicas,
|
||||
ServiceMetrics: serviceMetricOptions,
|
||||
StartedCounter: startedCounter,
|
||||
}
|
||||
|
||||
return metricsOptions
|
||||
|
Reference in New Issue
Block a user