8000 excludeMetricsRegexp -- filter out noisy metrics, e,g CPU and OS by alex-zaitsev · Pull Request #1975 · Altinity/clickhouse-operator · GitHub
[go: up one dir, main page]

Skip to content
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
4 changes: 4 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ clickhouse:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
4 changes: 4 additions & 0 deletions deploy/builder/templates-config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ clickhouse:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down
9 changes: 9 additions & 0 deletions deploy/helm/clickhouse-operator/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,15 @@
"metrics": {
"type": "object",
"properties": {
"excludeMetricsRegexp": {
"type": "array",
"items": {
"type": "string"
}
},
"tablesRegexp": {
"type": "string"
},
"timeouts": {
"type": "object",
"properties": {
Expand Down
4 changes: 4 additions & 0 deletions deploy/helm/clickhouse-operator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ configs:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"
keeper:
configuration:
################################################
Expand Down
11 changes: 11 additions & 0 deletions deploy/operator/clickhouse-operator-install-ansible.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down Expand Up @@ -5338,6 +5345,10 @@ data:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
13 changes: 11 additions & 2 deletions deploy/operator/clickhouse-operator-install-bundle-v1beta1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down Expand Up @@ -4760,7 +4767,6 @@ metadata:
namespace: kube-system
labels:
clickhouse.altinity.com/chop: 0.27.0

# Template Parameters:
#
# NAMESPACE=kube-system
Expand Down Expand Up @@ -5013,7 +5019,6 @@ subjects:
- kind: ServiceAccount
name: clickhouse-operator
namespace: kube-system

# Template Parameters:
#
# NAMESPACE=kube-system
Expand Down Expand Up @@ -5537,6 +5542,10 @@ data:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
11 changes: 11 additions & 0 deletions deploy/operator/clickhouse-operator-install-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3480,6 +3480,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down Expand Up @@ -5597,6 +5604,10 @@ data:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3454,6 +3454,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down Expand Up @@ -4760,7 +4767,6 @@ metadata:
namespace: ${OPERATOR_NAMESPACE}
labels:
clickhouse.altinity.com/chop: 0.27.0

# Template Parameters:
#
# NAMESPACE=${OPERATOR_NAMESPACE}
Expand Down Expand Up @@ -5284,6 +5290,10 @@ data:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
11 changes: 11 additions & 0 deletions deploy/operator/clickhouse-operator-install-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3480,6 +3480,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down Expand Up @@ -5331,6 +5338,10 @@ data:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
11 changes: 11 additions & 0 deletions deploy/operator/clickhouse-operator-install-tf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down Expand Up @@ -5338,6 +5345,10 @@ data:
# Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
# Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
tablesRegexp: "^(metrics|custom_metrics)$"
# List of regexps to match ClickHouse metrics to exclude from export.
# Regexps match internal metric names before Prometheus normalization and prefixing.
excludeMetricsRegexp:
- "^metric\\.(OS.*CPU[0-9]+|CPUFrequencyMHz_[0-9]+)$"

keeper:
configuration:
Expand Down
7 changes: 7 additions & 0 deletions deploy/operator/parts/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8428,6 +8428,13 @@ spec:
Regexp to match tables in system database to fetch metrics from.
Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
Default is "^(metrics|custom_metrics)$".
excludeMetricsRegexp:
type: array
items:
type: string
description: |
List of regexps to match ClickHouse metrics to exclude from export.
Regexps match internal metric names before Prometheus normalization and prefixing.
template:
type: object
description: "Parameters which are used if you want to generate ClickHouseInstallationTemplate custom resources from files which are stored inside clickhouse-operator deployment"
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/clickhouse.altinity.com/v1/type_configuration_chop.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"os"
"regexp"
"slices"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -416,6 +417,9 @@ type OperatorConfigClickHouse struct {
// Multiple tables can be matched using regexp. Matched tables are merged using merge() table function.
// Default is "^(metrics|custom_metrics)$" which fetches from both system.metrics and system.custom_metrics.
TablesRegexp string `json:"tablesRegexp" yaml:"tablesRegexp"`
// ExcludeMetricsRegexp specifies a list of regexps to match ClickHouse metric names to exclude.
// Regexps are matched against internal metric names before Prometheus normalization and prefixing.
ExcludeMetricsRegexp []string `json:"excludeMetricsRegexp,omitempty" yaml:"excludeMetricsRegexp,omitempty"`
} `json:"metrics" yaml:"metrics"`
}

Expand Down Expand Up @@ -930,10 +934,17 @@ func (c *OperatorConfig) MergeFrom(from *OperatorConfig) error {
return nil
}

excludeMetricsRegexp := from.ClickHouse.Metrics.ExcludeMetricsRegexp
if err := mergo.Merge(c, *from, mergo.WithAppendSlice, mergo.WithOverride); err != nil {
return fmt.Errorf("FAIL merge config Error: %q", err)
}

// Unlike additive label/template lists, metric exclusion regexps are a complete filter set.
// Preserve the distinction between omitted (nil) and explicitly empty ([]) CHOPCONF values.
if excludeMetricsRegexp != nil {
c.ClickHouse.Metrics.ExcludeMetricsRegexp = slices.Clone(excludeMetricsRegexp)
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/clickhouse.altinity.com/v1/zz_generated.deepcopy.go

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

19 changes: 17 additions & 2 deletions pkg/metrics/clickhouse/clickhouse_metrics_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,19 @@ const (
type MetricsFetcher struct {
connectionParams *clickhouse.EndpointConnectionParams
tablesRegexp string
metricFilter *metricRegexpFilter
}

// NewMetricsFetcher creates new clickhouse fetcher object
func NewMetricsFetcher(
endpointConnectionParams *clickhouse.EndpointConnectionParams,
tablesRegexp string,
metricFilter *metricRegexpFilter,
) *MetricsFetcher {
return &MetricsFetcher{
connectionParams: endpointConnectionParams,
tablesRegexp: tablesRegexp,
metricFilter: metricFilter,
}
}

Expand All @@ -169,12 +172,24 @@ func (f *MetricsFetcher) buildMetricsTableSource() string {
return fmt.Sprintf("merge('system','%s')", f.tablesRegexp)
}

func (f *MetricsFetcher) buildMetricsSQL() string {
metricsSQL := fmt.Sprintf(queryMetricsSQLTemplate, f.buildMetricsTableSource())
if !f.metricFilter.hasPatterns() {
return metricsSQL
}

return fmt.Sprintf(`
SELECT metric, value, description, type
FROM (%s)
WHERE NOT (%s)
`, metricsSQL, f.metricFilter.buildExcludeMetricsWhere())
}

// getClickHouseQueryMetrics requests metrics data from ClickHouse
func (f *MetricsFetcher) getClickHouseQueryMetrics(ctx context.Context) (Table, error) {
metricsSQL := fmt.Sprintf(queryMetricsSQLTemplate, f.buildMetricsTableSource())
return f.clickHouseQueryScanRows(
ctx,
metricsSQL,
f.buildMetricsSQL(),
func(rows *sql.Rows, data *Table) error {
var metric, value, description, _type string
if err := rows.Scan(&metric, &value, &description, &_type); err == nil {
Expand Down
Loading
Loading
0