From b6c2e56b7002fc7909731e6f32f3eb4ebf2988c8 Mon Sep 17 00:00:00 2001 From: Rene Dekker Date: Wed, 17 Jun 2020 10:51:32 -0700 Subject: [PATCH] Upgrade the default resource settings for Elastic --- pkg/render/logstorage.go | 26 +++++++++----------------- pkg/render/logstorage_test.go | 28 +++++++++++++++------------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/pkg/render/logstorage.go b/pkg/render/logstorage.go index 8978b3bb53..e3ac76297d 100644 --- a/pkg/render/logstorage.go +++ b/pkg/render/logstorage.go @@ -345,33 +345,25 @@ func (es elasticsearchComponent) pvcTemplate() corev1.PersistentVolumeClaim { // Generate the pod template required for the ElasticSearch nodes (controls the ElasticSearch container) func (es elasticsearchComponent) podTemplate() corev1.PodTemplateSpec { - // Setup default configuration for ES container + // Setup default configuration for ES container. For more information on managing resources, see: + // https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html and + // https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-jvm-heap-size.html#k8s-jvm-heap-size + esContainer := corev1.Container{ Name: "elasticsearch", - // Important note: Following Elastic ECK docs, the recommended practice is to set - // request and limit for memory to the same value: - // https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html#k8s-compute-resources-elasticsearch - // - // Default values for memory request and limit taken from ECK docs: - // https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html#k8s-default-behavior Resources: corev1.ResourceRequirements{ Limits: corev1.ResourceList{ "cpu": resource.MustParse("1"), - "memory": resource.MustParse("2Gi"), + "memory": resource.MustParse("4Gi"), }, Requests: corev1.ResourceList{ - "cpu": resource.MustParse("1"), - "memory": resource.MustParse("2Gi"), + "cpu": resource.MustParse("250m"), + "memory": resource.MustParse("4Gi"), }, }, Env: []corev1.EnvVar{ - // Important note: Following Elastic ECK docs, the recommendation is to set - // the Java heap size to half the size of RAM allocated to the Pod: - // https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-managing-compute-resources.html#k8s-compute-resources-elasticsearch - // - // Default values for Java Heap min and max taken from ECK docs: - // https://www.elastic.co/guide/en/cloud-on-k8s/current/k8s-jvm-heap-size.html#k8s-jvm-heap-size - {Name: "ES_JAVA_OPTS", Value: "-Xms1G -Xmx1G"}, + // Set to 30% of the default memory, such that resources can be divided over ES, Lucene and ML. + {Name: "ES_JAVA_OPTS", Value: "-Xms1398101K -Xmx1398101K"}, }, } diff --git a/pkg/render/logstorage_test.go b/pkg/render/logstorage_test.go index 2a53aff8ab..1b7d35f661 100644 --- a/pkg/render/logstorage_test.go +++ b/pkg/render/logstorage_test.go @@ -133,8 +133,22 @@ var _ = Describe("Elasticsearch rendering tests", func() { compareResources(createResources, expectedCreateResources) compareResources(deleteResources, []resourceTestObj{}) + resultES := GetResource(createResources, render.ElasticsearchName, render.ElasticsearchNamespace, + "elasticsearch.k8s.elastic.co", "v1", "Elasticsearch").(*esv1.Elasticsearch) + // There are no node selectors in the LogStorage CR, so we expect no node selectors in the Elasticsearch CR. - Expect(createResources[15].(*esv1.Elasticsearch).Spec.NodeSets[0].PodTemplate.Spec.NodeSelector).To(BeEmpty()) + Expect(resultES.Spec.NodeSets[0].PodTemplate.Spec.NodeSelector).To(BeEmpty()) + + // Verify that the default container limist/requests are set. + esContainer := resultES.Spec.NodeSets[0].PodTemplate.Spec.Containers[0] + limits := esContainer.Resources.Limits + resources := esContainer.Resources.Requests + + Expect(limits.Cpu().String()).To(Equal("1")) + Expect(limits.Memory().String()).To(Equal("4Gi")) + Expect(resources.Cpu().String()).To(Equal("250m")) + Expect(resources.Memory().String()).To(Equal("4Gi")) + Expect(esContainer.Env[0].Value).To(Equal("-Xms1398101K -Xmx1398101K")) }) It("should render an elasticsearchComponent and delete the Elasticsearch and Kibana ExternalService", func() { expectedCreateResources := []resourceTestObj{ @@ -289,18 +303,6 @@ var _ = Describe("Elasticsearch rendering tests", func() { }, }, }, - Indices: &operator.Indices{ - Replicas: &replicas, - }, - Retention: &operatorv1.Retention{ - Flows: &retention, - AuditReports: &retention, - Snapshots: &retention, - ComplianceReports: &retention, - }, - }, - Status: operator.LogStorageStatus{ - State: "", }, }