-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: setup metrics in the simulator to report block items sent (#316)
Signed-off-by: Matt Peterson <[email protected]>
- Loading branch information
1 parent
791af49
commit ccff828
Showing
19 changed files
with
458 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
simulator/src/main/java/com/hedera/block/simulator/metrics/MetricsInjectionModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed 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 com.hedera.block.simulator.metrics; | ||
|
||
import com.swirlds.common.metrics.platform.DefaultMetricsProvider; | ||
import com.swirlds.config.api.Configuration; | ||
import com.swirlds.metrics.api.Metrics; | ||
import dagger.Binds; | ||
import dagger.Module; | ||
import dagger.Provides; | ||
import javax.inject.Singleton; | ||
|
||
/** The module used to inject the metrics service and metrics into the application. */ | ||
@Module | ||
public interface MetricsInjectionModule { | ||
|
||
/** | ||
* Provides the metrics service. | ||
* | ||
* @param metricsService the metrics service to be used | ||
* @return the metrics service | ||
*/ | ||
@Singleton | ||
@Binds | ||
MetricsService bindMetricsService(MetricsServiceImpl metricsService); | ||
|
||
/** | ||
* Provides the metrics. | ||
* | ||
* @param configuration the configuration to be used by the metrics | ||
* @return the metrics | ||
*/ | ||
@Singleton | ||
@Provides | ||
static Metrics provideMetrics(Configuration configuration) { | ||
final DefaultMetricsProvider metricsProvider = new DefaultMetricsProvider(configuration); | ||
final Metrics metrics = metricsProvider.createGlobalMetrics(); | ||
metricsProvider.start(); | ||
return metrics; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
simulator/src/main/java/com/hedera/block/simulator/metrics/MetricsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed 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 com.hedera.block.simulator.metrics; | ||
|
||
import com.swirlds.metrics.api.Counter; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** Use member variables of this class to update metric data for the Hedera Block Node. */ | ||
public interface MetricsService { | ||
/** | ||
* Use this method to get a specific counter for the given metric type. | ||
* | ||
* @param key to get a specific counter | ||
* @return the counter | ||
*/ | ||
Counter get(@NonNull SimulatorMetricTypes.Counter key); | ||
} |
65 changes: 65 additions & 0 deletions
65
simulator/src/main/java/com/hedera/block/simulator/metrics/MetricsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* Licensed 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 com.hedera.block.simulator.metrics; | ||
|
||
import com.swirlds.metrics.api.Counter; | ||
import com.swirlds.metrics.api.Metrics; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.EnumMap; | ||
import javax.inject.Inject; | ||
|
||
/** | ||
* Use member variables of this class to update metric data for the Hedera Block Node. | ||
* | ||
* <p>Metrics are updated by calling the appropriate method on the metric object instance. For | ||
* example, to increment a counter, call {@link Counter#increment()}. | ||
*/ | ||
public class MetricsServiceImpl implements MetricsService { | ||
|
||
private static final String CATEGORY = "hedera_block_node_simulator"; | ||
|
||
private final EnumMap<SimulatorMetricTypes.Counter, Counter> counters = | ||
new EnumMap<>(SimulatorMetricTypes.Counter.class); | ||
|
||
/** | ||
* Create singleton instance of metrics service to be used throughout the application. | ||
* | ||
* @param metrics the metrics instance | ||
*/ | ||
@Inject | ||
public MetricsServiceImpl(@NonNull final Metrics metrics) { | ||
// Initialize the counters | ||
for (SimulatorMetricTypes.Counter counter : SimulatorMetricTypes.Counter.values()) { | ||
counters.put( | ||
counter, | ||
metrics.getOrCreate(new Counter.Config(CATEGORY, counter.grafanaLabel()) | ||
.withDescription(counter.description()))); | ||
} | ||
} | ||
|
||
/** | ||
* Use this method to get a specific counter for the given metric type. | ||
* | ||
* @param key to get a specific counter | ||
* @return the counter | ||
*/ | ||
@NonNull | ||
@Override | ||
public Counter get(@NonNull SimulatorMetricTypes.Counter key) { | ||
return counters.get(key); | ||
} | ||
} |
Oops, something went wrong.