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

Commit

Permalink
Custom Prometheus exporter configuration (#93)
Browse files Browse the repository at this point in the history
* Updated operator to accept custom exporter config

Co-authored-by: Andreas Neumann <[email protected]>
Signed-off-by: Andreas Neumann <[email protected]>
  • Loading branch information
shubhanilBag and ANeumann82 authored May 12, 2020
1 parent 27a703b commit 14f5fe6
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 4 deletions.
46 changes: 46 additions & 0 deletions docs/monitoring.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,49 @@ to check the `Prometheus` resource. The `serviceMonitorNamespaceSelector` and
match the
[labels on the `ServiceMonitor` resource](../operator/templates/service-monitor.yaml#L7)
created by the KUDO Cassandra operator.

## Custom Configuration

To use the custom
[prometheus exporter configuration](https://github.com/criteo/cassandra_exporter#config-file-example),
we need to create a configmap with the properties we want to override.

Example custom configuration:

```
apiVersion: v1
kind: ConfigMap
metadata:
name: custom-exporter-configuration
data:
config.yml: |
maxScrapFrequencyInSec:
2000:
- .*:totaldiskspaceused:.*
```

Create the ConfigMap in the namespace we will have the KUDO Cassandra cluster

```
$ kubectl create -f custom-exporter-configuration.yaml -n $namespace_name
configmap/custom-exporter-configuration created
```

Enable the exporter

```bash
kubectl kudo update \
-p PROMETHEUS_EXPORTER_ENABLED=true \
-p PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME=custom-exporter-configuration \
--instance $instance_name -n $namespace_name
```

:warning: The following properties are configured internally by the operator and
cannot be overridden using custom configuration:

- host
- listenAddress
- listenPort
- user
- password
- ssl
1 change: 1 addition & 0 deletions docs/parameters.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
| **PROMETHEUS_EXPORTER_MEM_LIMIT_MIB** | Memory limit (in MiB) for the Prometheus exporter containers. | 512 |
| **PROMETHEUS_EXPORTER_DOCKER_IMAGE** | Prometheus exporter Docker image. | mesosphere/cassandra-prometheus-exporter:2.3.4-0.1.2-SNAPSHOT |
| **PROMETHEUS_EXPORTER_DOCKER_IMAGE_PULL_POLICY** | Prometheus exporter Docker image pull policy. | Always |
| **PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME** | The properties present in this configmap will be appended to the prometheus configuration properties | |
| **STORAGE_PORT** | The port for inter-node communication. | 7000 |
| **SSL_STORAGE_PORT** | The port for inter-node communication over SSL. | 7001 |
| **NATIVE_TRANSPORT_PORT** | The port for CQL communication. | 9042 |
Expand Down
5 changes: 5 additions & 0 deletions operator/params.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ parameters:
description: "Prometheus exporter Docker image pull policy."
default: "Always"

- name: PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME
displayName: "custom prometheus configuration configmap name"
description: "The properties present in this configmap will be appended to the prometheus configuration properties"
required: false

################################################################################
########################### Cassandra node settings ############################
################################################################################
Expand Down
18 changes: 18 additions & 0 deletions operator/templates/cassandra-exporter-config-yml.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ metadata:
name: {{ .Name }}-cassandra-exporter-config-yml
namespace: {{ .Namespace }}
data:
setup.sh: |
cp /cassandra-exporter-config/config.yml /etc/cassandra_exporter/config.yml;
{{ if .Params.PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME }}
PROMETHEUS_CUSTOM_CONFIGURATION_FILE=$(ls -d /custom-configuration/* | head -n 1);
cp $PROMETHEUS_CUSTOM_CONFIGURATION_FILE /tmp/custom-configuration;
echo "Appending custom configuration file to the config.yml..." | xargs -L 1 echo $(date +'[%Y-%m-%d %H:%M:%S,%3N]') $1;
skip_properties=("host" "listenAddress" "listenPort" "user" "password" "ssl");
for property in "${skip_properties[@]}"; do
if grep -q "${property}:" /tmp/custom-configuration; then
echo "WARN: cannot override '$property' using custom properties configmap.";
echo "Removing property '$property'";
sed -i "/^${property}:/d" /tmp/custom-configuration;
fi;
done;
CUSTOM_CONFIGURATION=$(cat /tmp/custom-configuration);
echo ${CUSTOM_CONFIGURATION};
printf "\n${CUSTOM_CONFIGURATION}" >> /etc/cassandra_exporter/config.yml;
{{ end }}
config.yml: |
host: localhost:{{ .Params.JMX_PORT }}
{{ if ne $.Params.JMX_LOCAL_ONLY "true" }}
Expand Down
18 changes: 16 additions & 2 deletions operator/templates/stateful-set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ spec:
JVM_OPTS="${JVM_OPTS} $flag";
done < /etc/cassandra/nodetool-ssl.properties;
{{ end }}
bash -c /cassandra-exporter-config/setup.sh;
JVM_OPTS="${JVM_OPTS}" /sbin/dumb-init /bin/bash /run.sh;
env:
- name: NODE_NAME
Expand Down Expand Up @@ -324,16 +325,21 @@ spec:
memory: "{{ $.Params.PROMETHEUS_EXPORTER_MEM_LIMIT_MIB }}Mi"
cpu: "{{ $.Params.PROMETHEUS_EXPORTER_CPU_LIMIT_MC }}m"
volumeMounts:
- name: etc-cassandra-exporter
mountPath: /etc/cassandra_exporter/
- name: cassandra-exporter-config-yml
mountPath: /etc/cassandra_exporter/config.yml
subPath: config.yml
mountPath: /cassandra-exporter-config/
{{ if ne $.Params.JMX_LOCAL_ONLY "true" }}
- name: etc-cassandra
mountPath: /etc/cassandra/
- name: generate-nodetool-ssl-properties
mountPath: /etc/cassandra/generate-nodetool-ssl-properties.sh
subPath: generate-nodetool-ssl-properties.sh
{{ end }}
{{ if $.Params.PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME }}
- name: custom-exporter-configuration
mountPath: /custom-configuration
{{ end }}
{{ end }}
{{ if eq $.Params.BACKUP_RESTORE_ENABLED "true" }}
- name: medusa-backup
Expand Down Expand Up @@ -642,6 +648,14 @@ spec:
- name: cassandra-exporter-config-yml
configMap:
name: {{ $.Name }}-cassandra-exporter-config-yml
defaultMode: 0755
- name: etc-cassandra-exporter
emptyDir: {}
{{ if $.Params.PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME }}
- name: custom-exporter-configuration
configMap:
name: {{ $.Params.PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME }}
{{ end }}
{{ end }}
{{ if eq $.Params.BACKUP_RESTORE_ENABLED "true" }}
- name: etc-medusa
Expand Down
5 changes: 5 additions & 0 deletions templates/operator/params.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ parameters:
description: "Prometheus exporter Docker image pull policy."
default: "Always"

- name: PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME
displayName: "custom prometheus configuration configmap name"
description: "The properties present in this configmap will be appended to the prometheus configuration properties"
required: false

################################################################################
########################### Cassandra node settings ############################
################################################################################
Expand Down
18 changes: 16 additions & 2 deletions templates/operator/templates/stateful-set.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ spec:
JVM_OPTS="${JVM_OPTS} $flag";
done < /etc/cassandra/nodetool-ssl.properties;
{{ end }}
bash -c /cassandra-exporter-config/setup.sh;
JVM_OPTS="${JVM_OPTS}" /sbin/dumb-init /bin/bash /run.sh;
env:
- name: NODE_NAME
Expand Down Expand Up @@ -324,16 +325,21 @@ spec:
memory: "{{ $.Params.PROMETHEUS_EXPORTER_MEM_LIMIT_MIB }}Mi"
cpu: "{{ $.Params.PROMETHEUS_EXPORTER_CPU_LIMIT_MC }}m"
volumeMounts:
- name: etc-cassandra-exporter
mountPath: /etc/cassandra_exporter/
- name: cassandra-exporter-config-yml
mountPath: /etc/cassandra_exporter/config.yml
subPath: config.yml
mountPath: /cassandra-exporter-config/
{{ if ne $.Params.JMX_LOCAL_ONLY "true" }}
- name: etc-cassandra
mountPath: /etc/cassandra/
- name: generate-nodetool-ssl-properties
mountPath: /etc/cassandra/generate-nodetool-ssl-properties.sh
subPath: generate-nodetool-ssl-properties.sh
{{ end }}
{{ if $.Params.PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME }}
- name: custom-exporter-configuration
mountPath: /custom-configuration
{{ end }}
{{ end }}
{{ if eq $.Params.BACKUP_RESTORE_ENABLED "true" }}
- name: medusa-backup
Expand Down Expand Up @@ -642,6 +648,14 @@ spec:
- name: cassandra-exporter-config-yml
configMap:
name: {{ $.Name }}-cassandra-exporter-config-yml
defaultMode: 0755
- name: etc-cassandra-exporter
emptyDir: {}
{{ if $.Params.PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME }}
- name: custom-exporter-configuration
configMap:
name: {{ $.Params.PROMETHEUS_EXPORTER_CUSTOM_CONFIG_CM_NAME }}
{{ end }}
{{ end }}
{{ if eq $.Params.BACKUP_RESTORE_ENABLED "true" }}
- name: etc-medusa
Expand Down

0 comments on commit 14f5fe6

Please sign in to comment.