5 commented on code in PR #204:
URL: https://github.com/apache/cassandra-sidecar/pull/204#discussion_r1999621811


##########
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:
   Exception in emit will be wrapped into a `RuntimeException` and rethrown, 
aborting conversion, and resulting in the `Failed` metric being updated from 
the `catch`. I guess we don't care about the number of aspects produced before 
failure has happened…



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to