sarankk commented on code in PR #204:
URL: https://github.com/apache/cassandra-sidecar/pull/204#discussion_r1999285452
##########
server/src/main/java/org/apache/cassandra/sidecar/datahub/IdentifiersProvider.java:
##########
@@ -42,7 +43,26 @@ public abstract class IdentifiersProvider
protected static final String DATA_PLATFORM_INSTANCE =
"dataPlatformInstance";
protected static final String CONTAINER = "container";
protected static final String DATASET = "dataset";
- protected static final String PROD = "PROD"; // DataHub requires this to
be {@code PROD} regardless
+ protected static final String PROD = "PROD"; // DataHub requires this to
be {@code PROD}
+
+ protected static final ToStringStyle STYLE = new ToStringStyle()
+ {{
Review Comment:
Minor nit: We can use method chaining here with
`ToStringStyle.DEFAULT_STYLE.withUseShortClassName()`
##########
server/src/test/integration/org/apache/cassandra/sidecar/datahub/SchemaReporterIntegrationTest.java:
##########
@@ -97,18 +122,28 @@ void testSchemaConverter() throws IOException
JsonEmitter emitter = new JsonEmitter();
try (Session session = maybeGetSession())
{
- new SchemaReporter(IDENTIFIERS, () ->
emitter).process(session.getCluster());
+ new SchemaReporter(IDENTIFIERS, () -> emitter,
metrics).processScheduled(session.getCluster());
}
String actualJson = normalizeNames(emitter.content());
Review Comment:
Nit: extra space
##########
server/src/main/java/org/apache/cassandra/sidecar/datahub/SchemaReporter.java:
##########
@@ -96,44 +110,72 @@ 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
+ * 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 process(@NotNull Cluster cluster)
+ public void processScheduled(@NotNull Cluster cluster)
+ {
+ process(cluster.getMetadata(),
reportingMetrics.startedSchedule.metric);
+ }
+
+ /**
+ * Public method for converting and reporting the Cassandra schema when
triggered by a received API request
+ *
+ * @param metadata the {@link Metadata} to extract Cassandra schema from
+ */
+ public void processRequested(@NotNull Metadata metadata)
{
- process(cluster.getMetadata());
+ process(metadata, reportingMetrics.startedRequest.metric);
}
/**
- * Public method for converting and reporting the Cassandra schema
+ * 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
*/
- public void process(@NotNull Metadata metadata)
+ private void process(@NotNull Metadata metadata,
+ @NotNull DeltaGauge started)
{
+ LOGGER.info("Starting to report schema for cluster, identifiers={}",
identifiersProvider);
+ started.increment();
+
try (Emitter emitter = emitterFactory.emitter())
{
- stream(metadata).forEach(ThrowableUtils.consumer(emitter::emit));
+ Stopwatch stopwatch = Stopwatch.createStarted();
+ long counter =
stream(metadata).map(ThrowableUtils.function(emitter::emit))
Review Comment:
This count seems to ignore exceptions in emit, what will we be using this
counter metric for?
##########
server/src/main/java/org/apache/cassandra/sidecar/metrics/DeltaGauge.java:
##########
@@ -33,7 +33,15 @@ public class DeltaGauge implements Gauge<Long>, Metric
public DeltaGauge()
{
- this.count = new AtomicLong();
+ this.count = new AtomicLong(0L);
Review Comment:
Any reason why we add `0L` here? default `new AtomicLong()` creates with `0`
##########
server/src/main/java/org/apache/cassandra/sidecar/metrics/server/SchemaReportingMetrics.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.cassandra.sidecar.metrics.server;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.cassandra.sidecar.metrics.DeltaGauge;
+import org.apache.cassandra.sidecar.metrics.NamedMetric;
+import org.apache.cassandra.sidecar.metrics.ServerMetrics;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Tracks metrics for the schema reporting done by Sidecar
+ */
+public class SchemaReportingMetrics
+{
+ protected static final String DOMAIN = ServerMetrics.SERVER_PREFIX +
".SchemaReporting";
+
+ public final NamedMetric<DeltaGauge> startedRequest;
+ public final NamedMetric<DeltaGauge> startedSchedule;
+ public final NamedMetric<DeltaGauge> finishedSuccess;
+ public final NamedMetric<DeltaGauge> finishedFailure;
+ public final NamedMetric<Histogram> durationMilliseconds;
+ public final NamedMetric<Histogram> sizeAspects;
+
+ public SchemaReportingMetrics(@NotNull MetricRegistry registry)
+ {
+ startedSchedule = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("StartedBySchedule")
+ .build();
+ startedRequest = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("StartedByRequest")
+ .build();
+
+ finishedSuccess = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("FinishedWithSuccess")
+ .build();
+ finishedFailure = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("FinishedWithFailure")
+ .build();
+
+ sizeAspects = NamedMetric.builder(registry::histogram)
+ .withDomain(DOMAIN)
+ .withName("SizeInAspects")
Review Comment:
What is the use case of `SizeInAspects` metric?
##########
server/src/main/java/org/apache/cassandra/sidecar/metrics/server/SchemaReportingMetrics.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+
+package org.apache.cassandra.sidecar.metrics.server;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.MetricRegistry;
+import org.apache.cassandra.sidecar.metrics.DeltaGauge;
+import org.apache.cassandra.sidecar.metrics.NamedMetric;
+import org.apache.cassandra.sidecar.metrics.ServerMetrics;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Tracks metrics for the schema reporting done by Sidecar
+ */
+public class SchemaReportingMetrics
+{
+ protected static final String DOMAIN = ServerMetrics.SERVER_PREFIX +
".SchemaReporting";
+
+ public final NamedMetric<DeltaGauge> startedRequest;
+ public final NamedMetric<DeltaGauge> startedSchedule;
+ public final NamedMetric<DeltaGauge> finishedSuccess;
+ public final NamedMetric<DeltaGauge> finishedFailure;
+ public final NamedMetric<Histogram> durationMilliseconds;
+ public final NamedMetric<Histogram> sizeAspects;
+
+ public SchemaReportingMetrics(@NotNull MetricRegistry registry)
+ {
+ startedSchedule = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("StartedBySchedule")
+ .build();
+ startedRequest = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("StartedByRequest")
+ .build();
+
+ finishedSuccess = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("FinishedWithSuccess")
+ .build();
+ finishedFailure = NamedMetric.builder(name -> registry.gauge(name,
DeltaGauge::new))
+ .withDomain(DOMAIN)
+ .withName("FinishedWithFailure")
+ .build();
+
+ sizeAspects = NamedMetric.builder(registry::histogram)
+ .withDomain(DOMAIN)
+ .withName("SizeInAspects")
+ .build();
+
+ durationMilliseconds = NamedMetric.builder(registry::histogram)
+ .withDomain(DOMAIN)
+ .withName("DurationInMilliseconds")
+ .build();
Review Comment:
Yes agree, timer is better here. Also we can record time taken directly with
the timer.
##########
server/src/main/java/org/apache/cassandra/sidecar/datahub/SchemaReporter.java:
##########
@@ -96,44 +110,72 @@ 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
+ * 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 process(@NotNull Cluster cluster)
+ public void processScheduled(@NotNull Cluster cluster)
+ {
+ process(cluster.getMetadata(),
reportingMetrics.startedSchedule.metric);
+ }
+
+ /**
+ * Public method for converting and reporting the Cassandra schema when
triggered by a received API request
+ *
+ * @param metadata the {@link Metadata} to extract Cassandra schema from
+ */
+ public void processRequested(@NotNull Metadata metadata)
{
- process(cluster.getMetadata());
+ process(metadata, reportingMetrics.startedRequest.metric);
}
/**
- * Public method for converting and reporting the Cassandra schema
+ * 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
*/
- public void process(@NotNull Metadata metadata)
+ private void process(@NotNull Metadata metadata,
+ @NotNull DeltaGauge started)
{
+ LOGGER.info("Starting to report schema for cluster, identifiers={}",
identifiersProvider);
+ started.increment();
+
try (Emitter emitter = emitterFactory.emitter())
{
- stream(metadata).forEach(ThrowableUtils.consumer(emitter::emit));
+ Stopwatch stopwatch = Stopwatch.createStarted();
Review Comment:
We can use the metric to record time instead of `Stopwatch`,
`reportContext.stop();` calls `update`
```
try (Emitter emitter = emitterFactory.emitter())
{
try (Timer.Context reportContext =
reportingMetrics.durationMilliseconds.metric.time())
{
long counter =
stream(metadata).map(ThrowableUtils.function(emitter::emit))
.count();
reportContext.stop();
reportingMetrics.sizeAspects.metric.update(counter);
reportingMetrics.finishedSuccess.metric.increment();
LOGGER.info("Successfully reported schema for cluster,
identifiers={}", identifiersProvider);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]