Skip to content

Commit

Permalink
Merge pull request #108 from johndelcastillo/john-staging
Browse files Browse the repository at this point in the history
Cassandra 4.0 support
  • Loading branch information
johndelcastillo authored Feb 17, 2023
2 parents e6da3f1 + 0e3d93e commit d0d2ce5
Show file tree
Hide file tree
Showing 31 changed files with 2,558 additions and 32 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ dependency-reduced-pom.xml
release.properties

*.srl

test/build
*.egg-info
__pycache__
143 changes: 139 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,17 @@ For example, the following PromQL query will return an estimate of the number of

## Compatibility

*cassandra-exporter* is has been tested with:
*cassandra-exporter* is now Cassandra 4.0+ compatible, but the change is not a backwards compatible. Support for older Cassandra versions is via the older releases, as follows:

| Component | Version |
| Cassandra Version | Compatible Exporter Version |
|-----------------|---------------|
| Apache Cassandra| 3.0.17 (experimental), 3.11.2, 3.11.3 |
| Prometheus | 2.0 and later |
| Apache Cassandra 4.x | 0.9.12 |
| Apache Cassandra 3.0.17, 3.11.2, 3.11.3 | 0.9.11 |

| Prometheus Version |
|-----------------|
| 2.42.0
|
Other Cassandra and Prometheus versions will be tested for compatibility in the future.

## Usage
Expand Down Expand Up @@ -409,6 +413,137 @@ We suggest viewing the metrics endpoint (e.g., <http://localhost:9500/metrics>)
are exported by your Cassandra node.


## Testing

### Java
There are unit tests in the various projects which will get executed with the maven commands.

### Integration test harness

There is an integration test harness available in the */test/* folder.
This harness is a work in progress, and is currently only useful for manual verification.

#### Requirements

The test harness uses Python (tested with 3.10).

Initialise the project by using the pyproject.toml file

pip install .

The tool can be launched via

python test_tool.py

#### Operation

There are four modes of operation:

- `benchmark`

Not Implemented - TBA - Intended to test the speed of collection.

- `demo`

Usage: test_tool.py demo [OPTIONS]

Start a Cassandra cluster with cassandra-exporter installed (agent or
standalone). Optionally setup a schema. Wait for ctrl-c to shut everything
down.

Working Directory:
-C, --working-directory PATH location to install Cassandra and/or Prometheus.
Must be empty or not exist. Defaults to a
temporary directory.
--cleanup-working-directory [on-error|always|never]
how to delete the working directory on exit:
"on-error": delete working directory on exit
unless an error occurs, "always": always delete
working directory on exit, "never": never delete
working directory. [default: on-error]

Cassandra:
--cluster-name TEXT name of the Cassandra cluster [default: test-
cluster]
--cassandra-version TEXT Cassandra version to run [default: 4.1.0]
--topology DCS RACKS NODES number of data centers, racks per data center,
and nodes per rack. [default: 2, 3, 1]
-j, --exporter-jar PATH path of the cassandra-exporter jar to use,
either agent or standalone builds, or one of
"agent" or "standalone" for the currently built
jar of that type in the project directory
(assumes that the sources for this test tool are
in the standard location within the project, and
that the jar(s) have been built). [default:
agent]
-s, --schema PATH path of the CQL schema YAML file to apply on
cluster start. The YAML file must contain a list
of CQL statement strings, which are applied in
order. [default: /root/source/forks/cassandra-
exporter/test/schema.yaml]

- `dump`

Usage: test_tool.py dump [OPTIONS] COMMAND [ARGS]...

Commands to capture, validate and diff metrics dumps

Options:
--help Show this message and exit.

Commands:
capture Start a Cassandra cluster, capture metrics from each node's...
diff Compare two metrics dumps and output the difference
validate Validate a metrics dump using Prometheus's promtool.

- `e2e` - *Note no tests are run at the moment*

Usage: test_tool.py e2e [OPTIONS]

Run cassandra-exporter end-to-end tests.

- Start C* with the exporter JAR (agent or standalone).
- Setup a schema.
- Configure and start prometheus.
- Wait for all scrape targets to get healthy.
- Run some tests.

Working Directory:
-C, --working-directory PATH location to install Cassandra and/or
Prometheus. Must be empty or not exist.
Defaults to a temporary directory.
--cleanup-working-directory [on-error|always|never]
how to delete the working directory on exit:
"on-error": delete working directory on exit
unless an error occurs, "always": always delete
working directory on exit, "never": never
delete working directory. [default: on-error]

Cassandra:
--cluster-name TEXT name of the Cassandra cluster [default: test-
cluster]
--cassandra-version TEXT Cassandra version to run [default: 4.1.0]
--topology DCS RACKS NODES number of data centers, racks per data center,
and nodes per rack. [default: 2, 3, 1]
-j, --exporter-jar PATH path of the cassandra-exporter jar to use,
either agent or standalone builds, or one of
"agent" or "standalone" for the currently built
jar of that type in the project directory
(assumes that the sources for this test tool
are in the standard location within the
project, and that the jar(s) have been built).
[default: agent]
-s, --schema PATH path of the CQL schema YAML file to apply on
cluster start. The YAML file must contain a
list of CQL statement strings, which are
applied in order. [default:
/root/source/forks/cassandra-
exporter/test/schema.yaml]

Prometheus Archive: [mutually exclusive]
--prometheus-version TAG
--prometheus-archive PATH/URL

## Unstable, Missing & Future Features

See the [project issue tracker](https://github.com/instaclustr/cassandra-exporter/issues) for a complete list.
Expand Down
4 changes: 2 additions & 2 deletions agent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<groupId>com.zegelin.cassandra-exporter</groupId>
<artifactId>exporter-parent</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>
</parent>

<artifactId>agent</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>

<name>Cassandra Exporter Agent</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
package com.zegelin.cassandra.exporter;

import com.zegelin.cassandra.exporter.MetadataFactory;
import org.apache.cassandra.config.CFMetaData;
import org.apache.cassandra.config.DatabaseDescriptor;
import org.apache.cassandra.config.Schema;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.locator.IEndpointSnitch;
import org.apache.cassandra.locator.InetAddressAndPort;
import org.apache.cassandra.utils.FBUtilities;
import org.apache.cassandra.schema.Schema;

import java.net.InetAddress;
import java.util.Optional;
import java.util.Set;

public class InternalMetadataFactory extends MetadataFactory {
private static Optional<CFMetaData> getCFMetaData(final String keyspaceName, final String tableName) {
return Optional.ofNullable(Schema.instance.getCFMetaData(keyspaceName, tableName));
private static Optional<org.apache.cassandra.schema.TableMetadata> getTableMetaData(final String keyspaceName, final String tableName) {
return Optional.ofNullable(Schema.instance.getTableMetadata(keyspaceName, tableName));
}

private static Optional<org.apache.cassandra.schema.TableMetadataRef> getIndexMetadata(final String keyspaceName, final String indexName) {
return Optional.ofNullable(Schema.instance.getIndexTableMetadataRef(keyspaceName, indexName));
}

@Override
public Optional<IndexMetadata> indexMetadata(final String keyspaceName, final String tableName, final String indexName) {
return getCFMetaData(keyspaceName, tableName)
.flatMap(m -> m.getIndexes().get(indexName))
return getIndexMetadata(keyspaceName, indexName)
.flatMap(m -> m.get().indexName())
.map(m -> {
final IndexMetadata.IndexType indexType = IndexMetadata.IndexType.valueOf(m.kind.toString());
final Optional<String> className = Optional.ofNullable(m.options.get("class_name"));
final IndexMetadata.IndexType indexType = IndexMetadata.IndexType.valueOf(m);
final Optional<String> className = Optional.ofNullable(m);

return new IndexMetadata() {
@Override
Expand All @@ -41,7 +45,7 @@ public Optional<String> customClassName() {

@Override
public Optional<TableMetadata> tableOrViewMetadata(final String keyspaceName, final String tableOrViewName) {
return getCFMetaData(keyspaceName, tableOrViewName)
return getTableMetaData(keyspaceName, tableOrViewName)
.map(m -> new TableMetadata() {
@Override
public String compactionStrategyClassName() {
Expand All @@ -67,12 +71,12 @@ public Optional<EndpointMetadata> endpointMetadata(final InetAddress endpoint) {
return Optional.of(new EndpointMetadata() {
@Override
public String dataCenter() {
return endpointSnitch.getDatacenter(endpoint);
return endpointSnitch.getDatacenter(InetAddressAndPort.getByAddress(endpoint));
}

@Override
public String rack() {
return endpointSnitch.getRack(endpoint);
return endpointSnitch.getRack(InetAddressAndPort.getByAddress(endpoint));
}
});
}
Expand All @@ -84,6 +88,6 @@ public String clusterName() {

@Override
public InetAddress localBroadcastAddress() {
return FBUtilities.getBroadcastAddress();
return FBUtilities.getBroadcastAddressAndPort().getAddress();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.zegelin.cassandra.exporter.collector;

import com.google.common.collect.ImmutableSet;
import com.zegelin.cassandra.exporter.MetadataFactory;
import com.zegelin.prometheus.domain.Labels;
import com.zegelin.prometheus.domain.NumericMetric;
import org.apache.cassandra.gms.EndpointState;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.locator.InetAddressAndPort;

import java.net.InetAddress;
import java.util.Map;
Expand Down Expand Up @@ -34,13 +36,11 @@ private InternalGossiperMBeanMetricFamilyCollector(final Gossiper gossiper, fina

@Override
protected void collect(final Stream.Builder<NumericMetric> generationNumberMetrics, final Stream.Builder<NumericMetric> downtimeMetrics, final Stream.Builder<NumericMetric> activeMetrics) {
final Set<Map.Entry<InetAddress, EndpointState>> endpointStates = gossiper.getEndpointStates();
for (InetAddressAndPort endpoint : gossiper.getEndpoints()) {
final InetAddress endpointAddress = endpoint.getAddress();
final EndpointState state = gossiper.getEndpointStateForEndpoint(endpoint);

for (final Map.Entry<InetAddress, EndpointState> endpointState : endpointStates) {
final InetAddress endpoint = endpointState.getKey();
final EndpointState state = endpointState.getValue();

final Labels labels = metadataFactory.endpointLabels(endpoint);
final Labels labels = metadataFactory.endpointLabels(endpointAddress);

generationNumberMetrics.add(new NumericMetric(labels, gossiper.getCurrentGenerationNumber(endpoint)));
downtimeMetrics.add(new NumericMetric(labels, millisecondsToSeconds(gossiper.getEndpointDowntime(endpoint))));
Expand Down
4 changes: 2 additions & 2 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<groupId>com.zegelin.cassandra-exporter</groupId>
<artifactId>exporter-parent</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>
</parent>

<artifactId>common</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>

<name>Cassandra Exporter Common</name>

Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.zegelin.cassandra-exporter</groupId>
<artifactId>exporter-parent</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Cassandra Exporter Parent</name>
Expand All @@ -15,7 +15,7 @@
</modules>

<properties>
<version.cassandra.all>3.11.2</version.cassandra.all>
<version.cassandra.all>4.1.0</version.cassandra.all>

<version.maven.release.plugin>2.5.3</version.maven.release.plugin>
<version.maven.dependency.plugin>3.1.1</version.maven.dependency.plugin>
Expand All @@ -41,7 +41,7 @@
<dependency>
<groupId>com.zegelin.cassandra-exporter</groupId>
<artifactId>common</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.glassfish.hk2.external</groupId>
Expand Down
4 changes: 2 additions & 2 deletions standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<parent>
<groupId>com.zegelin.cassandra-exporter</groupId>
<artifactId>exporter-parent</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>
</parent>

<artifactId>standalone</artifactId>
<version>0.9.11-SNAPSHOT</version>
<version>0.9.12-SNAPSHOT</version>

<name>Cassandra Exporter Standalone/CLI</name>

Expand Down
Loading

0 comments on commit d0d2ce5

Please sign in to comment.