-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CASSSIDECAR-216: Capture Metrics for Schema Reporting #204
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,9 +20,13 @@ | |||||
package org.apache.cassandra.sidecar.datahub; | ||||||
|
||||||
import java.util.List; | ||||||
import java.util.concurrent.TimeUnit; | ||||||
import java.util.stream.Stream; | ||||||
import com.google.common.base.Stopwatch; | ||||||
import com.google.common.collect.ImmutableList; | ||||||
import com.google.common.collect.Streams; | ||||||
import org.slf4j.Logger; | ||||||
import org.slf4j.LoggerFactory; | ||||||
|
||||||
import com.datastax.driver.core.Cluster; | ||||||
import com.datastax.driver.core.KeyspaceMetadata; | ||||||
|
@@ -34,6 +38,9 @@ | |||||
import datahub.client.Emitter; | ||||||
import datahub.event.MetadataChangeProposalWrapper; | ||||||
import org.apache.cassandra.sidecar.common.server.utils.ThrowableUtils; | ||||||
import org.apache.cassandra.sidecar.metrics.DeltaGauge; | ||||||
import org.apache.cassandra.sidecar.metrics.SidecarMetrics; | ||||||
import org.apache.cassandra.sidecar.metrics.server.SchemaReportingMetrics; | ||||||
import org.jetbrains.annotations.NotNull; | ||||||
|
||||||
/** | ||||||
|
@@ -47,6 +54,8 @@ | |||||
@Singleton | ||||||
public class SchemaReporter | ||||||
{ | ||||||
private static final Logger LOGGER = LoggerFactory.getLogger(SchemaReporter.class); | ||||||
|
||||||
@NotNull | ||||||
protected final IdentifiersProvider identifiersProvider; | ||||||
@NotNull | ||||||
|
@@ -57,6 +66,8 @@ public class SchemaReporter | |||||
protected final List<TableToAspectConverter<? extends RecordTemplate>> tableConverters; | ||||||
@NotNull | ||||||
protected final EmitterFactory emitterFactory; | ||||||
@NotNull | ||||||
protected final SchemaReportingMetrics reportingMetrics; | ||||||
|
||||||
/** | ||||||
* The public constructor that instantiates {@link SchemaReporter} with default configuration. | ||||||
|
@@ -66,10 +77,12 @@ public class SchemaReporter | |||||
* | ||||||
* @param identifiersProvider an instance of {@link IdentifiersProvider} to use | ||||||
* @param emitterFactory an instance of {@link EmitterFactory} to use | ||||||
* @param sidecarMetrics an instance of {@link SidecarMetrics} to obtain {@link SchemaReportingMetrics} from | ||||||
*/ | ||||||
@Inject | ||||||
public SchemaReporter(@NotNull IdentifiersProvider identifiersProvider, | ||||||
@NotNull EmitterFactory emitterFactory) | ||||||
@NotNull EmitterFactory emitterFactory, | ||||||
@NotNull SidecarMetrics sidecarMetrics) | ||||||
{ | ||||||
this(identifiersProvider, | ||||||
ImmutableList.of(new ClusterToDataPlatformInfoConverter(identifiersProvider), | ||||||
|
@@ -85,7 +98,8 @@ public SchemaReporter(@NotNull IdentifiersProvider identifiersProvider, | |||||
new TableToDataPlatformInstanceConverter(identifiersProvider), | ||||||
new TableToBrowsePathsV2Converter(identifiersProvider), | ||||||
new TableToBrowsePathsConverter(identifiersProvider)), | ||||||
emitterFactory); | ||||||
emitterFactory, | ||||||
sidecarMetrics.server().schemaReporting()); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -96,35 +110,73 @@ public SchemaReporter(@NotNull IdentifiersProvider identifiersProvider, | |||||
* @param keyspaceConverters a {@link List} of {@link KeyspaceToAspectConverter} instances to use | ||||||
* @param tableConverters a {@link List} of {@link TableToAspectConverter} instances to use | ||||||
* @param emitterFactory an instance of {@link EmitterFactory} to use | ||||||
* @param reportingMetrics an instance of {@link SchemaReportingMetrics} to use | ||||||
*/ | ||||||
protected SchemaReporter(@NotNull IdentifiersProvider identifiersProvider, | ||||||
@NotNull List<ClusterToAspectConverter<? extends RecordTemplate>> clusterConverters, | ||||||
@NotNull List<KeyspaceToAspectConverter<? extends RecordTemplate>> keyspaceConverters, | ||||||
@NotNull List<TableToAspectConverter<? extends RecordTemplate>> tableConverters, | ||||||
@NotNull EmitterFactory emitterFactory) | ||||||
@NotNull EmitterFactory emitterFactory, | ||||||
@NotNull SchemaReportingMetrics reportingMetrics) | ||||||
{ | ||||||
this.identifiersProvider = identifiersProvider; | ||||||
this.clusterConverters = clusterConverters; | ||||||
this.keyspaceConverters = keyspaceConverters; | ||||||
this.tableConverters = tableConverters; | ||||||
this.emitterFactory = emitterFactory; | ||||||
this.reportingMetrics = reportingMetrics; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Public method for converting and reporting the Cassandra schema when triggered by a scheduled periodic task | ||||||
* | ||||||
* @param cluster the {@link Cluster} to extract Cassandra schema from | ||||||
*/ | ||||||
public void processScheduled(@NotNull Cluster cluster) | ||||||
{ | ||||||
process(cluster.getMetadata(), reportingMetrics.startedSchedule.metric); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Public method for converting and reporting the Cassandra schema | ||||||
* Public method for converting and reporting the Cassandra schema when triggered by a received API request | ||||||
* | ||||||
* @param cluster a {@link Cluster} to extract Cassandra schema from | ||||||
* @param metadata the {@link Metadata} to extract Cassandra schema from | ||||||
*/ | ||||||
public void process(@NotNull Cluster cluster) | ||||||
public void processRequested(@NotNull Metadata metadata) | ||||||
{ | ||||||
process(metadata, reportingMetrics.startedRequest.metric); | ||||||
} | ||||||
|
||||||
/** | ||||||
* Private method for converting and reporting the Cassandra schema | ||||||
* | ||||||
* @param metadata the {@link Metadata} to extract Cassandra schema from | ||||||
* @param started the {@link DeltaGauge} for the metric counting invocations | ||||||
*/ | ||||||
private void process(@NotNull Metadata metadata, | ||||||
@NotNull DeltaGauge started) | ||||||
{ | ||||||
String action = " reporting schema for cluster with identifiers " + identifiersProvider; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can remove the heading space. It should make the error message in the RuntimeException look a bit nicer too. |
||||||
LOGGER.info("Started" + action); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the value placeholder of logger to eval lazily. Update the other places too.
Suggested change
|
||||||
started.increment(); | ||||||
|
||||||
try (Emitter emitter = emitterFactory.emitter()) | ||||||
{ | ||||||
stream(cluster.getMetadata()) | ||||||
.forEach(ThrowableUtils.consumer(emitter::emit)); | ||||||
Stopwatch stopwatch = Stopwatch.createStarted(); | ||||||
long counter = stream(metadata) | ||||||
.map(ThrowableUtils.function(emitter::emit)) | ||||||
.count(); | ||||||
|
||||||
reportingMetrics.durationMilliseconds.metric.update(stopwatch.elapsed(TimeUnit.MILLISECONDS)); | ||||||
reportingMetrics.sizeAspects.metric.update(counter); | ||||||
reportingMetrics.finishedSuccess.metric.increment(); | ||||||
LOGGER.info("Success" + action); | ||||||
} | ||||||
catch (Exception exception) | ||||||
{ | ||||||
throw new RuntimeException("Cannot extract schema for cluster " + identifiersProvider.cluster(), exception); | ||||||
reportingMetrics.finishedFailure.metric.increment(); | ||||||
LOGGER.error("Failure" + action); | ||||||
throw new RuntimeException(action, exception); | ||||||
} | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The toString is relatively complex. Is there a test?