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

Allow Beats stack monitoring w/o elasticseachRef #8273

Merged
merged 1 commit into from
Nov 29, 2024
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
Allow stack monitoring w/o elasticseachRef
  • Loading branch information
pebrc committed Nov 28, 2024
commit 8f5851808576bbdd45c07708bf18b5b721268725
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