Skip to content

Commit

Permalink
Improved the BlockNodeContext to include the MetricsService
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 6, 2024
1 parent 12d59b8 commit 928207f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
7 changes: 1 addition & 6 deletions server/src/main/java/com/hedera/block/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.hedera.block.server.persistence.WriteThroughCacheHandler;
import com.hedera.block.server.persistence.storage.BlockStorage;
import com.hedera.block.server.persistence.storage.FileSystemBlockStorage;
import com.swirlds.metrics.api.Metrics;
import io.grpc.stub.ServerCalls;
import io.grpc.stub.StreamObserver;
import io.helidon.config.Config;
Expand All @@ -51,9 +50,6 @@ public class Server {

private static final System.Logger LOGGER = System.getLogger(Server.class.getName());

private static Metrics metrics;
private static MetricsService metricsService;

private Server() {}

/**
Expand All @@ -66,10 +62,9 @@ public static void main(final String[] args) {
try {
// init metrics
BlockNodeContext blockNodeContext = BlockNodeContextFactory.create();
metrics = blockNodeContext.metrics();
metricsService = new MetricsService(metrics);

// increase by 1 just for the sake of an example
MetricsService metricsService = blockNodeContext.metricsService();
metricsService.exampleCounter.increment();

// Set the global configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

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;

public record BlockNodeContext(Metrics metrics, Configuration configuration) {}
public record BlockNodeContext(Metrics metrics, MetricsService metricsService, Configuration configuration) {}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

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;
Expand All @@ -37,7 +38,8 @@ private BlockNodeContextFactory() {}
public static BlockNodeContext create() {
final Configuration configuration = getConfiguration();
final Metrics metrics = getMetrics(configuration);
return new BlockNodeContext(metrics, configuration);
final MetricsService metricsService = new MetricsService(metrics);
return new BlockNodeContext(metrics, metricsService, configuration);
}

private static Configuration getConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import com.hedera.block.server.metrics.MetricsService;
import com.swirlds.config.api.Configuration;
import com.swirlds.metrics.api.Metrics;
import org.junit.jupiter.api.Test;
Expand All @@ -29,10 +30,12 @@ class BlockNodeContextTest {
void BlockNodeContext_initializesWithMetricsAndConfiguration() {
Metrics metrics = mock(Metrics.class);
Configuration configuration = mock(Configuration.class);
MetricsService metricsService = mock(MetricsService.class);

BlockNodeContext context = new BlockNodeContext(metrics, configuration);
BlockNodeContext context = new BlockNodeContext(metrics, metricsService, configuration);

assertEquals(metrics, context.metrics());
assertEquals(metricsService, context.metricsService());
assertEquals(configuration, context.configuration());
}
}

0 comments on commit 928207f

Please sign in to comment.