Skip to content

Commit

Permalink
#7265 Remove Settings, SettingsCommon (#7281)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Brandstätter <[email protected]>
  • Loading branch information
timo0 authored and agadzhalov committed Jul 3, 2023
1 parent c0294f6 commit 6a9eea9
Show file tree
Hide file tree
Showing 19 changed files with 174 additions and 853 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
* @param genesisFreezeTime
* If this node starts from genesis, this value is used as the freeze time. This feature is deprecated and
* planned for removal in a future platform version.
* @param deadlockCheckPeriod
* check for deadlocks every this many milliseconds (-1 for never)
* @param statsBufferSize
* number of bins to store for the history (in StatsBuffer etc.)
* @param statsRecentSeconds
* number of seconds covered by "recent" history (in StatsBuffer etc.)
*/
@ConfigData
public record BasicConfig(
Expand Down Expand Up @@ -164,7 +170,10 @@ public record BasicConfig(
@ConfigProperty(defaultValue = "log4j2.xml") Path logPath,
@ConfigProperty(defaultValue = "60s") Duration hangingThreadDuration,
@ConfigProperty(defaultValue = "data/saved") String emergencyRecoveryFileLoadDir,
@ConfigProperty(defaultValue = "0") long genesisFreezeTime) {
@ConfigProperty(defaultValue = "0") long genesisFreezeTime,
@ConfigProperty(defaultValue = "1000") int deadlockCheckPeriod,
@ConfigProperty(defaultValue = "100") int statsBufferSize,
@ConfigProperty(defaultValue = "63") double statsRecentSeconds) {

/**
* @return Absolute path to the emergency recovery file load directory.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
import com.swirlds.common.system.NodeId;
import com.swirlds.common.utility.CommonUtils;
import com.swirlds.config.api.Configuration;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executors;
Expand All @@ -59,14 +61,15 @@ public class DefaultMetricsProvider implements MetricsProvider, Lifecycle {
private final PrometheusEndpoint prometheusEndpoint;
private final SnapshotService snapshotService;
private final MetricsConfig metricsConfig;
private final Configuration configuration;

private LifecyclePhase lifecyclePhase = LifecyclePhase.NOT_STARTED;

/**
* Constructor of {@code DefaultMetricsProvider}
*/
public DefaultMetricsProvider(final Configuration configuration) {
CommonUtils.throwArgNull(configuration, "configuration");
public DefaultMetricsProvider(@NonNull final Configuration configuration) {
this.configuration = Objects.requireNonNull(configuration, "configuration is null");

metricsConfig = configuration.getConfigData(MetricsConfig.class);
final PrometheusConfig prometheusConfig = configuration.getConfigData(PrometheusConfig.class);
Expand Down Expand Up @@ -128,7 +131,7 @@ public Metrics createPlatformMetrics(final NodeId nodeId) {

// setup LegacyCsvWriter
if (StringUtils.isNotBlank(metricsConfig.csvFileName())) {
final LegacyCsvWriter legacyCsvWriter = new LegacyCsvWriter(nodeId, folderPath, metricsConfig);
final LegacyCsvWriter legacyCsvWriter = new LegacyCsvWriter(nodeId, folderPath, configuration);
snapshotService.subscribe(legacyCsvWriter::handleSnapshots);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.swirlds.common.metrics.platform;

import static com.swirlds.common.utility.CommonUtils.throwArgNull;
import static com.swirlds.logging.LogMarker.EXCEPTION;
import static com.swirlds.logging.LogMarker.STARTUP;
import static java.lang.Double.isInfinite;
Expand All @@ -26,13 +25,15 @@
import static java.nio.file.StandardOpenOption.TRUNCATE_EXISTING;
import static org.apache.commons.lang3.builder.ToStringStyle.SHORT_PREFIX_STYLE;

import com.swirlds.common.internal.SettingsCommon;
import com.swirlds.common.config.BasicConfig;
import com.swirlds.common.metrics.Metric;
import com.swirlds.common.metrics.Metric.ValueType;
import com.swirlds.common.metrics.Metrics;
import com.swirlds.common.metrics.config.MetricsConfig;
import com.swirlds.common.system.NodeId;
import com.swirlds.common.utility.ThresholdLimitingHandler;
import com.swirlds.config.api.Configuration;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -85,6 +86,7 @@ public class LegacyCsvWriter {
// path and filename of the .csv file to write to
private final Path csvFilePath;
private final MetricsConfig metricsConfig;
private final BasicConfig basicConfig;

private final Map<Pair<String, String>, Integer> indexLookup = new HashMap<>();
private final List<Integer> cellCount = new ArrayList<>();
Expand All @@ -98,16 +100,20 @@ public class LegacyCsvWriter {
* Constructor of a {@code LegacyCsvWriter}
*
* @param selfId
* {@link NodeId} of the platform for which the CSV-file is written
* {@link NodeId} of the platform for which the CSV-file is written
* @param folderPath
* {@link Path} to the folder where the file should be stored
* @param metricsConfig
* the metrics configuration
* {@link Path} to the folder where the file should be stored
* @param configuration
* the configuration
*/
public LegacyCsvWriter(final NodeId selfId, final Path folderPath, final MetricsConfig metricsConfig) {
this.selfId = throwArgNull(selfId, "selfId");
throwArgNull(folderPath, "folderPath");
this.metricsConfig = throwArgNull(metricsConfig, "metricsConfig");
public LegacyCsvWriter(
@NonNull final NodeId selfId, @NonNull final Path folderPath, @NonNull final Configuration configuration) {
Objects.requireNonNull(folderPath, "folderPath is null");
Objects.requireNonNull(configuration, "configuration is null");

this.selfId = Objects.requireNonNull(selfId, "selfId is null");
metricsConfig = configuration.getConfigData(MetricsConfig.class);
basicConfig = configuration.getConfigData(BasicConfig.class);

final String fileName = String.format("%s%d.csv", metricsConfig.csvFileName(), selfId.id());
this.csvFilePath = folderPath.resolve(fileName);
Expand All @@ -127,7 +133,7 @@ public Path getCsvFilePath() {
* it is not possible to add new metrics.
*
* @param snapshots
* {@link List} of {@link Snapshot}s of all known metrics at this point in time
* {@link List} of {@link Snapshot}s of all known metrics at this point in time
*/
private void init(final Collection<Snapshot> snapshots) {
logger.info(
Expand All @@ -139,7 +145,7 @@ private void init(final Collection<Snapshot> snapshots) {
// eventually filter out internal metrics
final List<Metric> filteredMetrics = snapshots.stream()
.map(Snapshot::metric)
.filter(LegacyCsvWriter::shouldWrite)
.filter(this::shouldWrite)
.toList();

indexLookup.clear();
Expand All @@ -153,7 +159,6 @@ private void init(final Collection<Snapshot> snapshots) {
try {
// create parent folder, if it does not exist
ensureFolderExists();

if (metricsConfig.csvAppend() && Files.exists(csvFilePath)) {
// make sure last line of previous test was ended, and a blank line is inserted between tests.
Files.writeString(csvFilePath, "\n\n", StandardOpenOption.APPEND);
Expand Down Expand Up @@ -185,13 +190,16 @@ private void init(final Collection<Snapshot> snapshots) {
}
}

@SuppressWarnings("deprecation")
private static boolean showAllEntries(final Metric metric) {
return SettingsCommon.verboseStatistics && !metric.getCategory().contains(EXCLUDE_CATEGORY);
private boolean showAllEntries(@NonNull final Metric metric) {
Objects.requireNonNull(metric, "metric is null");
return basicConfig.verboseStatistics() && !metric.getCategory().contains(EXCLUDE_CATEGORY);
}

// Add two rows, one with all categories, the other with all names
private static void addHeaderRows(final ContentBuilder builder, final List<Metric> metrics) {
private void addHeaderRows(@NonNull final ContentBuilder builder, @NonNull final List<Metric> metrics) {
Objects.requireNonNull(builder, "builder is null");
Objects.requireNonNull(metrics, "metrics is null");

final List<String> categories = new ArrayList<>();
final List<String> names = new ArrayList<>();
for (final Metric metric : metrics) {
Expand Down Expand Up @@ -315,9 +323,9 @@ private String format(final Metric metric, final Object value) {
}

// Returns false, if a Metric is internal and internal metrics should not be written
@SuppressWarnings("deprecation")
private static boolean shouldWrite(final Metric metric) {
return SettingsCommon.showInternalStats || !metric.getCategory().equals(Metrics.INTERNAL_CATEGORY);
private boolean shouldWrite(@NonNull final Metric metric) {
Objects.requireNonNull(metric, "metric is null");
return basicConfig.showInternalStats() || !metric.getCategory().equals(Metrics.INTERNAL_CATEGORY);
}

// Ensure that the parent folder specified by {@link #csvFilePath} exists and if not create it recursively.
Expand Down
Loading

0 comments on commit 6a9eea9

Please sign in to comment.