Skip to content

expose health status as metric #17839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func main() {
// metrics collector
metricsCollector := metrics.NewCollector(latency.NewBucketsProvider())
prometheus.MustRegister(metricsCollector)
metricsCollector.SetHealthStatus(true)

// Instantiate configured commander.
var c commander.Commander
Expand Down
32 changes: 29 additions & 3 deletions components/event-publisher-proxy/pkg/metrics/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ import (
)

const (
// BackendLatencyKey name of the backendLatencyHelp metric.
// HealthKey name of the health metric.
HealthKey = "eventing_epp_health"
// HealthHelp help text for the Health metric.
healthHelp = "The current health of the system. `1` indicates a healthy system"

// BackendLatencyKey name of the backendLatency metric.
BackendLatencyKey = "eventing_epp_backend_duration_milliseconds"
// backendLatencyHelp help text for the backendLatencyHelp metric.
// backendLatencyHelp help text for the backendLatency metric.
backendLatencyHelp = "The duration of sending events to the messaging server in milliseconds"

// durationKey name of the duration metric.
Expand Down Expand Up @@ -66,6 +71,8 @@ type Collector struct {
requests *prometheus.CounterVec

eventType *prometheus.CounterVec

health *prometheus.GaugeVec
}

// NewCollector creates a new instance of Collector.
Expand Down Expand Up @@ -102,7 +109,15 @@ func NewCollector(latency histogram.BucketsProvider) *Collector {
Name: RequestsKey,
Help: requestsHelp,
},
[]string{responseCodeLabel, methodLabel, pathLabel}),
[]string{responseCodeLabel, methodLabel, pathLabel},
),
health: prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: HealthKey,
Help: healthHelp,
},
nil,
),
}
}

Expand All @@ -112,6 +127,7 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
c.eventType.Describe(ch)
c.requests.Describe(ch)
c.duration.Describe(ch)
c.health.Describe(ch)
}

// Collect implements the prometheus.Collector interface Collect method.
Expand All @@ -120,13 +136,23 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
c.eventType.Collect(ch)
c.requests.Collect(ch)
c.duration.Collect(ch)
c.health.Collect(ch)
}

// RecordLatency records a backendLatencyHelp metric.
func (c *Collector) RecordBackendLatency(duration time.Duration, statusCode int, destSvc string) {
c.backendLatency.WithLabelValues(fmt.Sprint(statusCode), destSvc).Observe(float64(duration.Milliseconds()))
}

// SetHealthStatus updates the health metric.
func (c *Collector) SetHealthStatus(healthy bool) {
var v float64
if healthy {
v = 1
}
c.health.WithLabelValues().Set(v)
}

// RecordEventType records an eventType metric.
func (c *Collector) RecordEventType(eventType, eventSource string, statusCode int) {
c.eventType.WithLabelValues(eventType, eventSource, fmt.Sprint(statusCode)).Inc()
Expand Down
4 changes: 3 additions & 1 deletion components/eventing-controller/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ lint-thoroughly:

update_metrics_docs:
@promlinter list -ojson ../event-publisher-proxy > metrics_epp.json
@jq 'sort_by(.Name)' metrics_epp.json > metrics_epp_sorted.json
@promlinter list -ojson ../eventing-controller/ > metrics_ec.json
@gomplate -d ec=metrics_ec.json -d epp=metrics_epp.json -f hack/metrics.doc.tpl | prettier --parser markdown > ../../docs/04-operation-guides/operations/evnt-02-eventing-metrics.md
@jq 'sort_by(.Name)' metrics_ec.json > metrics_ec_sorted.json
@gomplate -d ec=metrics_ec_sorted.json -d epp=metrics_epp_sorted.json -f hack/metrics.doc.tpl | prettier --parser markdown > ../../docs/04-operation-guides/operations/evnt-02-eventing-metrics.md

update_docs: copy-crds
go run ../../hack/table-gen/main.go --crd-filename ../../installation/resources/crds/eventing/subscriptions.eventing.kyma-project.io.crd.yaml --md-filename ../../docs/05-technical-reference/00-custom-resources/evnt-01-subscription.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ The metrics follow the [Prometheus naming convention](https://prometheus.io/docs

| Metric | Description |
| ----------------------------------------------- | :------------------------------------------------------------------------------- |
| **eventing_epp_requests_total** | The total number of requests |
| **eventing_epp_backend_duration_milliseconds** | The duration of sending events to the messaging server in milliseconds |
| **eventing_epp_event_type_published_total** | The total number of events published for a given eventTypeLabel |
| **eventing_epp_health** | The current health of the system. `1` indicates a healthy system |
| **eventing_epp_requests_duration_milliseconds** | The duration of processing an incoming request (includes sending to the backend) |
| **eventing_epp_requests_total** | The total number of requests |

### Metrics Emitted by Eventing Controller:

| Metric | Description |
| --------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------- |
| **eventing_ec_event_type_subscribed_total** | The total number of eventTypes subscribed using the Subscription CRD |
| **eventing_ec_nats_delivery_per_subscription_total** | The total number of dispatched events per subscription |
| **eventing_ec_nats_subscriber_dispatch_duration_seconds** | The duration of sending an incoming NATS message to the subscriber (not including processing the message in the dispatcher) |
| **eventing_ec_event_type_subscribed_total** | The total number of eventTypes subscribed using the Subscription CRD |

### Metrics Emitted by NATS Exporter:

Expand Down
2 changes: 1 addition & 1 deletion resources/eventing/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ global:
images:
eventing_controller:
name: eventing-controller
version: PR-17860
version: PR-17839
directory: dev
pullPolicy: "IfNotPresent"
publisher_proxy:
Expand Down