diff --git a/pkg/controller/common/stackmon/monitoring/monitoring.go b/pkg/controller/common/stackmon/monitoring/monitoring.go index d8fef7ac2c7..1dd4122b1c4 100644 --- a/pkg/controller/common/stackmon/monitoring/monitoring.go +++ b/pkg/controller/common/stackmon/monitoring/monitoring.go @@ -20,15 +20,15 @@ type HasMonitoring interface { MonitoringAssociation(ref commonv1.ObjectSelector) commonv1.Association } -func IsMonitoringDefined(resource HasMonitoring) bool { - return IsMonitoringMetricsDefined(resource) || IsMonitoringLogsDefined(resource) +func IsDefined(resource HasMonitoring) bool { + return IsMetricsDefined(resource) || IsLogsDefined(resource) } -func IsMonitoringMetricsDefined(resource HasMonitoring) bool { +func IsMetricsDefined(resource HasMonitoring) bool { return AreEsRefsDefined(resource.GetMonitoringMetricsRefs()) } -func IsMonitoringLogsDefined(resource HasMonitoring) bool { +func IsLogsDefined(resource HasMonitoring) bool { return AreEsRefsDefined(resource.GetMonitoringLogsRefs()) } @@ -41,7 +41,7 @@ func AreEsRefsDefined(esRefs []commonv1.ObjectSelector) bool { return len(esRefs) > 0 } -func GetMonitoringMetricsAssociation(resource HasMonitoring) []commonv1.Association { +func GetMetricsAssociation(resource HasMonitoring) []commonv1.Association { associations := make([]commonv1.Association, 0) for _, ref := range resource.GetMonitoringMetricsRefs() { if ref.IsDefined() { @@ -51,7 +51,7 @@ func GetMonitoringMetricsAssociation(resource HasMonitoring) []commonv1.Associat return associations } -func GetMonitoringLogsAssociation(resource HasMonitoring) []commonv1.Association { +func GetLogsAssociation(resource HasMonitoring) []commonv1.Association { associations := make([]commonv1.Association, 0) for _, ref := range resource.GetMonitoringLogsRefs() { if ref.IsDefined() { diff --git a/pkg/controller/common/stackmon/name_test.go b/pkg/controller/common/stackmon/name_test.go index cfcf3b8d38d..6f05a9ab811 100644 --- a/pkg/controller/common/stackmon/name_test.go +++ b/pkg/controller/common/stackmon/name_test.go @@ -46,16 +46,16 @@ func TestCAVolumeName(t *testing.T) { }, } - name := caVolumeName(monitoring.GetMonitoringMetricsAssociation(&es)[0]) + name := caVolumeName(monitoring.GetMetricsAssociation(&es)[0]) assert.LessOrEqual(t, len(name), maxVolumeNameLength) assert.Equal(t, "es-monitoring-954c60-ca", name) - name = caVolumeName(monitoring.GetMonitoringLogsAssociation(&es)[0]) + name = caVolumeName(monitoring.GetLogsAssociation(&es)[0]) assert.LessOrEqual(t, len(name), maxVolumeNameLength) assert.Equal(t, "es-monitoring-954c60-ca", name) es.Spec.Monitoring.Logs.ElasticsearchRefs[0].Name = "another-name" - newName := caVolumeName(monitoring.GetMonitoringLogsAssociation(&es)[0]) + newName := caVolumeName(monitoring.GetLogsAssociation(&es)[0]) assert.NotEqual(t, name, newName) assert.Equal(t, "es-monitoring-ae0f57-ca", newName) } diff --git a/pkg/controller/common/stackmon/sidecar.go b/pkg/controller/common/stackmon/sidecar.go index fd62c4115e4..2f07bda1c90 100644 --- a/pkg/controller/common/stackmon/sidecar.go +++ b/pkg/controller/common/stackmon/sidecar.go @@ -44,12 +44,12 @@ func NewMetricBeatSidecar( return BeatSidecar{}, err } image := container.ImageRepository(container.MetricbeatImage, version) - return NewBeatSidecar(client, "metricbeat", image, resource, monitoring.GetMonitoringMetricsAssociation(resource), baseConfig, sourceCaVolume) + return NewBeatSidecar(client, "metricbeat", image, resource, monitoring.GetMetricsAssociation(resource), baseConfig, sourceCaVolume) } func NewFileBeatSidecar(client k8s.Client, resource monitoring.HasMonitoring, version string, baseConfig string, additionalVolume volume.VolumeLike) (BeatSidecar, error) { image := container.ImageRepository(container.FilebeatImage, version) - return NewBeatSidecar(client, "filebeat", image, resource, monitoring.GetMonitoringLogsAssociation(resource), baseConfig, additionalVolume) + return NewBeatSidecar(client, "filebeat", image, resource, monitoring.GetLogsAssociation(resource), baseConfig, additionalVolume) } // BeatSidecar helps with building a beat sidecar container to monitor an Elastic Stack application. It focuses on diff --git a/pkg/controller/common/stackmon/validations/validations.go b/pkg/controller/common/stackmon/validations/validations.go index a388aaae45a..3d14b849db1 100644 --- a/pkg/controller/common/stackmon/validations/validations.go +++ b/pkg/controller/common/stackmon/validations/validations.go @@ -28,7 +28,7 @@ var ( // Elasticsearch reference defined to send monitoring data when Stack Monitoring is defined func Validate(resource monitoring.HasMonitoring, version string) field.ErrorList { var errs field.ErrorList - if monitoring.IsMonitoringDefined(resource) { + if monitoring.IsDefined(resource) { err := IsSupportedVersion(version) if err != nil { errs = append(errs, field.Invalid(field.NewPath("spec").Child("version"), version, diff --git a/pkg/controller/elasticsearch/stackmon/beat_config.go b/pkg/controller/elasticsearch/stackmon/beat_config.go index ada45d52e7d..7d8692eb620 100644 --- a/pkg/controller/elasticsearch/stackmon/beat_config.go +++ b/pkg/controller/elasticsearch/stackmon/beat_config.go @@ -25,7 +25,7 @@ var ( // ReconcileConfigSecrets reconciles the secrets holding beats configuration func ReconcileConfigSecrets(client k8s.Client, es esv1.Elasticsearch) error { - if monitoring.IsMonitoringMetricsDefined(&es) { + if monitoring.IsMetricsDefined(&es) { b, err := Metricbeat(client, es) if err != nil { return err @@ -36,7 +36,7 @@ func ReconcileConfigSecrets(client k8s.Client, es esv1.Elasticsearch) error { } } - if monitoring.IsMonitoringLogsDefined(&es) { + if monitoring.IsLogsDefined(&es) { b, err := Filebeat(client, es) if err != nil { return err diff --git a/pkg/controller/elasticsearch/stackmon/es_config.go b/pkg/controller/elasticsearch/stackmon/es_config.go index 24aca0ffc28..5ef568f9c73 100644 --- a/pkg/controller/elasticsearch/stackmon/es_config.go +++ b/pkg/controller/elasticsearch/stackmon/es_config.go @@ -14,7 +14,7 @@ import ( // MonitoringConfig returns the Elasticsearch settings to enable the collection of monitoring data func MonitoringConfig(es esv1.Elasticsearch) commonv1.Config { - if !monitoring.IsMonitoringMetricsDefined(&es) { + if !monitoring.IsMetricsDefined(&es) { return commonv1.Config{} } return commonv1.Config{Data: map[string]interface{}{ diff --git a/pkg/controller/elasticsearch/stackmon/sidecar.go b/pkg/controller/elasticsearch/stackmon/sidecar.go index 16e295fc41c..c8364afecab 100644 --- a/pkg/controller/elasticsearch/stackmon/sidecar.go +++ b/pkg/controller/elasticsearch/stackmon/sidecar.go @@ -57,14 +57,14 @@ func Filebeat(client k8s.Client, es esv1.Elasticsearch) (stackmon.BeatSidecar, e // in the Elasticsearch pod and injects the volumes for the beat configurations and the ES CA certificates. func WithMonitoring(client k8s.Client, builder *defaults.PodTemplateBuilder, es esv1.Elasticsearch) (*defaults.PodTemplateBuilder, error) { // no monitoring defined, skip - if !monitoring.IsMonitoringDefined(&es) { + if !monitoring.IsDefined(&es) { return builder, nil } configHash := sha256.New224() volumes := make([]corev1.Volume, 0) - if monitoring.IsMonitoringMetricsDefined(&es) { + if monitoring.IsMetricsDefined(&es) { b, err := Metricbeat(client, es) if err != nil { return nil, err @@ -75,7 +75,7 @@ func WithMonitoring(client k8s.Client, builder *defaults.PodTemplateBuilder, es configHash.Write(b.ConfigHash.Sum(nil)) } - if monitoring.IsMonitoringLogsDefined(&es) { + if monitoring.IsLogsDefined(&es) { // enable Stack logging to write Elasticsearch logs to disk builder.WithEnv(fileLogStyleEnvVar()) diff --git a/pkg/controller/elasticsearch/stackmon/sidecar_test.go b/pkg/controller/elasticsearch/stackmon/sidecar_test.go index 99a76bdd90f..9960a7df571 100644 --- a/pkg/controller/elasticsearch/stackmon/sidecar_test.go +++ b/pkg/controller/elasticsearch/stackmon/sidecar_test.go @@ -85,7 +85,7 @@ func TestWithMonitoring(t *testing.T) { name: "with metrics monitoring", es: func() esv1.Elasticsearch { sampleEs.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringMetricsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetMetricsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) return sampleEs }, containersLength: 2, @@ -98,7 +98,7 @@ func TestWithMonitoring(t *testing.T) { es: func() esv1.Elasticsearch { sampleEs.Spec.Monitoring.Metrics.ElasticsearchRefs = nil sampleEs.Spec.Monitoring.Logs.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringLogsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetLogsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) return sampleEs }, containersLength: 2, @@ -110,9 +110,9 @@ func TestWithMonitoring(t *testing.T) { name: "with metrics and logs monitoring", es: func() esv1.Elasticsearch { sampleEs.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringMetricsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetMetricsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) sampleEs.Spec.Monitoring.Logs.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringLogsAssociation(&sampleEs)[0].SetAssociationConf(&logsAssocConf) + monitoring.GetLogsAssociation(&sampleEs)[0].SetAssociationConf(&logsAssocConf) return sampleEs }, containersLength: 3, @@ -124,9 +124,9 @@ func TestWithMonitoring(t *testing.T) { name: "with metrics and logs monitoring with different es ref", es: func() esv1.Elasticsearch { sampleEs.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringMetricsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetMetricsAssociation(&sampleEs)[0].SetAssociationConf(&monitoringAssocConf) sampleEs.Spec.Monitoring.Logs.ElasticsearchRefs = logsEsRef - monitoring.GetMonitoringLogsAssociation(&sampleEs)[0].SetAssociationConf(&logsAssocConf) + monitoring.GetLogsAssociation(&sampleEs)[0].SetAssociationConf(&logsAssocConf) return sampleEs }, containersLength: 3, @@ -147,14 +147,14 @@ func TestWithMonitoring(t *testing.T) { assert.Equal(t, tc.esEnvVarsLength, len(builder.PodTemplate.Spec.Containers[0].Env)) assert.Equal(t, tc.podVolumesLength, len(builder.PodTemplate.Spec.Volumes)) - if monitoring.IsMonitoringMetricsDefined(&es) { + if monitoring.IsMetricsDefined(&es) { for _, c := range builder.PodTemplate.Spec.Containers { if c.Name == "metricbeat" { assert.Equal(t, tc.beatVolumeMountsLength, len(c.VolumeMounts)) } } } - if monitoring.IsMonitoringLogsDefined(&es) { + if monitoring.IsLogsDefined(&es) { for _, c := range builder.PodTemplate.Spec.Containers { if c.Name == "filebeat" { assert.Equal(t, tc.beatVolumeMountsLength, len(c.VolumeMounts)) diff --git a/pkg/controller/kibana/stackmon/beat_config.go b/pkg/controller/kibana/stackmon/beat_config.go index 6bd7ff78e21..023fbd16730 100644 --- a/pkg/controller/kibana/stackmon/beat_config.go +++ b/pkg/controller/kibana/stackmon/beat_config.go @@ -25,7 +25,7 @@ var ( // ReconcileConfigSecrets reconciles the secrets holding beats configuration func ReconcileConfigSecrets(client k8s.Client, kb kbv1.Kibana) error { - if monitoring.IsMonitoringMetricsDefined(&kb) { + if monitoring.IsMetricsDefined(&kb) { b, err := Metricbeat(client, kb) if err != nil { return err @@ -36,7 +36,7 @@ func ReconcileConfigSecrets(client k8s.Client, kb kbv1.Kibana) error { } } - if monitoring.IsMonitoringLogsDefined(&kb) { + if monitoring.IsLogsDefined(&kb) { b, err := Filebeat(client, kb) if err != nil { return err diff --git a/pkg/controller/kibana/stackmon/kb_config.go b/pkg/controller/kibana/stackmon/kb_config.go index c1dfee1011b..656354ee1d5 100644 --- a/pkg/controller/kibana/stackmon/kb_config.go +++ b/pkg/controller/kibana/stackmon/kb_config.go @@ -27,13 +27,13 @@ var ( // MonitoringConfig returns the Kibana settings required to enable the collection of monitoring data and disk logging func MonitoringConfig(kb kbv1.Kibana) commonv1.Config { cfg := commonv1.Config{} - if monitoring.IsMonitoringMetricsDefined(&kb) { + if monitoring.IsMetricsDefined(&kb) { if cfg.Data == nil { cfg.Data = map[string]interface{}{} } cfg.Data[MonitoringKibanaCollectionEnabled] = false } - if monitoring.IsMonitoringLogsDefined(&kb) { + if monitoring.IsLogsDefined(&kb) { if cfg.Data == nil { cfg.Data = map[string]interface{}{} } diff --git a/pkg/controller/kibana/stackmon/sidecar.go b/pkg/controller/kibana/stackmon/sidecar.go index 17d57cf4589..1d3bfbefe29 100644 --- a/pkg/controller/kibana/stackmon/sidecar.go +++ b/pkg/controller/kibana/stackmon/sidecar.go @@ -61,14 +61,14 @@ func Filebeat(client k8s.Client, kb kbv1.Kibana) (stackmon.BeatSidecar, error) { // in the Elasticsearch pod and injects the volumes for the beat configurations and the ES CA certificates. func WithMonitoring(client k8s.Client, builder *defaults.PodTemplateBuilder, kb kbv1.Kibana) (*defaults.PodTemplateBuilder, error) { // no monitoring defined, skip - if !monitoring.IsMonitoringDefined(&kb) { + if !monitoring.IsDefined(&kb) { return builder, nil } configHash := sha256.New224() volumes := make([]corev1.Volume, 0) - if monitoring.IsMonitoringMetricsDefined(&kb) { + if monitoring.IsMetricsDefined(&kb) { b, err := Metricbeat(client, kb) if err != nil { return nil, err @@ -79,7 +79,7 @@ func WithMonitoring(client k8s.Client, builder *defaults.PodTemplateBuilder, kb configHash.Write(b.ConfigHash.Sum(nil)) } - if monitoring.IsMonitoringLogsDefined(&kb) { + if monitoring.IsLogsDefined(&kb) { b, err := Filebeat(client, kb) if err != nil { return nil, err diff --git a/pkg/controller/kibana/stackmon/sidecar_test.go b/pkg/controller/kibana/stackmon/sidecar_test.go index 42b3eace82f..bebc4284690 100644 --- a/pkg/controller/kibana/stackmon/sidecar_test.go +++ b/pkg/controller/kibana/stackmon/sidecar_test.go @@ -87,7 +87,7 @@ func TestWithMonitoring(t *testing.T) { name: "with metrics monitoring", kb: func() kbv1.Kibana { sampleKb.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringMetricsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetMetricsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) return sampleKb }, containersLength: 2, @@ -99,7 +99,7 @@ func TestWithMonitoring(t *testing.T) { kb: func() kbv1.Kibana { sampleKb.Spec.Monitoring.Metrics.ElasticsearchRefs = nil sampleKb.Spec.Monitoring.Logs.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringLogsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetLogsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) return sampleKb }, containersLength: 2, @@ -110,9 +110,9 @@ func TestWithMonitoring(t *testing.T) { name: "with metrics and logs monitoring", kb: func() kbv1.Kibana { sampleKb.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringMetricsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetMetricsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) sampleKb.Spec.Monitoring.Logs.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringLogsAssociation(&sampleKb)[0].SetAssociationConf(&logsAssocConf) + monitoring.GetLogsAssociation(&sampleKb)[0].SetAssociationConf(&logsAssocConf) return sampleKb }, containersLength: 3, @@ -123,9 +123,9 @@ func TestWithMonitoring(t *testing.T) { name: "with metrics and logs monitoring with different es ref", kb: func() kbv1.Kibana { sampleKb.Spec.Monitoring.Metrics.ElasticsearchRefs = monitoringEsRef - monitoring.GetMonitoringMetricsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) + monitoring.GetMetricsAssociation(&sampleKb)[0].SetAssociationConf(&monitoringAssocConf) sampleKb.Spec.Monitoring.Logs.ElasticsearchRefs = logsEsRef - monitoring.GetMonitoringLogsAssociation(&sampleKb)[0].SetAssociationConf(&logsAssocConf) + monitoring.GetLogsAssociation(&sampleKb)[0].SetAssociationConf(&logsAssocConf) return sampleKb }, containersLength: 3, @@ -147,14 +147,14 @@ func TestWithMonitoring(t *testing.T) { } assert.Equal(t, tc.podVolumesLength, len(builder.PodTemplate.Spec.Volumes)) - if monitoring.IsMonitoringMetricsDefined(&kb) { + if monitoring.IsMetricsDefined(&kb) { for _, c := range builder.PodTemplate.Spec.Containers { if c.Name == "metricbeat" { assert.Equal(t, tc.beatVolumeMountsLength, len(c.VolumeMounts)) } } } - if monitoring.IsMonitoringLogsDefined(&kb) { + if monitoring.IsLogsDefined(&kb) { for _, c := range builder.PodTemplate.Spec.Containers { if c.Name == "filebeat" { assert.Equal(t, tc.beatVolumeMountsLength, len(c.VolumeMounts))