-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Alfredo Gutierrez <[email protected]>
- Loading branch information
1 parent
5161410
commit 1a98d20
Showing
16 changed files
with
428 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Metrics | ||
This document describes the metrics that are available in the system, its purpose, and how to use them. | ||
|
||
## Overview | ||
We are using Prometheus to collect metrics from the system, through the use of [Hedera Platform SDK - Metrics](https://github.com/hashgraph/hedera-services/blob/develop/platform-sdk/docs/base/metrics/metrics.md). | ||
|
||
|
||
## Purpose | ||
|
||
The purpose of metrics is to provide a way to measure the performance of the system. Metrics are used to monitor the system and to detect any issues that may arise. Metrics can be used to identify bottlenecks, track the performance of the system over time, and to help diagnose problems. | ||
|
||
## Configuration | ||
|
||
### Prometheus | ||
|
||
Prefix: prometheus, ie. `prometheus.configKey` | ||
|
||
| ConfigKey | Description | Default | | ||
|----------------------------|---------------------------------------------------------------------------------------|-------------| | ||
| enableEndpoint | either `true` or `false`. Enables or disables the endpoint for metrics | true | | ||
| endpointPortNumber | Port of the Prometheus endpoint | 9999 | | ||
| endpointMaxBacklogAllowed | The maximum number of incoming TCP connections which the system will queue internally | 1 | | ||
|
||
## Usage | ||
All classes that need to observe metrics can get them from the BlockNodeContext. | ||
|
||
If a new metric is needed, it can be added to MetricsService, and then used in the classes that need it. This is to avoid having to define the metrics in several places. | ||
MetricsService centralizes the creation of metrics and provides a way to access them from any other class. | ||
|
||
To check the metrics you can access the Prometheus endpoint at `http://localhost:9999/metrics`. | ||
|
||
## Existing Metrics | ||
|
||
| Metric Name | Description | Type | | ||
|----------------|---------------------------|---------| | ||
| exampleGauge | An example gauge metric | Gauge | | ||
| exampleCounter | An example counter metric | Counter | |
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
41 changes: 41 additions & 0 deletions
41
server/src/main/java/com/hedera/block/server/config/BlockNodeConfigExtension.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,41 @@ | ||
/* | ||
* 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.server.config; | ||
|
||
import com.google.auto.service.AutoService; | ||
import com.swirlds.common.config.BasicCommonConfig; | ||
import com.swirlds.common.metrics.config.MetricsConfig; | ||
import com.swirlds.common.metrics.platform.prometheus.PrometheusConfig; | ||
import com.swirlds.config.api.ConfigurationExtension; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.util.Set; | ||
|
||
/** Registers configuration types for the server. */ | ||
@AutoService(ConfigurationExtension.class) | ||
public class BlockNodeConfigExtension implements ConfigurationExtension { | ||
|
||
/** | ||
* {@inheritDoc} | ||
* | ||
* @return Set of configuration data types for the server | ||
*/ | ||
@NonNull | ||
@Override | ||
public Set<Class<? extends Record>> getConfigDataTypes() { | ||
return Set.of(BasicCommonConfig.class, MetricsConfig.class, PrometheusConfig.class); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
server/src/main/java/com/hedera/block/server/config/BlockNodeContext.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,35 @@ | ||
/* | ||
* 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.server.config; | ||
|
||
import com.hedera.block.server.metrics.MetricsService; | ||
import com.swirlds.config.api.Configuration; | ||
import com.swirlds.metrics.api.Metrics; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
/** | ||
* Context for the block node. This record is returned by the BlockNodeContextFactory when a new | ||
* configuration is created. | ||
* | ||
* @param metrics the metrics used for monitoring and reporting | ||
* @param metricsService the service responsible for handling metrics | ||
* @param configuration the configuration settings for the block node | ||
*/ | ||
public record BlockNodeContext( | ||
@NonNull Metrics metrics, | ||
@NonNull MetricsService metricsService, | ||
@NonNull Configuration configuration) {} |
66 changes: 66 additions & 0 deletions
66
server/src/main/java/com/hedera/block/server/config/BlockNodeContextFactory.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,66 @@ | ||
/* | ||
* 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.server.config; | ||
|
||
import com.hedera.block.server.metrics.MetricsService; | ||
import com.swirlds.common.metrics.platform.DefaultMetricsProvider; | ||
import com.swirlds.config.api.Configuration; | ||
import com.swirlds.config.api.ConfigurationBuilder; | ||
import com.swirlds.config.extensions.sources.ClasspathFileConfigSource; | ||
import com.swirlds.config.extensions.sources.SystemEnvironmentConfigSource; | ||
import com.swirlds.config.extensions.sources.SystemPropertiesConfigSource; | ||
import com.swirlds.metrics.api.Metrics; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
|
||
/** Static factory that creates {@link BlockNodeContext} */ | ||
public class BlockNodeContextFactory { | ||
|
||
private static final String APPLICATION_PROPERTIES_1 = "app.properties"; | ||
|
||
private BlockNodeContextFactory() {} | ||
|
||
/** | ||
* @return an instance of {@link BlockNodeContext} which holds {@link Configuration}, {@link | ||
* Metrics} and {@link MetricsService} for the rest of the application to use. | ||
*/ | ||
public static BlockNodeContext create() throws IOException { | ||
final Configuration configuration = getConfiguration(); | ||
final Metrics metrics = getMetrics(configuration); | ||
final MetricsService metricsService = new MetricsService(metrics); | ||
return new BlockNodeContext(metrics, metricsService, configuration); | ||
} | ||
|
||
private static Configuration getConfiguration() throws IOException { | ||
|
||
return ConfigurationBuilder.create() | ||
.withSource(SystemEnvironmentConfigSource.getInstance()) | ||
.withSource(SystemPropertiesConfigSource.getInstance()) | ||
.withSource(new ClasspathFileConfigSource(Path.of(APPLICATION_PROPERTIES_1))) | ||
.autoDiscoverExtensions() | ||
.build(); | ||
} | ||
|
||
@NonNull | ||
private static Metrics getMetrics(@NonNull final Configuration configuration) { | ||
final DefaultMetricsProvider metricsProvider = new DefaultMetricsProvider(configuration); | ||
final Metrics metrics = metricsProvider.createGlobalMetrics(); | ||
metricsProvider.start(); | ||
return metrics; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
server/src/main/java/com/hedera/block/server/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,49 @@ | ||
/* | ||
* 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.server.metrics; | ||
|
||
import com.swirlds.metrics.api.Counter; | ||
import com.swirlds.metrics.api.LongGauge; | ||
import com.swirlds.metrics.api.Metrics; | ||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
|
||
public class MetricsService { | ||
|
||
private static final String CATEGORY = "app"; | ||
|
||
private static final LongGauge.Config EXAMPLE_GAUGE = | ||
new LongGauge.Config(CATEGORY, "exampleGauge").withDescription("An example gauge"); | ||
|
||
/** An example gauge. */ | ||
public final LongGauge exampleGauge; | ||
|
||
private static final Counter.Config EXAMPLE_COUNTER = | ||
new Counter.Config(CATEGORY, "exampleCounter").withDescription("An example counter"); | ||
|
||
/** An example counter. */ | ||
public final Counter exampleCounter; | ||
|
||
/** | ||
* Creates a new instance of {@link MetricsService}. | ||
* | ||
* @param metrics the metrics instance | ||
*/ | ||
public MetricsService(@NonNull final Metrics metrics) { | ||
this.exampleGauge = metrics.getOrCreate(EXAMPLE_GAUGE); | ||
this.exampleCounter = metrics.getOrCreate(EXAMPLE_COUNTER); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
import com.hedera.block.server.config.BlockNodeConfigExtension; | ||
|
||
/** Runtime module of the server. */ | ||
module com.hedera.block.server { | ||
requires com.hedera.block.protos; | ||
requires com.google.protobuf; | ||
requires com.swirlds.common; | ||
requires com.swirlds.config.api; | ||
requires com.swirlds.config.extensions; | ||
requires com.swirlds.metrics.api; | ||
requires io.grpc.stub; | ||
requires io.helidon.common; | ||
requires io.helidon.config; | ||
requires io.helidon.webserver.grpc; | ||
requires io.helidon.webserver; | ||
requires static com.github.spotbugs.annotations; | ||
requires static com.google.auto.service; | ||
|
||
provides com.swirlds.config.api.ConfigurationExtension with | ||
BlockNodeConfigExtension; | ||
} |
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 @@ | ||
prometheus.endpointPortNumber=9999 |
33 changes: 33 additions & 0 deletions
33
server/src/test/java/com/hedera/block/server/config/BlockNodeContextFactoryTest.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,33 @@ | ||
/* | ||
* 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.server.config; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.IOException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class BlockNodeContextFactoryTest { | ||
|
||
@Test | ||
void create_returnsBlockNodeContext() throws IOException { | ||
BlockNodeContext context = BlockNodeContextFactory.create(); | ||
|
||
assertNotNull(context.metrics()); | ||
assertNotNull(context.configuration()); | ||
} | ||
} |
Oops, something went wrong.