-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose API call metrics and node CSR approve statistics. Signed-off-by: Serge Logvinov <[email protected]>
- Loading branch information
1 parent
0faf0ae
commit 2150cdd
Showing
10 changed files
with
195 additions
and
4 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
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,62 @@ | ||
# Metrics documentation | ||
|
||
This document is a reflection of the current state of the exposed metrics of the Talos CCM. | ||
|
||
## Gater metrics from talos-cloud-controller-manager | ||
|
||
By default, the Talos CCM exposes metrics on the `https://localhost:50258/metrics` endpoint. | ||
|
||
Enabling the metrics is done by setting the `--secure-port` and the `--authorization-always-allow-paths` flag to allow access to the `/metrics` endpoint. | ||
|
||
```yaml | ||
talos-cloud-controller-manager | ||
--authorization-always-allow-paths="/metrics" | ||
--secure-port=50258 | ||
``` | ||
|
||
### Helm chart values | ||
|
||
The following values can be set in the Helm chart to expose the metrics of the Talos CCM. | ||
|
||
```yaml | ||
service: | ||
containerPort: 50258 | ||
annotations: | ||
prometheus.io/scrape: "true" | ||
prometheus.io/scheme: "https" | ||
prometheus.io/port: "50258" | ||
``` | ||
## Metrics exposed by the CCM | ||
### Talos API calls | ||
|Metric name|Metric type|Labels/tags| | ||
|-----------|-----------|-----------| | ||
|talosccm_api_request_duration_seconds|Histogram|`request`=<api_request>| | ||
|talosccm_api_request_errors_total|Counter|`request`=<api_request>| | ||
|
||
```txt | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="0.1"} 10 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="0.25"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="0.5"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="1"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="2.5"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="5"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="10"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="30"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="addresses",le="+Inf"} 16 | ||
talosccm_api_request_duration_seconds_sum{request="addresses"} 1.369387789 | ||
talosccm_api_request_duration_seconds_count{request="addresses"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="0.1"} 14 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="0.25"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="0.5"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="1"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="2.5"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="5"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="10"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="30"} 16 | ||
talosccm_api_request_duration_seconds_bucket{request="platformmetadata",le="+Inf"} 16 | ||
talosccm_api_request_duration_seconds_sum{request="platformmetadata"} 1.2046141220000002 | ||
talosccm_api_request_duration_seconds_count{request="platformmetadata"} 16 | ||
``` |
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,20 @@ | ||
// Package metrics collects metrics. | ||
package metrics | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// MetricContext indicates the context for Talos client metrics. | ||
type MetricContext struct { | ||
start time.Time | ||
attributes []string | ||
} | ||
|
||
// NewMetricContext creates a new MetricContext. | ||
func NewMetricContext(resource string) *MetricContext { | ||
return &MetricContext{ | ||
start: time.Now(), | ||
attributes: []string{resource}, | ||
} | ||
} |
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,51 @@ | ||
package metrics | ||
|
||
import ( | ||
"time" | ||
|
||
"k8s.io/component-base/metrics" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
) | ||
|
||
// TalosMetrics contains the metrics for Talos API calls. | ||
type TalosMetrics struct { | ||
Duration *metrics.HistogramVec | ||
Errors *metrics.CounterVec | ||
} | ||
|
||
var apiMetrics = registerAPIMetrics() | ||
|
||
// ObserveRequest records the request latency and counts the errors. | ||
func (mc *MetricContext) ObserveRequest(err error) error { | ||
apiMetrics.Duration.WithLabelValues(mc.attributes...).Observe( | ||
time.Since(mc.start).Seconds()) | ||
|
||
if err != nil { | ||
apiMetrics.Errors.WithLabelValues(mc.attributes...).Inc() | ||
} | ||
|
||
return err | ||
} | ||
|
||
func registerAPIMetrics() *TalosMetrics { | ||
metrics := &TalosMetrics{ | ||
Duration: metrics.NewHistogramVec( | ||
&metrics.HistogramOpts{ | ||
Name: "talosccm_api_request_duration_seconds", | ||
Help: "Latency of an Talos API call", | ||
Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 30}, | ||
}, []string{"request"}), | ||
Errors: metrics.NewCounterVec( | ||
&metrics.CounterOpts{ | ||
Name: "talosccm_api_request_errors_total", | ||
Help: "Total number of errors for an Talos API call", | ||
}, []string{"request"}), | ||
} | ||
|
||
legacyregistry.MustRegister( | ||
metrics.Duration, | ||
metrics.Errors, | ||
) | ||
|
||
return metrics | ||
} |
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,44 @@ | ||
package metrics | ||
|
||
import ( | ||
"k8s.io/component-base/metrics" | ||
"k8s.io/component-base/metrics/legacyregistry" | ||
) | ||
|
||
// CSRMetrics contains the metrics for certificate signing requests. | ||
type CSRMetrics struct { | ||
approvalCount *metrics.CounterVec | ||
} | ||
|
||
// CSRApprovalStatus is the status of a CSR. | ||
type CSRApprovalStatus string | ||
|
||
const ( | ||
// ApprovalStatusDeny is used when a CSR is denied. | ||
ApprovalStatusDeny CSRApprovalStatus = "deny" | ||
// ApprovalStatusApprove is used when a CSR is approved. | ||
ApprovalStatusApprove CSRApprovalStatus = "approve" | ||
) | ||
|
||
var csrMetrics = registerCSRMetrics() | ||
|
||
// CSRApprovedCount counts the number of approved, denied and ignored CSRs. | ||
func CSRApprovedCount(status CSRApprovalStatus) { | ||
csrMetrics.approvalCount.WithLabelValues(string(status)).Inc() | ||
} | ||
|
||
func registerCSRMetrics() *CSRMetrics { | ||
metrics := &CSRMetrics{ | ||
approvalCount: metrics.NewCounterVec( | ||
&metrics.CounterOpts{ | ||
Name: "talosccm_csr_approval_count", | ||
Help: "Count of approved, denied and ignored node CSRs", | ||
}, []string{"status"}), | ||
} | ||
|
||
legacyregistry.MustRegister( | ||
metrics.approvalCount, | ||
) | ||
|
||
return metrics | ||
} |
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