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
6 changes: 5 additions & 1 deletion pkg/controller/beat/common/stackmon/metricbeat.tpl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ metricbeat.modules:
xpack.enabled: true
http.enabled: false
monitoring.enabled: false
monitoring.cluster_uuid: "{{ .ClusterUUID }}"
# if no associated Elasticsearch cluster UUID known or determinable,
# monitored application will be treated as stand-alone without cluster_uuid.
{{ with .ClusterUUID -}}
monitoring.cluster_uuid: "{{ . }}"
{{- end}}

# Elasticsearch output configuration is generated and added here
4 changes: 4 additions & 0 deletions pkg/controller/beat/common/stackmon/stackmon.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ type clusterUUIDResponse struct {
func associatedESUUID(ctx context.Context, client k8s.Client, beat *v1beta1.Beat) (string, error) {
esAssociation := beat.EsAssociation()
esRef := esAssociation.AssociationRef()
if !esRef.IsDefined() {
// no association or indirect association e.g. via output configuration
return "", nil
}
if esRef.IsExternal() {
remoteES, err := association.GetUnmanagedAssociationConnectionInfoFromSecret(client, esAssociation)
if err != nil {
Expand Down
41 changes: 41 additions & 0 deletions pkg/controller/beat/common/stackmon/stackmon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,30 @@ output:
ssl:
verification_mode: certificate
username: es-user
`
standaloneBeatYML := `http:
enabled: false
metricbeat:
modules:
- hosts:
- http+unix:///var/shared/metricbeat-test-beat.sock
metricsets:
- stats
- state
module: beat
period: 10s
xpack:
enabled: true
monitoring:
enabled: false
output:
elasticsearch:
hosts:
- es-metrics-monitoring-url
password: es-password
ssl:
verification_mode: certificate
username: es-user
`
beatSidecarFixture := func(beatYml string) stackmon.BeatSidecar {
return stackmon.BeatSidecar{
Expand Down Expand Up @@ -251,6 +275,23 @@ output:
want: beatSidecarFixture(fmt.Sprintf(beatYml, "abcd1234", "es-metrics-monitoring-url")),
wantErr: false,
},
{
name: "beat with stack monitoring enabled and no elasticsearchRef returns configured sidecar",
args: args{
client: k8s.NewFakeClient(&beatFixture, &esFixture, &monitoringEsFixture, &corev1.Secret{
ObjectMeta: metav1.ObjectMeta{Name: "es-secret-name", Namespace: "test"},
Data: map[string][]byte{"es-user": []byte("es-password")},
}),
beat: func() *v1beta1.Beat {
beat := beatFixture.DeepCopy()
beat.Spec.ElasticsearchRef = commonv1.ObjectSelector{}
return beat
},
version: "8.2.3",
},
want: beatSidecarFixture(standaloneBeatYML),
wantErr: false,
},
{
name: "Beat with stack monitoring enabled and remote elasticsearchRef",
args: args{
Expand Down