Skip to content
Snippets Groups Projects
Commit fca32a0e authored by Alex Ellis (VMware)'s avatar Alex Ellis (VMware) Committed by Alex Ellis
Browse files

Instrument async handlers


- instruments async handler for report and for queueing async
requests
- make MustRegister only ever run once to prevent sync issues

Signed-off-by: default avatarAlex Ellis (VMware) <alexellis2@gmail.com>
parent 5a1bdcdb
No related branches found
No related tags found
No related merge requests found
File moved
......@@ -37,6 +37,7 @@ func NewExporter(options MetricOptions, credentials *auth.BasicAuthCredentials)
// Describe is to describe the metrics for Prometheus
func (e *Exporter) Describe(ch chan<- *prometheus.Desc) {
e.metricOptions.GatewayFunctionInvocation.Describe(ch)
e.metricOptions.GatewayFunctionsHistogram.Describe(ch)
e.metricOptions.ServiceReplicasGauge.Describe(ch)
......
......@@ -40,24 +40,27 @@ func Test_Describe_DescribesThePrometheusMetrics(t *testing.T) {
go exporter.Describe(ch)
d := (<-ch)
d := <-ch
expectedGatewayFunctionInvocationDesc := `Desc{fqName: "gateway_function_invocation_total", help: "Individual function metrics", constLabels: {}, variableLabels: [function_name code]}`
actualGatewayFunctionInvocationDesc := d.String()
if expectedGatewayFunctionInvocationDesc != actualGatewayFunctionInvocationDesc {
t.Errorf("Want %s, got: %s", expectedGatewayFunctionInvocationDesc, actualGatewayFunctionInvocationDesc)
}
d = (<-ch)
d = <-ch
expectedGatewayFunctionsHistogramDesc := `Desc{fqName: "gateway_functions_seconds", help: "Function time taken", constLabels: {}, variableLabels: [function_name]}`
actualGatewayFunctionsHistogramDesc := d.String()
if expectedGatewayFunctionsHistogramDesc != actualGatewayFunctionsHistogramDesc {
t.Errorf("Want %s, got: %s", expectedGatewayFunctionsHistogramDesc, actualGatewayFunctionsHistogramDesc)
}
d = (<-ch)
d = <-ch
expectedServiceReplicasGaugeDesc := `Desc{fqName: "gateway_service_count", help: "Docker service replicas", constLabels: {}, variableLabels: [function_name]}`
actualServiceReplicasGaugeDesc := d.String()
if expectedServiceReplicasGaugeDesc != actualServiceReplicasGaugeDesc {
t.Errorf("Want %s, got: %s", expectedServiceReplicasGaugeDesc, actualServiceReplicasGaugeDesc)
}
}
func Test_Collect_CollectsTheNumberOfReplicasOfAService(t *testing.T) {
......
......@@ -5,6 +5,7 @@ package metrics
import (
"net/http"
"sync"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
......@@ -24,6 +25,16 @@ type ServiceMetricOptions struct {
Counter *prometheus.CounterVec
}
// Synchronize to make sure MustRegister only called once
var once = sync.Once{}
// RegisterExporter registers with Prometheus for tracking
func RegisterExporter(exporter *Exporter) {
once.Do(func() {
prometheus.MustRegister(exporter)
})
}
// PrometheusHandler Bootstraps prometheus for metrics collection
func PrometheusHandler() http.Handler {
return promhttp.Handler()
......@@ -84,8 +95,3 @@ func BuildMetricsOptions() MetricOptions {
return metricsOptions
}
// RegisterExporter registers with Prometheus for tracking
func RegisterExporter(exporter *Exporter) {
prometheus.MustRegister(exporter)
}
......@@ -96,7 +96,10 @@ func main() {
faasHandlers.SecretHandler = handlers.MakeForwardingProxyHandler(reverseProxy, forwardingNotifiers, urlResolver, nilURLTransformer)
alertHandler := plugin.NewExternalServiceQuery(*config.FunctionsProviderURL, credentials)
faasHandlers.Alert = handlers.MakeNotifierWrapper(handlers.MakeAlertHandler(alertHandler), forwardingNotifiers)
faasHandlers.Alert = handlers.MakeNotifierWrapper(
handlers.MakeAlertHandler(alertHandler),
forwardingNotifiers,
)
if config.UseNATS() {
log.Println("Async enabled: Using NATS Streaming.")
......@@ -105,8 +108,15 @@ func main() {
log.Fatalln(queueErr)
}
faasHandlers.QueuedProxy = handlers.MakeCallIDMiddleware(handlers.MakeQueuedProxy(metricsOptions, true, natsQueue, functionURLTransformer))
faasHandlers.AsyncReport = handlers.MakeAsyncReport(metricsOptions)
faasHandlers.QueuedProxy = handlers.MakeNotifierWrapper(
handlers.MakeCallIDMiddleware(handlers.MakeQueuedProxy(metricsOptions, true, natsQueue, functionURLTransformer)),
forwardingNotifiers,
)
faasHandlers.AsyncReport = handlers.MakeNotifierWrapper(
handlers.MakeAsyncReport(metricsOptions),
forwardingNotifiers,
)
}
prometheusQuery := metrics.NewPrometheusQuery(config.PrometheusHost, config.PrometheusPort, &http.Client{})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment