-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event processing histogram metric (#1134)
Problem: NGF does not measure how long it takes to process an event batch. Solution: Add a new histogram metric event_batch_processing_milliseconds, that measures the time it takes to process an event batch. Also adds a debug log statement with the same information so we can debug spikes in processing time.
1 parent
4f40fca
commit 567f27e
Showing
17 changed files
with
234 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 13 additions & 10 deletions
23
internal/framework/events/eventsfakes/fake_event_handler.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package collectors | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
|
||
"github.com/nginxinc/nginx-gateway-fabric/internal/mode/static/metrics" | ||
) | ||
|
||
// ControllerCollector collects metrics for the NGF controller. | ||
// Implements the prometheus.Collector interface. | ||
type ControllerCollector struct { | ||
// Metrics | ||
eventBatchProcessDuration prometheus.Histogram | ||
} | ||
|
||
// NewControllerCollector creates a new ControllerCollector | ||
func NewControllerCollector(constLabels map[string]string) *ControllerCollector { | ||
nc := &ControllerCollector{ | ||
eventBatchProcessDuration: prometheus.NewHistogram( | ||
prometheus.HistogramOpts{ | ||
Name: "event_batch_processing_milliseconds", | ||
Namespace: metrics.Namespace, | ||
Help: "Duration in milliseconds of event batch processing", | ||
ConstLabels: constLabels, | ||
Buckets: []float64{500, 1000, 5000, 10000, 30000}, | ||
}, | ||
), | ||
} | ||
return nc | ||
} | ||
|
||
// ObserveLastEventBatchProcessTime adds the last event batch processing time to the histogram. | ||
func (c *ControllerCollector) ObserveLastEventBatchProcessTime(duration time.Duration) { | ||
c.eventBatchProcessDuration.Observe(float64(duration / time.Millisecond)) | ||
} | ||
|
||
// Describe implements prometheus.Collector interface Describe method. | ||
func (c *ControllerCollector) Describe(ch chan<- *prometheus.Desc) { | ||
c.eventBatchProcessDuration.Describe(ch) | ||
} | ||
|
||
// Collect implements the prometheus.Collector interface Collect method. | ||
func (c *ControllerCollector) Collect(ch chan<- prometheus.Metric) { | ||
c.eventBatchProcessDuration.Collect(ch) | ||
} | ||
|
||
// ControllerNoopCollector used to initialize the ControllerCollector when metrics are disabled to avoid nil pointer | ||
// errors. | ||
type ControllerNoopCollector struct{} | ||
|
||
// NewControllerNoopCollector returns an instance of the ControllerNoopCollector. | ||
func NewControllerNoopCollector() *ControllerNoopCollector { | ||
return &ControllerNoopCollector{} | ||
} | ||
|
||
func (c *ControllerNoopCollector) ObserveLastEventBatchProcessTime(_ time.Duration) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package metrics | ||
|
||
// nolint:gosec // flagged as potential hardcoded credentials, but is not sensitive | ||
const metricsNamespace = "nginx_gateway_fabric" | ||
const Namespace = "nginx_gateway_fabric" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters