Skip to content

Commit d0d2ce5

Browse files
Merge pull request #108 from johndelcastillo/john-staging
Cassandra 4.0 support
2 parents e6da3f1 + 0e3d93e commit d0d2ce5

31 files changed

+2558
-32
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ dependency-reduced-pom.xml
1111
release.properties
1212

1313
*.srl
14-
14+
test/build
15+
*.egg-info
16+
__pycache__

README.md

Lines changed: 139 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ For example, the following PromQL query will return an estimate of the number of
3535

3636
## Compatibility
3737

38-
*cassandra-exporter* is has been tested with:
38+
*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:
3939

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

45+
| Prometheus Version |
46+
|-----------------|
47+
| 2.42.0
48+
|
4549
Other Cassandra and Prometheus versions will be tested for compatibility in the future.
4650

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

411415

416+
## Testing
417+
418+
### Java
419+
There are unit tests in the various projects which will get executed with the maven commands.
420+
421+
### Integration test harness
422+
423+
There is an integration test harness available in the */test/* folder.
424+
This harness is a work in progress, and is currently only useful for manual verification.
425+
426+
#### Requirements
427+
428+
The test harness uses Python (tested with 3.10).
429+
430+
Initialise the project by using the pyproject.toml file
431+
432+
pip install .
433+
434+
The tool can be launched via
435+
436+
python test_tool.py
437+
438+
#### Operation
439+
440+
There are four modes of operation:
441+
442+
- `benchmark`
443+
444+
Not Implemented - TBA - Intended to test the speed of collection.
445+
446+
- `demo`
447+
448+
Usage: test_tool.py demo [OPTIONS]
449+
450+
Start a Cassandra cluster with cassandra-exporter installed (agent or
451+
standalone). Optionally setup a schema. Wait for ctrl-c to shut everything
452+
down.
453+
454+
Working Directory:
455+
-C, --working-directory PATH location to install Cassandra and/or Prometheus.
456+
Must be empty or not exist. Defaults to a
457+
temporary directory.
458+
--cleanup-working-directory [on-error|always|never]
459+
how to delete the working directory on exit:
460+
"on-error": delete working directory on exit
461+
unless an error occurs, "always": always delete
462+
working directory on exit, "never": never delete
463+
working directory. [default: on-error]
464+
465+
Cassandra:
466+
--cluster-name TEXT name of the Cassandra cluster [default: test-
467+
cluster]
468+
--cassandra-version TEXT Cassandra version to run [default: 4.1.0]
469+
--topology DCS RACKS NODES number of data centers, racks per data center,
470+
and nodes per rack. [default: 2, 3, 1]
471+
-j, --exporter-jar PATH path of the cassandra-exporter jar to use,
472+
either agent or standalone builds, or one of
473+
"agent" or "standalone" for the currently built
474+
jar of that type in the project directory
475+
(assumes that the sources for this test tool are
476+
in the standard location within the project, and
477+
that the jar(s) have been built). [default:
478+
agent]
479+
-s, --schema PATH path of the CQL schema YAML file to apply on
480+
cluster start. The YAML file must contain a list
481+
of CQL statement strings, which are applied in
482+
order. [default: /root/source/forks/cassandra-
483+
exporter/test/schema.yaml]
484+
485+
- `dump`
486+
487+
Usage: test_tool.py dump [OPTIONS] COMMAND [ARGS]...
488+
489+
Commands to capture, validate and diff metrics dumps
490+
491+
Options:
492+
--help Show this message and exit.
493+
494+
Commands:
495+
capture Start a Cassandra cluster, capture metrics from each node's...
496+
diff Compare two metrics dumps and output the difference
497+
validate Validate a metrics dump using Prometheus's promtool.
498+
499+
- `e2e` - *Note no tests are run at the moment*
500+
501+
Usage: test_tool.py e2e [OPTIONS]
502+
503+
Run cassandra-exporter end-to-end tests.
504+
505+
- Start C* with the exporter JAR (agent or standalone).
506+
- Setup a schema.
507+
- Configure and start prometheus.
508+
- Wait for all scrape targets to get healthy.
509+
- Run some tests.
510+
511+
Working Directory:
512+
-C, --working-directory PATH location to install Cassandra and/or
513+
Prometheus. Must be empty or not exist.
514+
Defaults to a temporary directory.
515+
--cleanup-working-directory [on-error|always|never]
516+
how to delete the working directory on exit:
517+
"on-error": delete working directory on exit
518+
unless an error occurs, "always": always delete
519+
working directory on exit, "never": never
520+
delete working directory. [default: on-error]
521+
522+
Cassandra:
523+
--cluster-name TEXT name of the Cassandra cluster [default: test-
524+
cluster]
525+
--cassandra-version TEXT Cassandra version to run [default: 4.1.0]
526+
--topology DCS RACKS NODES number of data centers, racks per data center,
527+
and nodes per rack. [default: 2, 3, 1]
528+
-j, --exporter-jar PATH path of the cassandra-exporter jar to use,
529+
either agent or standalone builds, or one of
530+
"agent" or "standalone" for the currently built
531+
jar of that type in the project directory
532+
(assumes that the sources for this test tool
533+
are in the standard location within the
534+
project, and that the jar(s) have been built).
535+
[default: agent]
536+
-s, --schema PATH path of the CQL schema YAML file to apply on
537+
cluster start. The YAML file must contain a
538+
list of CQL statement strings, which are
539+
applied in order. [default:
540+
/root/source/forks/cassandra-
541+
exporter/test/schema.yaml]
542+
543+
Prometheus Archive: [mutually exclusive]
544+
--prometheus-version TAG
545+
--prometheus-archive PATH/URL
546+
412547
## Unstable, Missing & Future Features
413548

414549
See the [project issue tracker](https://github.com/instaclustr/cassandra-exporter/issues) for a complete list.

agent/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<parent>
66
<groupId>com.zegelin.cassandra-exporter</groupId>
77
<artifactId>exporter-parent</artifactId>
8-
<version>0.9.11-SNAPSHOT</version>
8+
<version>0.9.12-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>agent</artifactId>
12-
<version>0.9.11-SNAPSHOT</version>
12+
<version>0.9.12-SNAPSHOT</version>
1313

1414
<name>Cassandra Exporter Agent</name>
1515

agent/src/main/java/com/zegelin/cassandra/exporter/InternalMetadataFactory.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,33 @@
11
package com.zegelin.cassandra.exporter;
22

33
import com.zegelin.cassandra.exporter.MetadataFactory;
4-
import org.apache.cassandra.config.CFMetaData;
54
import org.apache.cassandra.config.DatabaseDescriptor;
6-
import org.apache.cassandra.config.Schema;
75
import org.apache.cassandra.gms.Gossiper;
86
import org.apache.cassandra.locator.IEndpointSnitch;
7+
import org.apache.cassandra.locator.InetAddressAndPort;
98
import org.apache.cassandra.utils.FBUtilities;
9+
import org.apache.cassandra.schema.Schema;
1010

1111
import java.net.InetAddress;
1212
import java.util.Optional;
1313
import java.util.Set;
1414

1515
public class InternalMetadataFactory extends MetadataFactory {
16-
private static Optional<CFMetaData> getCFMetaData(final String keyspaceName, final String tableName) {
17-
return Optional.ofNullable(Schema.instance.getCFMetaData(keyspaceName, tableName));
16+
private static Optional<org.apache.cassandra.schema.TableMetadata> getTableMetaData(final String keyspaceName, final String tableName) {
17+
return Optional.ofNullable(Schema.instance.getTableMetadata(keyspaceName, tableName));
18+
}
19+
20+
private static Optional<org.apache.cassandra.schema.TableMetadataRef> getIndexMetadata(final String keyspaceName, final String indexName) {
21+
return Optional.ofNullable(Schema.instance.getIndexTableMetadataRef(keyspaceName, indexName));
1822
}
1923

2024
@Override
2125
public Optional<IndexMetadata> indexMetadata(final String keyspaceName, final String tableName, final String indexName) {
22-
return getCFMetaData(keyspaceName, tableName)
23-
.flatMap(m -> m.getIndexes().get(indexName))
26+
return getIndexMetadata(keyspaceName, indexName)
27+
.flatMap(m -> m.get().indexName())
2428
.map(m -> {
25-
final IndexMetadata.IndexType indexType = IndexMetadata.IndexType.valueOf(m.kind.toString());
26-
final Optional<String> className = Optional.ofNullable(m.options.get("class_name"));
29+
final IndexMetadata.IndexType indexType = IndexMetadata.IndexType.valueOf(m);
30+
final Optional<String> className = Optional.ofNullable(m);
2731

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

4246
@Override
4347
public Optional<TableMetadata> tableOrViewMetadata(final String keyspaceName, final String tableOrViewName) {
44-
return getCFMetaData(keyspaceName, tableOrViewName)
48+
return getTableMetaData(keyspaceName, tableOrViewName)
4549
.map(m -> new TableMetadata() {
4650
@Override
4751
public String compactionStrategyClassName() {
@@ -67,12 +71,12 @@ public Optional<EndpointMetadata> endpointMetadata(final InetAddress endpoint) {
6771
return Optional.of(new EndpointMetadata() {
6872
@Override
6973
public String dataCenter() {
70-
return endpointSnitch.getDatacenter(endpoint);
74+
return endpointSnitch.getDatacenter(InetAddressAndPort.getByAddress(endpoint));
7175
}
7276

7377
@Override
7478
public String rack() {
75-
return endpointSnitch.getRack(endpoint);
79+
return endpointSnitch.getRack(InetAddressAndPort.getByAddress(endpoint));
7680
}
7781
});
7882
}
@@ -84,6 +88,6 @@ public String clusterName() {
8488

8589
@Override
8690
public InetAddress localBroadcastAddress() {
87-
return FBUtilities.getBroadcastAddress();
91+
return FBUtilities.getBroadcastAddressAndPort().getAddress();
8892
}
8993
}

agent/src/main/java/com/zegelin/cassandra/exporter/collector/InternalGossiperMBeanMetricFamilyCollector.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.zegelin.cassandra.exporter.collector;
22

3+
import com.google.common.collect.ImmutableSet;
34
import com.zegelin.cassandra.exporter.MetadataFactory;
45
import com.zegelin.prometheus.domain.Labels;
56
import com.zegelin.prometheus.domain.NumericMetric;
67
import org.apache.cassandra.gms.EndpointState;
78
import org.apache.cassandra.gms.Gossiper;
9+
import org.apache.cassandra.locator.InetAddressAndPort;
810

911
import java.net.InetAddress;
1012
import java.util.Map;
@@ -34,13 +36,11 @@ private InternalGossiperMBeanMetricFamilyCollector(final Gossiper gossiper, fina
3436

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

39-
for (final Map.Entry<InetAddress, EndpointState> endpointState : endpointStates) {
40-
final InetAddress endpoint = endpointState.getKey();
41-
final EndpointState state = endpointState.getValue();
42-
43-
final Labels labels = metadataFactory.endpointLabels(endpoint);
43+
final Labels labels = metadataFactory.endpointLabels(endpointAddress);
4444

4545
generationNumberMetrics.add(new NumericMetric(labels, gossiper.getCurrentGenerationNumber(endpoint)));
4646
downtimeMetrics.add(new NumericMetric(labels, millisecondsToSeconds(gossiper.getEndpointDowntime(endpoint))));

common/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<parent>
66
<groupId>com.zegelin.cassandra-exporter</groupId>
77
<artifactId>exporter-parent</artifactId>
8-
<version>0.9.11-SNAPSHOT</version>
8+
<version>0.9.12-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>common</artifactId>
12-
<version>0.9.11-SNAPSHOT</version>
12+
<version>0.9.12-SNAPSHOT</version>
1313

1414
<name>Cassandra Exporter Common</name>
1515

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<groupId>com.zegelin.cassandra-exporter</groupId>
55
<artifactId>exporter-parent</artifactId>
6-
<version>0.9.11-SNAPSHOT</version>
6+
<version>0.9.12-SNAPSHOT</version>
77
<packaging>pom</packaging>
88

99
<name>Cassandra Exporter Parent</name>
@@ -15,7 +15,7 @@
1515
</modules>
1616

1717
<properties>
18-
<version.cassandra.all>3.11.2</version.cassandra.all>
18+
<version.cassandra.all>4.1.0</version.cassandra.all>
1919

2020
<version.maven.release.plugin>2.5.3</version.maven.release.plugin>
2121
<version.maven.dependency.plugin>3.1.1</version.maven.dependency.plugin>
@@ -41,7 +41,7 @@
4141
<dependency>
4242
<groupId>com.zegelin.cassandra-exporter</groupId>
4343
<artifactId>common</artifactId>
44-
<version>0.9.11-SNAPSHOT</version>
44+
<version>0.9.12-SNAPSHOT</version>
4545
<exclusions>
4646
<exclusion>
4747
<groupId>org.glassfish.hk2.external</groupId>

standalone/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<parent>
66
<groupId>com.zegelin.cassandra-exporter</groupId>
77
<artifactId>exporter-parent</artifactId>
8-
<version>0.9.11-SNAPSHOT</version>
8+
<version>0.9.12-SNAPSHOT</version>
99
</parent>
1010

1111
<artifactId>standalone</artifactId>
12-
<version>0.9.11-SNAPSHOT</version>
12+
<version>0.9.12-SNAPSHOT</version>
1313

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

0 commit comments

Comments
 (0)