Skip to content

Commit

Permalink
Merge pull request #566 from Aoao54/support-configure-metrics-histogr…
Browse files Browse the repository at this point in the history
…am-boundaries

feat(config): add support for Metrics PerUnitHistogramBoundaries config
  • Loading branch information
alexandrevilain authored Dec 11, 2023
2 parents b78c58b + 7aa3997 commit 214522d
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
9 changes: 9 additions & 0 deletions api/v1beta1/temporalcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,15 @@ type PrometheusSpec struct {
type MetricsSpec struct {
// Enabled defines if the operator should enable metrics exposition on temporal components.
Enabled bool `json:"enabled"`
// PerUnitHistogramBoundaries defines the default histogram bucket boundaries.
// Configuration of histogram boundaries for given metric unit.
//
// Supported values:
// - "dimensionless"
// - "milliseconds"
// - "bytes"
// +optional
PerUnitHistogramBoundaries map[string][]string `json:"perUnitHistogramBoundaries,omitempty"`
// Prometheus reporter configuration.
// +optional
Prometheus *PrometheusSpec `json:"prometheus,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/temporal.io_temporalclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@ spec:
enabled:
description: Enabled defines if the operator should enable metrics exposition on temporal components.
type: boolean
perUnitHistogramBoundaries:
additionalProperties:
items:
type: string
type: array
description: "PerUnitHistogramBoundaries defines the default histogram bucket boundaries. Configuration of histogram boundaries for given metric unit. \n Supported values: - \"dimensionless\" - \"milliseconds\" - \"bytes\""
type: object
prometheus:
description: Prometheus reporter configuration.
properties:
Expand Down
20 changes: 20 additions & 0 deletions internal/resource/config/configmap_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"path"
"strconv"
"time"

"github.com/alexandrevilain/controller-tools/pkg/resource"
Expand Down Expand Up @@ -314,6 +315,25 @@ func (b *ConfigmapBuilder) Update(object client.Object) error {
Tags: map[string]string{"type": "{{ .Env.SERVICES }}"},
},
}

if b.instance.Spec.Metrics.PerUnitHistogramBoundaries != nil {
buckets := make(map[string][]float64)
p := b.instance.Spec.Metrics.PerUnitHistogramBoundaries
// Convert map[string][]string to map[string][]float64
for key, value := range p {
var floatSlice []float64
for _, str := range value {
floatVal, err := strconv.ParseFloat(str, 64)
if err != nil {
return fmt.Errorf("can't build metrics config: Error converting %s to float: %w", str, err)
}
floatSlice = append(floatSlice, floatVal)
}
buckets[key] = floatSlice
}
temporalCfg.Global.Metrics.ClientConfig.PerUnitHistogramBoundaries = buckets
}

if b.instance.Spec.Metrics.Prometheus != nil && b.instance.Spec.Metrics.Prometheus.ListenPort != nil {
temporalCfg.Global.Metrics.Prometheus = &metrics.PrometheusConfig{
TimerType: "histogram",
Expand Down
18 changes: 18 additions & 0 deletions webhooks/temporalcluster_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,24 @@ func (w *TemporalClusterWebhook) validateCluster(cluster *v1beta1.TemporalCluste
}
}

// Check for per unit histogram boundaries if metrics is enabled
if cluster.Spec.Metrics.IsEnabled() && cluster.Spec.Metrics.PerUnitHistogramBoundaries != nil {
p := cluster.Spec.Metrics.PerUnitHistogramBoundaries
for _, value := range p {
for _, str := range value {
_, err := strconv.ParseFloat(str, 64)
if err != nil {
errs = append(errs,
field.Forbidden(
field.NewPath("spec", "metrics", "perUnitHistogramBoundaries"),
fmt.Sprintf("can't parse this strings value to float64: %s ", str),
),
)
}
}
}
}

return warns, errs
}

Expand Down

0 comments on commit 214522d

Please sign in to comment.