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

Commit

Permalink
Custom Cassandra YAML and JVM options. (#9)
Browse files Browse the repository at this point in the history
* Add test for custom jvm.options.

* Custom Cassandra YAML and JVM options improvements. (#20)

* The KUDO dependency updated, reflect that.
  • Loading branch information
Pavel Hrynchanka authored and mpereira committed Nov 8, 2019
1 parent 4a760ef commit 46fc04b
Show file tree
Hide file tree
Showing 7 changed files with 203 additions and 10 deletions.
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"
)

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(
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

0 comments on commit 46fc04b

Please sign in to comment.