# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

public_url: "https://cloud.google.com/stackdriver/docs/solutions/agents/ops-agent/third-party/cassandra"
app_url: "http://cassandra.apache.org/"
short_name: Cassandra
long_name: Apache Cassandra
logo_path: /stackdriver/images/cassandra.png # supplied by google technical writer
description: |-
  The Apache Cassandra integration collects request, task, and storage metrics
  that highlight the load on an instance. Optionally, the integration can also
  collect general JVM metrics related to memory and garbage collection. The
  integration also collects system, debug, and garbage-collection logs. These logs
  are parsed into a JSON payload, which includes fields for the message, Java
  class, and line number.
configure_integration: |-
  To expose a JMX endpoint, you must set the `com.sun.management.jmxremote.port`
  system property when starting the JVM. We also recommend setting the
  `com.sun.management.jmxremote.rmi.port` system property to the same port. To
  expose a JMX endpoint remotely, you must also set the `java.rmi.server.hostname`
  system property.

  By default, these properties are set in a Cassandra deployment's
  `cassandra-env.sh` file.

  To set system properties by using command-line arguments, prepend the property
  name with `-D` when starting the JVM. For example, to set
  `com.sun.management.jmxremote.port` to port `7199`, specify the following when
  starting the JVM:

  <pre>
  -Dcom.sun.management.jmxremote.port=7199
  </pre>
minimum_supported_agent_version:
  metrics: 2.6.0
  logging: 2.5.0
supported_operating_systems: linux
# TODO: Fix errors and enable tests on all platforms.
platforms_to_skip:
  - debian-cloud:debian-12 # QueryLog() failed: cassandra_system not found, exhausted retries; QueryLog() failed: cassandra_debug not found, exhausted retries; QueryLog() failed: cassandra_gc not found, exhausted retries
  - debian-cloud:debian-12-arm64 # QueryLog() failed: cassandra_system not found, exhausted retries; QueryLog() failed: cassandra_debug not found, exhausted retries; QueryLog() failed: cassandra_gc not found, exhausted retries
supported_app_version: ["3.11", "4.0"]
expected_metrics:
  - type: workload.googleapis.com/cassandra.client.request.count
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: operation
        value_regex: .*
    representative: true
  - type: workload.googleapis.com/cassandra.client.request.error.count
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
    labels:
      - name: operation
        value_regex: .*
      - name: status
        value_regex: .*
  - type: workload.googleapis.com/cassandra.client.request.range_slice.latency.50p
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.range_slice.latency.99p
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.range_slice.latency.max
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.read.latency.50p
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.read.latency.99p
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.read.latency.max
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.write.latency.50p
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.write.latency.99p
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.client.request.write.latency.max
    value_type: DOUBLE
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.compaction.tasks.completed
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.compaction.tasks.pending
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.storage.load.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.storage.total_hints.count
    value_type: INT64
    kind: CUMULATIVE
    monitored_resources: [gce_instance]
  - type: workload.googleapis.com/cassandra.storage.total_hints.in_progress.count
    value_type: INT64
    kind: GAUGE
    monitored_resources: [gce_instance]
expected_logs:
  - log_name: cassandra_system
    fields:
      - name: jsonPayload.message
        value_regex: .*Startup complete.*
        type: string
        description: Log message, including detailed stacktrace where provided
      - name: jsonPayload.level
        value_regex: INFO
        type: string
        description: Log entry level
      - name: jsonPayload.module
        value_regex: main
        type: string
        description: Module of cassandra where the log originated
      - name: jsonPayload.javaClass
        value_regex: CassandraDaemon.java
        type: string
        description: Java class where the log originated
      - name: jsonPayload.lineNumber
        type: string
        description: Line number of the source file where the log originated
      - name: severity
        type: string
        description: ''
  - log_name: cassandra_debug
    fields:
      - name: jsonPayload.message
        value_regex: .*Loading settings from file.*
        type: string
        description: Log message
      - name: jsonPayload.level
        value_regex: DEBUG
        type: string
        description: Log entry level
      - name: jsonPayload.module
        value_regex: main
        type: string
        description: Module of cassandra where the log originated
      - name: jsonPayload.javaClass
        value_regex: YamlConfigurationLoader.java
        type: string
        description: Java class where the log originated
      - name: jsonPayload.lineNumber
        type: string
        description: Line number of the source file where the log originated
      - name: severity
        type: string
        description: ''
  - log_name: cassandra_gc
    fields:
      - name: jsonPayload.message
        value_regex: (?s).*Total time for which application threads were stopped.* # The (?s) part will make the . match with newline as well. See https://github.com/google/re2/blob/main/doc/syntax.txt#L65,L68
        type: string
        description: Log message
      - name: jsonPayload.uptime
        type: string
        description: Seconds the JVM has been active
      - name: jsonPayload.timeStopped
        type: string
        description: Seconds the JVM was stopped for garbage collection
      - name: jsonPayload.timeStopping
        type: string
        description: Seconds the JVM took to stop threads before garbage collection
      # Level, pid and tid are only available for GC logs with Java 11 and above
      - name: jsonPayload.level
        type: string
        optional: true
        description: Level of the log entry
      - name: jsonPayload.pid
        type: string
        optional: true
        description: Process ID of the Java process logging the message
      - name: jsonPayload.tid
        type: string
        optional: true
        description: Thread ID of the Java process logging the message
      - name: severity
        type: string
        description: ''
configuration_options:
  logs:
    - type: cassandra_system
      fields:
        - name: type
          default: null
          description: This value must be `cassandra_system`.
        - name: include_paths
          default: '[/var/log/cassandra/system*.log]'
          description: A list of filesystem paths to read by tailing each file. A wild card (`*`) can be used in the paths; for example, `/var/log/cassandra/system*.log`.
        - name: exclude_paths
          default: null
          description: A list of filesystem path patterns to exclude from the set matched by `include_paths`.
        - name: record_log_file_path
          default: false
          description: If set to `true`, then the path to the specific file from which the log record was obtained appears in the output log entry as the value of the `agent.googleapis.com/log_file_path` label. When using a wildcard, only the path of the file from which the record was obtained is recorded.
        - name: wildcard_refresh_interval
          default: 60s
          description: The interval at which wildcard file paths in `include_paths` are refreshed. Given as a [time duration](https://pkg.go.dev/time#ParseDuration), for example `30s` or `2m`. This property might be useful under high logging throughputs where log files are rotated faster than the default interval.
    - type: cassandra_debug
      fields:
        - name: type
          default: null
          description: This value must be `cassandra_debug`.
        - name: include_paths
          default: '[/var/log/cassandra/debug*.log]'
          description: A list of filesystem paths to read by tailing each file. A wild card (`*`) can be used in the paths; for example, `/var/log/cassandra/system*.log`.
        - name: exclude_paths
          default: null
          description: A list of filesystem path patterns to exclude from the set matched by `include_paths`.
        - name: record_log_file_path
          default: false
          description: If set to `true`, then the path to the specific file from which the log record was obtained appears in the output log entry as the value of the `agent.googleapis.com/log_file_path` label. When using a wildcard, only the path of the file from which the record was obtained is recorded.
        - name: wildcard_refresh_interval
          default: 60s
          description: The interval at which wildcard file paths in `include_paths` are refreshed. Given as a [time duration](https://pkg.go.dev/time#ParseDuration), for example `30s` or `2m`. This property might be useful under high logging throughputs where log files are rotated faster than the default interval.
    - type: cassandra_gc
      fields:
        - name: type
          default: null
          description: This value must be `cassandra_gc`.
        - name: include_paths
          default: '[/var/log/cassandra/gc.log.*.current]'
          description: A list of filesystem paths to read by tailing each file. A wild card (`*`) can be used in the paths; for example, `/var/log/cassandra/system*.log`.
        - name: exclude_paths
          default: null
          description: A list of filesystem path patterns to exclude from the set matched by `include_paths`.
        - name: record_log_file_path
          default: false
          description: If set to `true`, then the path to the specific file from which the log record was obtained appears in the output log entry as the value of the `agent.googleapis.com/log_file_path` label. When using a wildcard, only the path of the file from which the record was obtained is recorded.
        - name: wildcard_refresh_interval
          default: 60s
          description: The interval at which wildcard file paths in `include_paths` are refreshed. Given as a [time duration](https://pkg.go.dev/time#ParseDuration), for example `30s` or `2m`. This property might be useful under high logging throughputs where log files are rotated faster than the default interval.
  metrics:
    - type: cassandra
      fields:
        - name: type
          default: null
          description: This value must be `cassandra`.
        - name: endpoint
          default: localhost:7199
          description: The [JMX Service URL](https://docs.oracle.com/javase/8/docs/api/javax/management/remote/JMXServiceURL.html) or host and port used to construct the service URL. This value must be in the form of `service:jmx:<protocol>:<sap>` or `host:port`. Values in `host:port` form are used to create a service URL of `service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi`.
        - name: collect_jvm_metrics
          default: true
          description: Configures the receiver to also collect the supported JVM metrics.
        - name: username
          default: null
          description: The configured username if JMX is configured to require authentication.
        - name: password
          default: null
          description: The configured password if JMX is configured to require authentication.
        - name: collection_interval
          default: 60s
          description: A [time duration](https://pkg.go.dev/time#ParseDuration) value, such as `30s` or `5m`.
