Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collectors migration from PA-RCA #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ configurations.each {

compileJava {
dependsOn spotlessApply
JavaVersion targetVersion = JavaVersion.toVersion(targetCompatibility);
if (targetVersion.isJava9Compatible()) {
options.compilerArgs += ["--add-exports", "jdk.attach/sun.tools.attach=ALL-UNNAMED"]
options.compilerArgs += ["--add-exports", "jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED"]
}
}

test {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.performanceanalyzer.commons;


import org.opensearch.performanceanalyzer.commons.config.ConfigStatus;
import org.opensearch.performanceanalyzer.commons.metrics_generator.OSMetricsGenerator;
import org.opensearch.performanceanalyzer.commons.metrics_generator.linux.LinuxOSMetricsGenerator;

public class OSMetricsGeneratorFactory {

private static final String OS_TYPE = System.getProperty("os.name");

public static OSMetricsGenerator getInstance() {

if (isLinux()) {
return LinuxOSMetricsGenerator.getInstance();
} else {
ConfigStatus.INSTANCE.setConfigurationInvalid();
}

return null;
}

private static boolean isLinux() {
return OS_TYPE.toLowerCase().contains("linux");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.performanceanalyzer.commons.collectors;


import java.util.*;
import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.ShardStatsValue;

class CachedStats {
private static final Set<String> CACHABLE_VALUES =
new HashSet<>(
Arrays.asList(
ShardStatsValue.INDEXING_THROTTLE_TIME.toString(),
ShardStatsValue.CACHE_QUERY_HIT.toString(),
ShardStatsValue.CACHE_QUERY_MISS.toString(),
ShardStatsValue.CACHE_FIELDDATA_EVICTION.toString(),
ShardStatsValue.CACHE_REQUEST_HIT.toString(),
ShardStatsValue.CACHE_REQUEST_MISS.toString(),
ShardStatsValue.CACHE_REQUEST_EVICTION.toString(),
ShardStatsValue.REFRESH_EVENT.toString(),
ShardStatsValue.REFRESH_TIME.toString(),
ShardStatsValue.FLUSH_EVENT.toString(),
ShardStatsValue.FLUSH_TIME.toString(),
ShardStatsValue.MERGE_EVENT.toString(),
ShardStatsValue.MERGE_TIME.toString()));
private Map<String, Long> cachedValues = new HashMap<>();

long getValue(String statsName) {
return cachedValues.getOrDefault(statsName, 0L);
}

void putValue(String statsName, long value) {
cachedValues.put(statsName, value);
}

static Set<String> getCachableValues() {
return CACHABLE_VALUES;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.performanceanalyzer.commons.collectors;


import com.fasterxml.jackson.annotation.JsonProperty;
import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.DiskDimension;
import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.DiskValue;

public class DiskMetrics extends MetricStatus {
public String name;

public double utilization; // fraction, 0-1

public double await; // ms

public double serviceRate; // MBps

public DiskMetrics(String name, double utilization, double await, double serviceRate) {
super();
this.name = name;
this.utilization = utilization;
this.await = await;
this.serviceRate = serviceRate;
}

public DiskMetrics() {
super();
}

@JsonProperty(DiskDimension.Constants.NAME_VALUE)
public String getName() {
return name;
}

@JsonProperty(DiskValue.Constants.UTIL_VALUE)
public double getUtilization() {
return utilization;
}

@JsonProperty(DiskValue.Constants.WAIT_VALUE)
public double getAwait() {
return await;
}

@JsonProperty(DiskValue.Constants.SRATE_VALUE)
public double getServiceRate() {
return serviceRate;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.performanceanalyzer.commons.collectors;


import java.util.HashMap;
import java.util.Map;
import org.opensearch.performanceanalyzer.commons.OSMetricsGeneratorFactory;
import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor;
import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics;
import org.opensearch.performanceanalyzer.commons.metrics_generator.DiskMetricsGenerator;
import org.opensearch.performanceanalyzer.commons.metrics_generator.OSMetricsGenerator;
import org.opensearch.performanceanalyzer.commons.stats.CommonStats;
import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode;
import org.opensearch.performanceanalyzer.commons.stats.metrics.WriterMetrics;

public class DisksCollector extends PerformanceAnalyzerMetricsCollector
implements MetricsProcessor {

public DisksCollector(String name, int samplingIntervalMillis) {
super(
samplingIntervalMillis,
name,
WriterMetrics.DISKS_COLLECTOR_EXECUTION_TIME,
StatExceptionCode.DISK_METRICS_COLLECTOR_ERROR);
}

@Override
public String getMetricsPath(long startTime, String... keysPath) {
// throw exception if keys.length is not equal to 0
if (keysPath.length != 0) {
throw new RuntimeException("keys length should be 0");
}

return PerformanceAnalyzerMetrics.generatePath(
startTime, PerformanceAnalyzerMetrics.sDisksPath);
}

@Override
public void collectMetrics(long startTime) {
OSMetricsGenerator generator = OSMetricsGeneratorFactory.getInstance();
if (generator == null) {
return;
}
long mCurrT = System.currentTimeMillis();
DiskMetricsGenerator diskMetricsGenerator = generator.getDiskMetricsGenerator();
diskMetricsGenerator.addSample();

saveMetricValues(getMetrics(diskMetricsGenerator), startTime);
CommonStats.WRITER_METRICS_AGGREGATOR.updateStat(
WriterMetrics.DISKS_COLLECTOR_EXECUTION_TIME,
"",
System.currentTimeMillis() - mCurrT);
}

private Map<String, DiskMetrics> getMetricsMap(DiskMetricsGenerator diskMetricsGenerator) {

Map<String, DiskMetrics> map = new HashMap<>();

for (String disk : diskMetricsGenerator.getAllDisks()) {
DiskMetrics diskMetrics = new DiskMetrics();
diskMetrics.name = disk;
diskMetrics.await = diskMetricsGenerator.getAwait(disk);
diskMetrics.serviceRate = diskMetricsGenerator.getServiceRate(disk);
diskMetrics.utilization = diskMetricsGenerator.getDiskUtilization(disk);

map.put(disk, diskMetrics);
}

return map;
}

private String getMetrics(DiskMetricsGenerator diskMetricsGenerator) {

Map<String, DiskMetrics> map = getMetricsMap(diskMetricsGenerator);
value.setLength(0);
value.append(PerformanceAnalyzerMetrics.getJsonCurrentMilliSeconds())
.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor);
for (Map.Entry<String, DiskMetrics> entry : map.entrySet()) {
value.append(entry.getValue().serialize())
.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor);
}
return value.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

package org.opensearch.performanceanalyzer.commons.collectors;


import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Map;
import java.util.function.Supplier;
import org.opensearch.performanceanalyzer.commons.jvm.GarbageCollectorInfo;
import org.opensearch.performanceanalyzer.commons.metrics.AllMetrics.GCInfoDimension;
import org.opensearch.performanceanalyzer.commons.metrics.MetricsProcessor;
import org.opensearch.performanceanalyzer.commons.metrics.PerformanceAnalyzerMetrics;
import org.opensearch.performanceanalyzer.commons.stats.CommonStats;
import org.opensearch.performanceanalyzer.commons.stats.metrics.StatExceptionCode;
import org.opensearch.performanceanalyzer.commons.stats.metrics.WriterMetrics;

/**
* A collector that collects info about the current garbage collectors for various regions in the
* heap.
*/
public class GCInfoCollector extends PerformanceAnalyzerMetricsCollector
implements MetricsProcessor {

private static final int EXPECTED_KEYS_PATH_LENGTH = 0;

public GCInfoCollector(String name, int samplingIntervalMillis) {
super(
samplingIntervalMillis,
name,
WriterMetrics.GC_INFO_COLLECTOR_EXECUTION_TIME,
StatExceptionCode.GC_INFO_COLLECTOR_ERROR);
}

@Override
public void collectMetrics(long startTime) {
long mCurrT = System.currentTimeMillis();
// Zero the string builder
value.setLength(0);

// first line is the timestamp
value.append(PerformanceAnalyzerMetrics.getJsonCurrentMilliSeconds())
.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor);

for (Map.Entry<String, Supplier<String>> entry :
GarbageCollectorInfo.getGcSuppliers().entrySet()) {
value.append(new GCInfo(entry.getKey(), entry.getValue().get()).serialize())
.append(PerformanceAnalyzerMetrics.sMetricNewLineDelimitor);
}

saveMetricValues(value.toString(), startTime);
CommonStats.WRITER_METRICS_AGGREGATOR.updateStat(
WriterMetrics.GC_INFO_COLLECTOR_EXECUTION_TIME,
"",
System.currentTimeMillis() - mCurrT);
}

@Override
public String getMetricsPath(long startTime, String... keysPath) {
if (keysPath != null && keysPath.length != EXPECTED_KEYS_PATH_LENGTH) {
throw new RuntimeException("keys length should be " + EXPECTED_KEYS_PATH_LENGTH);
}

return PerformanceAnalyzerMetrics.generatePath(
startTime, PerformanceAnalyzerMetrics.sGcInfoPath);
}

public static class GCInfo extends MetricStatus {
private String memoryPool;
private String collectorName;

public GCInfo() {}

public GCInfo(final String memoryPool, final String collectorName) {
this.memoryPool = memoryPool;
this.collectorName = collectorName;
}

@JsonProperty(GCInfoDimension.Constants.MEMORY_POOL_VALUE)
public String getMemoryPool() {
return memoryPool;
}

@JsonProperty(GCInfoDimension.Constants.COLLECTOR_NAME_VALUE)
public String getCollectorName() {
return collectorName;
}
}
}
Loading