Skip to content
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

feat(kuma-cp): allow to disable resources count metrics #7304

Merged
merged 2 commits into from
Jul 24, 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
3 changes: 3 additions & 0 deletions docs/generated/kuma-cp.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,9 @@ metrics:
minResyncTimeout: 1s # ENV: KUMA_METRICS_MESH_MIN_RESYNC_TIMEOUT
# Max time that MeshInsight could spend without resync
maxResyncTimeout: 20s # ENV: KUMA_METRICS_MESH_MAX_RESYNC_TIMEOUT
controlPlane:
# If true metrics show number of resources in the system should be reported
reportResourcesCount: true # ENV: KUMA_METRICS_CONTROL_PLANE_REPORT_RESOURCES_COUNT

# Reports configuration
reports:
Expand Down
3 changes: 3 additions & 0 deletions docs/generated/raw/kuma-cp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ metrics:
minResyncTimeout: 1s # ENV: KUMA_METRICS_MESH_MIN_RESYNC_TIMEOUT
# Max time that MeshInsight could spend without resync
maxResyncTimeout: 20s # ENV: KUMA_METRICS_MESH_MAX_RESYNC_TIMEOUT
controlPlane:
# If true metrics show number of resources in the system should be reported
reportResourcesCount: true # ENV: KUMA_METRICS_CONTROL_PLANE_REPORT_RESOURCES_COUNT

# Reports configuration
reports:
Expand Down
16 changes: 13 additions & 3 deletions pkg/config/app/kuma-cp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ func (d *Defaults) Validate() error {
}

type Metrics struct {
Dataplane *DataplaneMetrics `json:"dataplane"`
Zone *ZoneMetrics `json:"zone"`
Mesh *MeshMetrics `json:"mesh"`
Dataplane *DataplaneMetrics `json:"dataplane"`
Zone *ZoneMetrics `json:"zone"`
Mesh *MeshMetrics `json:"mesh"`
ControlPlane *ControlPlaneMetrics `json:"controlPlane"`
}

func (m *Metrics) Sanitize() {
Expand Down Expand Up @@ -95,6 +96,12 @@ type MeshMetrics struct {
MaxResyncTimeout config_types.Duration `json:"maxResyncTimeout" envconfig:"kuma_metrics_mesh_max_resync_timeout"`
}

type ControlPlaneMetrics struct {
// ReportResourcesCount if true will report metrics with the count of resources.
// Default: true
ReportResourcesCount bool `json:"reportResourcesCount" envconfig:"kuma_metrics_control_plane_report_resources_count"`
}

func (d *MeshMetrics) Sanitize() {
}

Expand Down Expand Up @@ -196,6 +203,9 @@ var DefaultConfig = func() Config {
MinResyncTimeout: config_types.Duration{Duration: 1 * time.Second},
MaxResyncTimeout: config_types.Duration{Duration: 20 * time.Second},
},
ControlPlane: &ControlPlaneMetrics{
ReportResourcesCount: true,
},
},
Reports: &Reports{
Enabled: false,
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ metrics:
minResyncTimeout: 1s # ENV: KUMA_METRICS_MESH_MIN_RESYNC_TIMEOUT
# Max time that MeshInsight could spend without resync
maxResyncTimeout: 20s # ENV: KUMA_METRICS_MESH_MAX_RESYNC_TIMEOUT
controlPlane:
# If true metrics show number of resources in the system should be reported
reportResourcesCount: true # ENV: KUMA_METRICS_CONTROL_PLANE_REPORT_RESOURCES_COUNT

# Reports configuration
reports:
Expand Down
4 changes: 4 additions & 0 deletions pkg/config/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ var _ = Describe("Config loader", func() {
Expect(cfg.Metrics.Mesh.MaxResyncTimeout.Duration).To(Equal(27 * time.Second))
Expect(cfg.Metrics.Dataplane.SubscriptionLimit).To(Equal(47))
Expect(cfg.Metrics.Dataplane.IdleTimeout.Duration).To(Equal(1 * time.Minute))
Expect(cfg.Metrics.ControlPlane.ReportResourcesCount).To(BeTrue())

Expect(cfg.DpServer.TlsCertFile).To(Equal("/test/path"))
Expect(cfg.DpServer.TlsKeyFile).To(Equal("/test/path/key"))
Expand Down Expand Up @@ -577,6 +578,8 @@ metrics:
dataplane:
subscriptionLimit: 47
idleTimeout: 1m
controlPlane:
reportResourcesCount: true
dpServer:
tlsCertFile: /test/path
tlsKeyFile: /test/path/key
Expand Down Expand Up @@ -837,6 +840,7 @@ proxy:
"KUMA_METRICS_MESH_MIN_RESYNC_TIMEOUT": "35s",
"KUMA_METRICS_DATAPLANE_SUBSCRIPTION_LIMIT": "47",
"KUMA_METRICS_DATAPLANE_IDLE_TIMEOUT": "1m",
"KUMA_METRICS_CONTROL_PLANE_REPORT_RESOURCES_COUNT": "true",
"KUMA_DP_SERVER_TLS_CERT_FILE": "/test/path",
"KUMA_DP_SERVER_TLS_KEY_FILE": "/test/path/key",
"KUMA_DP_SERVER_TLS_MIN_VERSION": "TLSv1_3",
Expand Down
15 changes: 9 additions & 6 deletions pkg/metrics/components/cp_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ func Setup(rt runtime.Runtime) error {
// We don't want to use cached ResourceManager because the cache is just for a couple of seconds
// and we will be retrieving resources every minute. There is no other place in the system for now that needs all resources from all meshes
// therefore it makes no sense to cache all content of the Database in the cache.
counter, err := metrics.NewStoreCounter(rt.ResourceManager(), rt.Metrics(), rt.Tenants())
if err != nil {
return err
}
if err := rt.Add(counter); err != nil {
return err
if rt.Config().Metrics.ControlPlane.ReportResourcesCount {
counter, err := metrics.NewStoreCounter(rt.ResourceManager(), rt.Metrics(), rt.Tenants())
if err != nil {
return err
}
if err := rt.Add(counter); err != nil {
return err
}
}

return nil
}

Expand Down