Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
thbkrkr committed Jul 7, 2021
1 parent 897e5f6 commit 9f9c07f
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 41 deletions.
12 changes: 6 additions & 6 deletions pkg/controller/common/stackmon/monitoring/monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/common/stackmon/name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions pkg/controller/common/stackmon/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/common/stackmon/validations/validations.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/elasticsearch/stackmon/beat_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/elasticsearch/stackmon/es_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/elasticsearch/stackmon/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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())

Expand Down
16 changes: 8 additions & 8 deletions pkg/controller/elasticsearch/stackmon/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/kibana/stackmon/beat_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/kibana/stackmon/kb_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{}
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/kibana/stackmon/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/controller/kibana/stackmon/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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))
Expand Down

0 comments on commit 9f9c07f

Please sign in to comment.