Skip to content

Commit

Permalink
config: expose metrics configuration.
Browse files Browse the repository at this point in the history
Add configuration bits for controlling which metrics are
collected. Enable collection of policy metrics by default.

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Nov 15, 2024
1 parent a0f29c9 commit 0000b06
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 25 deletions.
28 changes: 26 additions & 2 deletions config/crd/bases/config.nri_balloonspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,36 @@ spec:
to expose Prometheus metrics among other things.
example: :8891
type: string
metrics:
default:
enabled:
- policy
description: Metrics defines which metrics to collect.
properties:
enabled:
description: Enabled enables collection for metrics matched
by glob patterns.
example:
- '*'
items:
type: string
type: array
polled:
description: Polled forces polled collection for metrics matched
by glob patterns.
example:
- computationally-expensive-metrics
items:
type: string
type: array
type: object
prometheusExport:
description: PrometheusExport enables exporting /metrics for Prometheus.
type: boolean
reportPeriod:
description: ReportPeriod is the interval between reporting aggregated
metrics.
default: 30s
description: ReportPeriod is the interval between between collecting
polled metrics.
format: duration
type: string
samplingRatePerMillion:
Expand Down
28 changes: 26 additions & 2 deletions config/crd/bases/config.nri_templatepolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,36 @@ spec:
to expose Prometheus metrics among other things.
example: :8891
type: string
metrics:
default:
enabled:
- policy
description: Metrics defines which metrics to collect.
properties:
enabled:
description: Enabled enables collection for metrics matched
by glob patterns.
example:
- '*'
items:
type: string
type: array
polled:
description: Polled forces polled collection for metrics matched
by glob patterns.
example:
- computationally-expensive-metrics
items:
type: string
type: array
type: object
prometheusExport:
description: PrometheusExport enables exporting /metrics for Prometheus.
type: boolean
reportPeriod:
description: ReportPeriod is the interval between reporting aggregated
metrics.
default: 30s
description: ReportPeriod is the interval between between collecting
polled metrics.
format: duration
type: string
samplingRatePerMillion:
Expand Down
28 changes: 26 additions & 2 deletions config/crd/bases/config.nri_topologyawarepolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,36 @@ spec:
to expose Prometheus metrics among other things.
example: :8891
type: string
metrics:
default:
enabled:
- policy
description: Metrics defines which metrics to collect.
properties:
enabled:
description: Enabled enables collection for metrics matched
by glob patterns.
example:
- '*'
items:
type: string
type: array
polled:
description: Polled forces polled collection for metrics matched
by glob patterns.
example:
- computationally-expensive-metrics
items:
type: string
type: array
type: object
prometheusExport:
description: PrometheusExport enables exporting /metrics for Prometheus.
type: boolean
reportPeriod:
description: ReportPeriod is the interval between reporting aggregated
metrics.
default: 30s
description: ReportPeriod is the interval between between collecting
polled metrics.
format: duration
type: string
samplingRatePerMillion:
Expand Down
28 changes: 26 additions & 2 deletions deployment/helm/balloons/crds/config.nri_balloonspolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,12 +320,36 @@ spec:
to expose Prometheus metrics among other things.
example: :8891
type: string
metrics:
default:
enabled:
- policy
description: Metrics defines which metrics to collect.
properties:
enabled:
description: Enabled enables collection for metrics matched
by glob patterns.
example:
- '*'
items:
type: string
type: array
polled:
description: Polled forces polled collection for metrics matched
by glob patterns.
example:
- computationally-expensive-metrics
items:
type: string
type: array
type: object
prometheusExport:
description: PrometheusExport enables exporting /metrics for Prometheus.
type: boolean
reportPeriod:
description: ReportPeriod is the interval between reporting aggregated
metrics.
default: 30s
description: ReportPeriod is the interval between between collecting
polled metrics.
format: duration
type: string
samplingRatePerMillion:
Expand Down
28 changes: 26 additions & 2 deletions deployment/helm/template/crds/config.nri_templatepolicies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,36 @@ spec:
to expose Prometheus metrics among other things.
example: :8891
type: string
metrics:
default:
enabled:
- policy
description: Metrics defines which metrics to collect.
properties:
enabled:
description: Enabled enables collection for metrics matched
by glob patterns.
example:
- '*'
items:
type: string
type: array
polled:
description: Polled forces polled collection for metrics matched
by glob patterns.
example:
- computationally-expensive-metrics
items:
type: string
type: array
type: object
prometheusExport:
description: PrometheusExport enables exporting /metrics for Prometheus.
type: boolean
reportPeriod:
description: ReportPeriod is the interval between reporting aggregated
metrics.
default: 30s
description: ReportPeriod is the interval between between collecting
polled metrics.
format: duration
type: string
samplingRatePerMillion:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,36 @@ spec:
to expose Prometheus metrics among other things.
example: :8891
type: string
metrics:
default:
enabled:
- policy
description: Metrics defines which metrics to collect.
properties:
enabled:
description: Enabled enables collection for metrics matched
by glob patterns.
example:
- '*'
items:
type: string
type: array
polled:
description: Polled forces polled collection for metrics matched
by glob patterns.
example:
- computationally-expensive-metrics
items:
type: string
type: array
type: object
prometheusExport:
description: PrometheusExport enables exporting /metrics for Prometheus.
type: boolean
reportPeriod:
description: ReportPeriod is the interval between reporting aggregated
metrics.
default: 30s
description: ReportPeriod is the interval between between collecting
polled metrics.
format: duration
type: string
samplingRatePerMillion:
Expand Down
9 changes: 6 additions & 3 deletions docs/resource-policy/policy/balloons.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ Balloons policy parameters:
- `prometheusExport`: if set to True, balloons with their CPUs
and assigned containers are readable through `/metrics` from the
httpEndpoint.
- `reportPeriod`: `/metrics` aggregation interval.
- `reportPeriod`: `/metrics` aggregation interval for polled metrics.
### Example
Example configuration that runs all pods in balloons of 1-4
CPUs. Instrumentation enables reading CPUs and containers in balloons
from `http://localhost:8891/metrics`.
from `http://$localhost_or_pod_IP:8891/metrics`.
```yaml
apiVersion: config.nri/v1alpha1
Expand Down Expand Up @@ -413,9 +413,12 @@ nri-resource-policy global config:
instrumentation:
# The balloons policy exports containers running in each balloon,
# and cpusets of balloons. Accessible in command line:
# curl --silent http://localhost:8891/metrics
# curl --silent http://$localhost_or_pod_IP:8891/metrics
HTTPEndpoint: :8891
PrometheusExport: true
metrics:
enabled: # use '*' instead for all available metrics
- policy
logger:
Debug: policy
```
8 changes: 7 additions & 1 deletion pkg/apis/config/v1alpha1/instrumentation/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
package instrumentation

import (
"github.com/containers/nri-plugins/pkg/apis/config/v1alpha1/metrics"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Config provides runtime configuration for instrumentation.
// +k8s:deepcopy-gen=true
type Config struct {
// SamplingRatePerMillion is the number of samples to collect per million spans.
// +optional
Expand All @@ -33,9 +35,10 @@ type Config struct {
// +optional
// +kubebuilder:example="otlp-http://localhost:4318"
TracingCollector string `json:"tracingCollector,omitempty"`
// ReportPeriod is the interval between reporting aggregated metrics.
// ReportPeriod is the interval between between collecting polled metrics.
// +optional
// +kubebuilder:validation:Format="duration"
// +kubebuilder:default="30s"
ReportPeriod metav1.Duration `json:"reportPeriod,omitempty"`
// HTTPEndpoint is the address our HTTP server listens on. This endpoint is used
// to expose Prometheus metrics among other things.
Expand All @@ -45,4 +48,7 @@ type Config struct {
// PrometheusExport enables exporting /metrics for Prometheus.
// +optional
PrometheusExport bool `json:"prometheusExport,omitempty"`
// Metrics defines which metrics to collect.
// +kubebuilder:default={"enabled": {"policy"}}
Metrics *metrics.Config `json:"metrics,omitempty"`
}
44 changes: 44 additions & 0 deletions pkg/apis/config/v1alpha1/instrumentation/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions pkg/apis/config/v1alpha1/metrics/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright The NRI Plugins Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package metrics

// Config provides runtime configuration for metrics collection.
// +k8s:deepcopy-gen=true
type Config struct {
// Enabled enables collection for metrics matched by glob patterns.
// +optional
// +kubebuilder:example={"*"}
Enabled []string `json:"enabled,omitempty"`
// Polled forces polled collection for metrics matched by glob patterns.
// +optional
// +kubebuilder:example={"computationally-expensive-metrics"}
Polled []string `json:"polled,omitempty"`
}
Loading

0 comments on commit 0000b06

Please sign in to comment.