Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Custom Cassandra YAML and JVM options. #9

Merged
merged 11 commits into from
Nov 8, 2019
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
8 changes: 8 additions & 0 deletions operator/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,10 @@ parameters:
description: "How many milliseconds to wait between two expiration runs on the backlog (queue) of the OutboundTcpConnection."
default: ""

- name: CUSTOM_CASSANDRA_YAML_BASE64
description: "Base64-encoded Cassandra properties appended to cassandra.yaml."
default: ""

################################################################################
################################ JVM Options ###################################
################################################################################
Expand Down Expand Up @@ -766,3 +770,7 @@ parameters:
- name: JVM_OPT_G1R_SET_UPDATING_PAUSE_TIME_PERCENT
description: "Have the JVM do less remembered set work during STW, instead preferring concurrent GC. Reduces p99.9 latency."
default: ""

- name: CUSTOM_JVM_OPTIONS_BASE64
description: "Base64-encoded JVM options appended to jvm.options."
default: ""
4 changes: 4 additions & 0 deletions operator/templates/cassandra-yaml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1352,3 +1352,7 @@ data:
{{ if .Params.OTC_BACKLOG_EXPIRATION_INTERVAL_MS }}
otc_backlog_expiration_interval_ms: {{ .Params.OTC_BACKLOG_EXPIRATION_INTERVAL_MS }}
{{ end }}

{{ if .Params.CUSTOM_CASSANDRA_YAML_BASE64 }}
{{ .Params.CUSTOM_CASSANDRA_YAML_BASE64 | b64dec }}
{{ end }}
4 changes: 4 additions & 0 deletions operator/templates/jvm-options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,7 @@ data:
### Cassandra 4.0 which will use JDK 11.
-XX:+UnlockExperimentalVMOptions
-XX:+UseCGroupMemoryLimitForHeap

{{ if .Params.CUSTOM_JVM_OPTIONS_BASE64 }}
{{ .Params.CUSTOM_JVM_OPTIONS_BASE64 | b64dec }}
{{ end }}
2 changes: 1 addition & 1 deletion tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.13
require (
github.com/avast/retry-go v2.4.1+incompatible
github.com/imdario/mergo v0.3.8 // indirect
github.com/kudobuilder/kudo v0.8.0-pre.2
github.com/kudobuilder/kudo v0.8.0-pre.3
github.com/mitchellh/go-homedir v1.1.0
github.com/onsi/ginkgo v1.10.1
github.com/onsi/gomega v1.7.0
Expand Down
96 changes: 96 additions & 0 deletions tests/go.sum

Large diffs are not rendered by default.

66 changes: 62 additions & 4 deletions tests/suites/sanity_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package suites

import (
"encoding/base64"
"fmt"
"os"
"strings"
Expand All @@ -12,10 +13,10 @@ import (

// log "github.com/sirupsen/logrus"

cassandra "github.com/mesosphere/kudo-cassandra-operator/tests/utils/cassandra"
k8s "github.com/mesosphere/kudo-cassandra-operator/tests/utils/k8s"
kubectl "github.com/mesosphere/kudo-cassandra-operator/tests/utils/kubectl"
kudo "github.com/mesosphere/kudo-cassandra-operator/tests/utils/kudo"
"github.com/mesosphere/kudo-cassandra-operator/tests/utils/cassandra"
"github.com/mesosphere/kudo-cassandra-operator/tests/utils/k8s"
"github.com/mesosphere/kudo-cassandra-operator/tests/utils/kubectl"
"github.com/mesosphere/kudo-cassandra-operator/tests/utils/kudo"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious about this change.

)

var (
Expand Down Expand Up @@ -85,6 +86,63 @@ var _ = Describe(TestName, func() {
Expect(configuration[parameter]).To(Equal(desiredValue))
})

It("Configures Cassandra properties through custom properties", func() {
parameter := "otc_backlog_expiration_interval_ms"
initialValue := "200"
desiredValue := "300"
desiredEncodedProperties := base64.StdEncoding.EncodeToString(
[]byte(parameter + ": " + desiredValue),
)

configuration, err := cassandra.ClusterConfiguration(
TestNamespace, TestInstance,
)
Expect(err).To(BeNil())
Expect(configuration[parameter]).To(Equal(initialValue))

err = kudo.UpdateInstanceParameters(
TestNamespace,
TestInstance,
map[string]string{"CUSTOM_CASSANDRA_YAML_BASE64": desiredEncodedProperties},
)
Expect(err).To(BeNil())

configuration, err = cassandra.ClusterConfiguration(
TestNamespace, TestInstance,
)
Expect(err).To(BeNil())
Expect(configuration[parameter]).To(Equal(desiredValue))
})

It("Configures Cassandra JVM options through custom options", func() {
parameter := "-XX:CMSWaitDuration"
initialValue := "10000"
desiredValue := "11000"
desiredEncodedProperties := base64.StdEncoding.EncodeToString(
[]byte(parameter + "=" + desiredValue),
)

configuration, err := cassandra.NodeJvmOptions(
TestNamespace, TestInstance,
)

Expect(err).To(BeNil())
Expect(configuration[parameter]).To(Equal(initialValue))

err = kudo.UpdateInstanceParameters(
TestNamespace,
TestInstance,
map[string]string{"CUSTOM_JVM_OPTIONS_BASE64": desiredEncodedProperties},
)
Expect(err).To(BeNil())

configuration, err = cassandra.NodeJvmOptions(
TestNamespace, TestInstance,
)
Expect(err).To(BeNil())
Expect(configuration[parameter]).To(Equal(desiredValue))
})

It("Uninstalls the operator", func() {
err := kudo.UninstallOperator(OperatorName, TestNamespace, TestInstance)
Expect(err).To(BeNil())
Expand Down
33 changes: 28 additions & 5 deletions tests/utils/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,36 @@ import (

log "github.com/sirupsen/logrus"

kudo "github.com/mesosphere/kudo-cassandra-operator/tests/utils/kudo"
"github.com/mesosphere/kudo-cassandra-operator/tests/utils/kudo"
)

func ClusterConfiguration(
namespaceName string, instanceName string,
) (map[string]string, error) {
return getConfigurationFromNodeLogs(
namespaceName,
instanceName,
"org.apache.cassandra.config.Config - Node configuration:\\[(.+)\\]",
";",
)
}

func NodeJvmOptions(
namespaceName string, instanceName string,
) (map[string]string, error) {
return getConfigurationFromNodeLogs(
namespaceName,
instanceName,
"o.a.c.service.CassandraDaemon - JVM Arguments: \\[(.+)\\]",
",",
)
}

func getConfigurationFromNodeLogs(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice approach.

namespaceName string,
instanceName string,
regexpr string,
separator string,
) (map[string]string, error) {
configuration := make(map[string]string)

Expand All @@ -27,9 +52,7 @@ func ClusterConfiguration(
}

scanner := bufio.NewScanner(logs)
configurationLinePattern := regexp.MustCompile(
"org.apache.cassandra.config.Config - Node configuration:\\[(.+)\\]",
)
configurationLinePattern := regexp.MustCompile(regexpr)
var configurationLine string
for scanner.Scan() {
match := configurationLinePattern.FindStringSubmatch(scanner.Text())
Expand All @@ -47,7 +70,7 @@ func ClusterConfiguration(
return configuration, err
}

for _, kv := range strings.Split(configurationLine, ";") {
for _, kv := range strings.Split(configurationLine, separator) {
parts := strings.Split(strings.TrimSpace(kv), "=")
if len(parts) == 2 {
configuration[parts[0]] = parts[1]
Expand Down