diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 5cfcaf28..eedd9b81 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -3,10 +3,10 @@ name: Java CI on: push: branches: - - master + - main pull_request: branches: - - master + - main jobs: build_rca_pkg: @@ -22,6 +22,10 @@ jobs: uses: actions/checkout@v2 with: path: ./tmp/pa + # fetch the main branch to make it available for spotless ratcheting + - name: Fetch 'main' branch + working-directory: ./tmp/pa + run: git fetch --depth=1 origin main - name: Set up JDK 1.12 uses: actions/setup-java@v1 with: diff --git a/build.gradle b/build.gradle index 8ee8984d..51c84d3c 100644 --- a/build.gradle +++ b/build.gradle @@ -34,9 +34,8 @@ plugins { id 'java' id 'nebula.ospackage' version "8.3.0" id 'com.github.spotbugs' version '4.6.0' - id 'checkstyle' id 'jacoco' - id 'com.diffplug.spotless' version '5.8.2' + id 'com.diffplug.spotless' version '5.11.0' } spotbugsMain { @@ -71,13 +70,23 @@ ext { projectSubstitutions = [:] licenseFile = rootProject.file('LICENSE.txt') noticeFile = rootProject.file('NOTICE.txt') + gitDefaultBranch = 'main' } -apply plugin: 'com.diffplug.spotless' - spotless { java { + // only apply formatting rules to updated files + ratchetFrom "origin/${gitDefaultBranch}" + licenseHeaderFile(file('license-header')) + googleJavaFormat().aosp() + importOrder() + removeUnusedImports() + trimTrailingWhitespace() + endWithNewline() + + // add support for spotless:off and spotless:on tags to exclude sections of code + toggleOffOn() } } @@ -88,6 +97,8 @@ test { licenseHeaders.enabled = false validateNebulaPom.enabled = false + + loggerUsageCheck.enabled = false esplugin { @@ -188,13 +199,8 @@ jacocoTestCoverageVerification { // to run coverage verification during the build (and fail when appropriate) check.dependsOn jacocoTestCoverageVerification -checkstyle { - toolVersion = '8.24' - configFile file("checkstyle/checkstyle.xml") -} - -checkstyleMain.ignoreFailures = true -checkstyleTest.ignoreFailures = true +checkstyleMain.enabled = false +checkstyleTest.enabled = false dependencies { if (JavaVersion.current() <= JavaVersion.VERSION_1_8) { @@ -209,7 +215,6 @@ dependencies { configurations.all { resolutionStrategy { - force "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}" force 'com.fasterxml.jackson.core:jackson-databind:2.10.5.1' force 'com.fasterxml.jackson.core:jackson-core:2.10.5' force 'com.fasterxml.jackson.dataformat:jackson-dataformat-smile:2.10.5' @@ -263,8 +268,6 @@ dependencies { force = 'true' } testCompile group: 'com.google.code.gson', name: 'gson', version: '2.8.6' - - checkstyle "com.puppycrawl.tools:checkstyle:${project.checkstyle.toolVersion}" } dependencyLicenses { @@ -300,6 +303,7 @@ task cloneGitRepo(type: GitClone) { rcaDir = Paths.get(getProject().getBuildDir().toString(), "performance-analyzer-rca").toString() def destination = file(rcaDir) uri = "https://github.com/opendistro-for-elasticsearch/performance-analyzer-rca.git" + branch = gitDefaultBranch destinationPath = destination bare = false enabled = !destination.exists() // to clone only once diff --git a/licenses/bcpkix-jdk15on-1.66.jar.sha1 b/licenses/bcpkix-jdk15on-1.66.jar.sha1 deleted file mode 100644 index 7a5b700b..00000000 --- a/licenses/bcpkix-jdk15on-1.66.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -86cca2c1a32775abe92316d9628b7ee50b6f19ad \ No newline at end of file diff --git a/licenses/bcprov-jdk15on-1.66.jar.sha1 b/licenses/bcprov-jdk15on-1.66.jar.sha1 deleted file mode 100644 index 009cae20..00000000 --- a/licenses/bcprov-jdk15on-1.66.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -ed564ade61defca27e26fb1378a70b22831fc5c1 \ No newline at end of file diff --git a/licenses/jackson-annotations-2.10.4.jar.sha1 b/licenses/jackson-annotations-2.10.4.jar.sha1 deleted file mode 100644 index 0c548bb0..00000000 --- a/licenses/jackson-annotations-2.10.4.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -6ae6028aff033f194c9710ad87c224ccaadeed6c \ No newline at end of file diff --git a/licenses/jackson-databind-2.10.4.jar.sha1 b/licenses/jackson-databind-2.10.4.jar.sha1 deleted file mode 100644 index 27d5a72c..00000000 --- a/licenses/jackson-databind-2.10.4.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -76e9152e93d4cf052f93a64596f633ba5b1c8ed9 \ No newline at end of file diff --git a/licenses/performanceanalyzer-rca-1.13.jar.sha1 b/licenses/performanceanalyzer-rca-1.13.jar.sha1 index 1959cbc9..0c4379d5 100644 --- a/licenses/performanceanalyzer-rca-1.13.jar.sha1 +++ b/licenses/performanceanalyzer-rca-1.13.jar.sha1 @@ -1 +1 @@ -0ca252df95b9c0743d7b29452c7637504d5ba50f \ No newline at end of file +0d0d568122db55b2a11cf5d0f562d754e2bcf898 \ No newline at end of file diff --git a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerPlugin.java b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerPlugin.java index 29c75d0c..e2ef527e 100644 --- a/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerPlugin.java +++ b/src/main/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/PerformanceAnalyzerPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2019-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -21,11 +21,11 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.AdmissionControlMetricsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.CacheConfigMetricsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.CircuitBreakerCollector; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.ClusterApplierServiceStatsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.DisksCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.FaultDetectionMetricsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.GCInfoCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.HeapMetricsCollector; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.ShardIndexingPressureMetricsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.MasterServiceEventMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.MasterServiceMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.MasterThrottlingMetricsCollector; @@ -36,11 +36,10 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.NodeStatsFixedShardsMetricsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.OSMetricsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.ScheduledMetricCollectorsExecutor; +import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.ShardIndexingPressureMetricsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.ShardStateCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.StatsCollector; import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.ThreadPoolMetricsCollector; -import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.ClusterApplierServiceStatsCollector; - import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PerformanceAnalyzerController; import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.PluginSettings; import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.overrides.ConfigOverridesWrapper; @@ -112,7 +111,8 @@ import org.elasticsearch.transport.TransportInterceptor; import org.elasticsearch.watcher.ResourceWatcherService; -public final class PerformanceAnalyzerPlugin extends Plugin implements ActionPlugin, NetworkPlugin, SearchPlugin { +public final class PerformanceAnalyzerPlugin extends Plugin + implements ActionPlugin, NetworkPlugin, SearchPlugin { private static final Logger LOG = LogManager.getLogger(PerformanceAnalyzerPlugin.class); public static final String PLUGIN_NAME = "opendistro-performance-analyzer"; private static final String ADD_FAULT_DETECTION_METHOD = "addFaultDetectionListener"; @@ -130,22 +130,29 @@ public final class PerformanceAnalyzerPlugin extends Plugin implements ActionPlu static { SecurityManager sm = System.getSecurityManager(); Utils.configureMetrics(); - if(sm != null) { + if (sm != null) { // unprivileged code such as scripts do not have SpecialPermission sm.checkPermission(new SpecialPermission()); } } public static void invokePrivileged(Runnable runner) { - AccessController.doPrivileged((PrivilegedAction) () -> { - try { - runner.run(); - } catch(Exception ex) { - LOG.debug((Supplier) () -> new ParameterizedMessage("Privileged Invocation failed {}", - ex.toString()), ex); - } - return null; - } ); + AccessController.doPrivileged( + (PrivilegedAction) + () -> { + try { + runner.run(); + } catch (Exception ex) { + LOG.debug( + (Supplier) + () -> + new ParameterizedMessage( + "Privileged Invocation failed {}", + ex.toString()), + ex); + } + return null; + }); } private final ScheduledMetricCollectorsExecutor scheduledMetricCollectorsExecutor; @@ -155,74 +162,104 @@ public PerformanceAnalyzerPlugin(final Settings settings, final java.nio.file.Pa ESResources.INSTANCE.setSettings(settings); ESResources.INSTANCE.setConfigPath(configPath); - ESResources.INSTANCE.setPluginFileLocation(new Environment(settings, configPath). - pluginsFile().toAbsolutePath().toString() + File.separator + PLUGIN_NAME + File.separator); - //initialize plugin settings. Accessing plugin settings before this - //point will break, as the plugin location will not be initialized. + ESResources.INSTANCE.setPluginFileLocation( + new Environment(settings, configPath).pluginsFile().toAbsolutePath().toString() + + File.separator + + PLUGIN_NAME + + File.separator); + // initialize plugin settings. Accessing plugin settings before this + // point will break, as the plugin location will not be initialized. PluginSettings.instance(); scheduledMetricCollectorsExecutor = new ScheduledMetricCollectorsExecutor(); - this.performanceAnalyzerController = new PerformanceAnalyzerController(scheduledMetricCollectorsExecutor); + this.performanceAnalyzerController = + new PerformanceAnalyzerController(scheduledMetricCollectorsExecutor); configOverridesWrapper = new ConfigOverridesWrapper(); - clusterSettingsManager = new ClusterSettingsManager(Arrays.asList(PerformanceAnalyzerClusterSettings.COMPOSITE_PA_SETTING, - PerformanceAnalyzerClusterSettings.PA_NODE_STATS_SETTING), - Collections.singletonList(PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING)); - configOverridesClusterSettingHandler = new ConfigOverridesClusterSettingHandler(configOverridesWrapper, clusterSettingsManager, - PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING); - clusterSettingsManager.addSubscriberForStringSetting(PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING, + clusterSettingsManager = + new ClusterSettingsManager( + Arrays.asList( + PerformanceAnalyzerClusterSettings.COMPOSITE_PA_SETTING, + PerformanceAnalyzerClusterSettings.PA_NODE_STATS_SETTING), + Collections.singletonList( + PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING)); + configOverridesClusterSettingHandler = + new ConfigOverridesClusterSettingHandler( + configOverridesWrapper, + clusterSettingsManager, + PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING); + clusterSettingsManager.addSubscriberForStringSetting( + PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING, configOverridesClusterSettingHandler); - perfAnalyzerClusterSettingHandler = new PerformanceAnalyzerClusterSettingHandler(performanceAnalyzerController, - clusterSettingsManager); - clusterSettingsManager.addSubscriberForIntSetting(PerformanceAnalyzerClusterSettings.COMPOSITE_PA_SETTING, + perfAnalyzerClusterSettingHandler = + new PerformanceAnalyzerClusterSettingHandler( + performanceAnalyzerController, clusterSettingsManager); + clusterSettingsManager.addSubscriberForIntSetting( + PerformanceAnalyzerClusterSettings.COMPOSITE_PA_SETTING, perfAnalyzerClusterSettingHandler); - nodeStatsSettingHandler = new NodeStatsSettingHandler(performanceAnalyzerController, - clusterSettingsManager); - clusterSettingsManager.addSubscriberForIntSetting(PerformanceAnalyzerClusterSettings.PA_NODE_STATS_SETTING, - nodeStatsSettingHandler); + nodeStatsSettingHandler = + new NodeStatsSettingHandler(performanceAnalyzerController, clusterSettingsManager); + clusterSettingsManager.addSubscriberForIntSetting( + PerformanceAnalyzerClusterSettings.PA_NODE_STATS_SETTING, nodeStatsSettingHandler); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new ThreadPoolMetricsCollector()); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new CacheConfigMetricsCollector()); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new CircuitBreakerCollector()); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new ThreadPoolMetricsCollector()); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new CacheConfigMetricsCollector()); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new CircuitBreakerCollector()); scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new OSMetricsCollector()); scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new HeapMetricsCollector()); scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new MetricsPurgeActivity()); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new NodeDetailsCollector(configOverridesWrapper)); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new - NodeStatsAllShardsMetricsCollector(performanceAnalyzerController)); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new - NodeStatsFixedShardsMetricsCollector(performanceAnalyzerController)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new NodeDetailsCollector(configOverridesWrapper)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new NodeStatsAllShardsMetricsCollector(performanceAnalyzerController)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new NodeStatsFixedShardsMetricsCollector(performanceAnalyzerController)); scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new MasterServiceMetrics()); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new MasterServiceEventMetrics()); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new MasterServiceEventMetrics()); scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new DisksCollector()); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new NetworkInterfaceCollector()); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new NetworkInterfaceCollector()); scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new GCInfoCollector()); scheduledMetricCollectorsExecutor.addScheduledMetricCollector(StatsCollector.instance()); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new FaultDetectionMetricsCollector( - performanceAnalyzerController, configOverridesWrapper)); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new ShardStateCollector( - performanceAnalyzerController,configOverridesWrapper)); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new MasterThrottlingMetricsCollector( - performanceAnalyzerController,configOverridesWrapper)); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new ClusterApplierServiceStatsCollector( - performanceAnalyzerController,configOverridesWrapper)); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new AdmissionControlMetricsCollector()); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new FaultDetectionMetricsCollector( + performanceAnalyzerController, configOverridesWrapper)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new ShardStateCollector(performanceAnalyzerController, configOverridesWrapper)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new MasterThrottlingMetricsCollector( + performanceAnalyzerController, configOverridesWrapper)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new ClusterApplierServiceStatsCollector( + performanceAnalyzerController, configOverridesWrapper)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new AdmissionControlMetricsCollector()); try { Class.forName(ShardIndexingPressureMetricsCollector.SHARD_INDEXING_PRESSURE_CLASS_NAME); - scheduledMetricCollectorsExecutor.addScheduledMetricCollector(new ShardIndexingPressureMetricsCollector( - performanceAnalyzerController,configOverridesWrapper)); + scheduledMetricCollectorsExecutor.addScheduledMetricCollector( + new ShardIndexingPressureMetricsCollector( + performanceAnalyzerController, configOverridesWrapper)); } catch (ClassNotFoundException e) { - LOG.info("Shard IndexingPressure not present in this ES version. Skipping ShardIndexingPressureMetricsCollector"); + LOG.info( + "Shard IndexingPressure not present in this ES version. Skipping ShardIndexingPressureMetricsCollector"); } scheduledMetricCollectorsExecutor.start(); EventLog eventLog = new EventLog(); - EventLogFileHandler eventLogFileHandler = new EventLogFileHandler(eventLog, PluginSettings.instance().getMetricsLocation()); - new EventLogQueueProcessor(eventLogFileHandler, - MetricsConfiguration.SAMPLING_INTERVAL, - QUEUE_PURGE_INTERVAL_MS, performanceAnalyzerController).scheduleExecutor(); + EventLogFileHandler eventLogFileHandler = + new EventLogFileHandler(eventLog, PluginSettings.instance().getMetricsLocation()); + new EventLogQueueProcessor( + eventLogFileHandler, + MetricsConfiguration.SAMPLING_INTERVAL, + QUEUE_PURGE_INTERVAL_MS, + performanceAnalyzerController) + .scheduleExecutor(); } // - http level: bulk, search @@ -233,70 +270,96 @@ public List getActionFilters() { @Override public List> getActions() { - List> actions = new ArrayList<>(1); - actions.add(new ActionHandler<>(WhoAmIAction.INSTANCE, - TransportWhoAmIAction.class)); + List> actions = + new ArrayList<>(1); + actions.add(new ActionHandler<>(WhoAmIAction.INSTANCE, TransportWhoAmIAction.class)); return actions; } - //- shardquery, shardfetch + // - shardquery, shardfetch @Override public void onIndexModule(IndexModule indexModule) { PerformanceAnalyzerSearchListener performanceanalyzerSearchListener = - new PerformanceAnalyzerSearchListener(performanceAnalyzerController); + new PerformanceAnalyzerSearchListener(performanceAnalyzerController); indexModule.addSearchOperationListener(performanceanalyzerSearchListener); } - //follower check, leader check + // follower check, leader check public void onDiscovery(Discovery discovery) { try { Class listenerInjector = Class.forName(LISTENER_INJECTOR_CLASS_PATH); - Object listenerInjectorInstance = listenerInjector.getDeclaredConstructor().newInstance(); - Method addListenerMethod = listenerInjectorInstance.getClass().getMethod(ADD_FAULT_DETECTION_METHOD, - Discovery.class); + Object listenerInjectorInstance = + listenerInjector.getDeclaredConstructor().newInstance(); + Method addListenerMethod = + listenerInjectorInstance + .getClass() + .getMethod(ADD_FAULT_DETECTION_METHOD, Discovery.class); addListenerMethod.invoke(listenerInjectorInstance, discovery); - } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | - IllegalAccessException e) { + } catch (InstantiationException + | InvocationTargetException + | NoSuchMethodException + | IllegalAccessException e) { LOG.debug("Exception while calling addFaultDetectionListener in Discovery"); } catch (ClassNotFoundException e) { LOG.debug("No Class for ListenerInjector detected"); } } - //- shardbulk + // - shardbulk @Override - public List getTransportInterceptors(NamedWriteableRegistry namedWriteableRegistry, ThreadContext threadContext) { - return singletonList(new PerformanceAnalyzerTransportInterceptor(performanceAnalyzerController)); + public List getTransportInterceptors( + NamedWriteableRegistry namedWriteableRegistry, ThreadContext threadContext) { + return singletonList( + new PerformanceAnalyzerTransportInterceptor(performanceAnalyzerController)); } @Override - public List getRestHandlers(final Settings settings, - final RestController restController, - final ClusterSettings clusterSettings, - final IndexScopedSettings indexScopedSettings, - final SettingsFilter settingsFilter, - final IndexNameExpressionResolver indexNameExpressionResolver, - final Supplier nodesInCluster) { - PerformanceAnalyzerConfigAction performanceanalyzerConfigAction = new PerformanceAnalyzerConfigAction( - restController, performanceAnalyzerController); + public List getRestHandlers( + final Settings settings, + final RestController restController, + final ClusterSettings clusterSettings, + final IndexScopedSettings indexScopedSettings, + final SettingsFilter settingsFilter, + final IndexNameExpressionResolver indexNameExpressionResolver, + final Supplier nodesInCluster) { + PerformanceAnalyzerConfigAction performanceanalyzerConfigAction = + new PerformanceAnalyzerConfigAction(restController, performanceAnalyzerController); PerformanceAnalyzerConfigAction.setInstance(performanceanalyzerConfigAction); - PerformanceAnalyzerResourceProvider performanceAnalyzerRp = new PerformanceAnalyzerResourceProvider(settings, restController); - PerformanceAnalyzerClusterConfigAction paClusterConfigAction = new PerformanceAnalyzerClusterConfigAction(settings, - restController, perfAnalyzerClusterSettingHandler, nodeStatsSettingHandler); + PerformanceAnalyzerResourceProvider performanceAnalyzerRp = + new PerformanceAnalyzerResourceProvider(settings, restController); + PerformanceAnalyzerClusterConfigAction paClusterConfigAction = + new PerformanceAnalyzerClusterConfigAction( + settings, + restController, + perfAnalyzerClusterSettingHandler, + nodeStatsSettingHandler); PerformanceAnalyzerOverridesClusterConfigAction paOverridesConfigClusterAction = - new PerformanceAnalyzerOverridesClusterConfigAction(settings, restController, - configOverridesClusterSettingHandler, configOverridesWrapper); - return Arrays.asList(performanceanalyzerConfigAction, paClusterConfigAction, performanceAnalyzerRp, paOverridesConfigClusterAction); + new PerformanceAnalyzerOverridesClusterConfigAction( + settings, + restController, + configOverridesClusterSettingHandler, + configOverridesWrapper); + return Arrays.asList( + performanceanalyzerConfigAction, + paClusterConfigAction, + performanceAnalyzerRp, + paOverridesConfigClusterAction); } @Override @SuppressWarnings("checkstyle:parameternumber") - public Collection createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, - ResourceWatcherService resourceWatcherService, ScriptService scriptService, - NamedXContentRegistry xContentRegistry, Environment environment, - NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry, - IndexNameExpressionResolver indexNameExpressionResolver, - Supplier repositoriesServiceSupplier) { + public Collection createComponents( + Client client, + ClusterService clusterService, + ThreadPool threadPool, + ResourceWatcherService resourceWatcherService, + ScriptService scriptService, + NamedXContentRegistry xContentRegistry, + Environment environment, + NodeEnvironment nodeEnvironment, + NamedWriteableRegistry namedWriteableRegistry, + IndexNameExpressionResolver indexNameExpressionResolver, + Supplier repositoriesServiceSupplier) { ESResources.INSTANCE.setClusterService(clusterService); ESResources.INSTANCE.setThreadPool(threadPool); ESResources.INSTANCE.setEnvironment(environment); @@ -310,24 +373,24 @@ public Collection createComponents(Client client, ClusterService cluster } @Override - public Map> getTransports(Settings settings, ThreadPool threadPool, - PageCacheRecycler pageCacheRecycler, - CircuitBreakerService circuitBreakerService, - NamedWriteableRegistry namedWriteableRegistry, - NetworkService networkService) { + public Map> getTransports( + Settings settings, + ThreadPool threadPool, + PageCacheRecycler pageCacheRecycler, + CircuitBreakerService circuitBreakerService, + NamedWriteableRegistry namedWriteableRegistry, + NetworkService networkService) { ESResources.INSTANCE.setSettings(settings); ESResources.INSTANCE.setCircuitBreakerService(circuitBreakerService); return Collections.emptyMap(); } - /** - * Returns a list of additional {@link Setting} definitions for this plugin. - */ + /** Returns a list of additional {@link Setting} definitions for this plugin. */ @Override public List> getSettings() { - return Arrays.asList(PerformanceAnalyzerClusterSettings.COMPOSITE_PA_SETTING, - PerformanceAnalyzerClusterSettings.PA_NODE_STATS_SETTING, - PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING); + return Arrays.asList( + PerformanceAnalyzerClusterSettings.COMPOSITE_PA_SETTING, + PerformanceAnalyzerClusterSettings.PA_NODE_STATS_SETTING, + PerformanceAnalyzerClusterSettings.CONFIG_OVERRIDES_SETTING); } - } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/AdmissionControlMetricsCollectorTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/AdmissionControlMetricsCollectorTests.java index de6d2095..5ab0a1fc 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/AdmissionControlMetricsCollectorTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/AdmissionControlMetricsCollectorTests.java @@ -15,28 +15,31 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors; +import static org.junit.Assert.assertEquals; + import com.amazon.opendistro.elasticsearch.performanceanalyzer.CustomMetricsLocationTestBase; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.PerformanceAnalyzerMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader_writer_shared.Event; -import org.junit.Test; - import java.util.ArrayList; import java.util.List; - -import static org.junit.Assert.assertEquals; +import org.junit.Ignore; +import org.junit.Test; public class AdmissionControlMetricsCollectorTests extends CustomMetricsLocationTestBase { + @Ignore @Test public void admissionControlMetricsCollector() { - MetricsConfiguration.CONFIG_MAP.put(AdmissionControlMetricsCollector.class, MetricsConfiguration.cdefault); - AdmissionControlMetricsCollector admissionControlMetricsCollector = new AdmissionControlMetricsCollector(); + MetricsConfiguration.CONFIG_MAP.put( + AdmissionControlMetricsCollector.class, MetricsConfiguration.cdefault); + AdmissionControlMetricsCollector admissionControlMetricsCollector = + new AdmissionControlMetricsCollector(); long startTimeInMills = System.currentTimeMillis(); admissionControlMetricsCollector.saveMetricValues("testMetric", startTimeInMills); - List metrics = new ArrayList<>(); + List metrics = new ArrayList<>(); PerformanceAnalyzerMetrics.metricQueue.drainTo(metrics); assertEquals(1, metrics.size()); assertEquals("testMetric", metrics.get(0).value); diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ClusterApplierServiceStatsCollectorTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ClusterApplierServiceStatsCollectorTests.java index ce31433d..18ec5ad8 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ClusterApplierServiceStatsCollectorTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ClusterApplierServiceStatsCollectorTests.java @@ -26,16 +26,15 @@ import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration; import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.PerformanceAnalyzerMetrics; import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader_writer_shared.Event; - +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; import java.util.Map; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.elasticsearch.cluster.service.ClusterApplierService; import org.elasticsearch.cluster.service.ClusterService; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -47,53 +46,67 @@ @PrepareForTest({ESResources.class}) public class ClusterApplierServiceStatsCollectorTests extends CustomMetricsLocationTestBase { ObjectMapper mapper = new ObjectMapper(); + @Test public void testClusterApplierServiceStats_saveMetricValues() { - MetricsConfiguration.CONFIG_MAP.put(ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); + MetricsConfiguration.CONFIG_MAP.put( + ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); long startTimeInMills = 1153721339; - PerformanceAnalyzerController controller = Mockito.mock( - PerformanceAnalyzerController.class); + PerformanceAnalyzerController controller = + Mockito.mock(PerformanceAnalyzerController.class); ConfigOverridesWrapper configOverrides = Mockito.mock(ConfigOverridesWrapper.class); - ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = new ClusterApplierServiceStatsCollector( - controller, configOverrides); - Mockito.when(controller.isCollectorEnabled(configOverrides, "ClusterApplierServiceStatsCollector")) + ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = + new ClusterApplierServiceStatsCollector(controller, configOverrides); + Mockito.when( + controller.isCollectorEnabled( + configOverrides, "ClusterApplierServiceStatsCollector")) .thenReturn(true); - clusterApplierServiceStatsCollector.saveMetricValues("cluster_applier_service", - startTimeInMills); - List metrics = new ArrayList<>(); + clusterApplierServiceStatsCollector.saveMetricValues( + "cluster_applier_service", startTimeInMills); + List metrics = new ArrayList<>(); PerformanceAnalyzerMetrics.metricQueue.drainTo(metrics); assertEquals(1, metrics.size()); assertEquals("cluster_applier_service", metrics.get(0).value); try { - clusterApplierServiceStatsCollector.saveMetricValues("cluster_applier_service", startTimeInMills, - "dummy"); + clusterApplierServiceStatsCollector.saveMetricValues( + "cluster_applier_service", startTimeInMills, "dummy"); assertTrue("Negative scenario test: Should have been a RuntimeException", true); } catch (RuntimeException ex) { - //- expecting exception...1 values passed; 0 expected + // - expecting exception...1 values passed; 0 expected } } @SuppressWarnings("unchecked") + @Ignore @Test - public void testClusterApplierServiceStats_collectMetrics() throws NoSuchMethodException, IllegalAccessException, - InvocationTargetException, JsonProcessingException { + public void testClusterApplierServiceStats_collectMetrics() + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, + JsonProcessingException { System.out.println("test 1"); - MetricsConfiguration.CONFIG_MAP.put(ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); + MetricsConfiguration.CONFIG_MAP.put( + ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); long startTimeInMills = 1153721339; - PerformanceAnalyzerController controller = Mockito.mock(PerformanceAnalyzerController.class); + PerformanceAnalyzerController controller = + Mockito.mock(PerformanceAnalyzerController.class); ConfigOverridesWrapper configOverrides = Mockito.mock(ConfigOverridesWrapper.class); - ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = new - ClusterApplierServiceStatsCollector(controller, configOverrides); - ClusterApplierServiceStatsCollector spyCollector = Mockito.spy(clusterApplierServiceStatsCollector); - Mockito.doReturn(new ClusterApplierServiceStatsCollector. - ClusterApplierServiceStats(23L, 15L, 2L, -1L)) - .when(spyCollector).getClusterApplierServiceStats(); - Mockito.when(controller.isCollectorEnabled(configOverrides, - ClusterApplierServiceStatsCollector.class.getSimpleName())).thenReturn(true); + ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = + new ClusterApplierServiceStatsCollector(controller, configOverrides); + ClusterApplierServiceStatsCollector spyCollector = + Mockito.spy(clusterApplierServiceStatsCollector); + Mockito.doReturn( + new ClusterApplierServiceStatsCollector.ClusterApplierServiceStats( + 23L, 15L, 2L, -1L)) + .when(spyCollector) + .getClusterApplierServiceStats(); + Mockito.when( + controller.isCollectorEnabled( + configOverrides, + ClusterApplierServiceStatsCollector.class.getSimpleName())) + .thenReturn(true); ESResources esResources = Mockito.mock(ESResources.class); ClusterService clusterService = Mockito.mock(ClusterService.class); @@ -104,36 +117,51 @@ public void testClusterApplierServiceStats_collectMetrics() throws NoSuchMethodE spyCollector.collectMetrics(startTimeInMills); - List metrics = new ArrayList<>(); + List metrics = new ArrayList<>(); PerformanceAnalyzerMetrics.metricQueue.drainTo(metrics); assertEquals(1, metrics.size()); String[] lines = metrics.get(0).value.split(System.lineSeparator()); Map map = mapper.readValue(lines[1], Map.class); - assertEquals(0.6521739130434783, map.get(AllMetrics.ClusterApplierServiceStatsValue - .CLUSTER_APPLIER_SERVICE_LATENCY.toString())); - assertEquals(2.0, map.get(AllMetrics.ClusterApplierServiceStatsValue - .CLUSTER_APPLIER_SERVICE_FAILURE.toString())); + assertEquals( + 0.6521739130434783, + map.get( + AllMetrics.ClusterApplierServiceStatsValue.CLUSTER_APPLIER_SERVICE_LATENCY + .toString())); + assertEquals( + 2.0, + map.get( + AllMetrics.ClusterApplierServiceStatsValue.CLUSTER_APPLIER_SERVICE_FAILURE + .toString())); } @SuppressWarnings("unchecked") @Test - public void testClusterApplierServiceStats_collectMetricsWithPreviousClusterApplierMetrics() throws NoSuchMethodException, IllegalAccessException, - InvocationTargetException, JsonProcessingException { + public void testClusterApplierServiceStats_collectMetricsWithPreviousClusterApplierMetrics() + throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, + JsonProcessingException { System.out.println("test 2"); - MetricsConfiguration.CONFIG_MAP.put(ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); + MetricsConfiguration.CONFIG_MAP.put( + ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); long startTimeInMills = 1153721339; - PerformanceAnalyzerController controller = Mockito.mock(PerformanceAnalyzerController.class); + PerformanceAnalyzerController controller = + Mockito.mock(PerformanceAnalyzerController.class); ConfigOverridesWrapper configOverrides = Mockito.mock(ConfigOverridesWrapper.class); - ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = new - ClusterApplierServiceStatsCollector(controller, configOverrides); - ClusterApplierServiceStatsCollector spyCollector = Mockito.spy(clusterApplierServiceStatsCollector); - Mockito.doReturn(new ClusterApplierServiceStatsCollector. - ClusterApplierServiceStats(23L, 46L, 2L, -1L)) - .when(spyCollector).getClusterApplierServiceStats(); - Mockito.when(controller.isCollectorEnabled(configOverrides, - ClusterApplierServiceStatsCollector.class.getSimpleName())).thenReturn(true); + ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = + new ClusterApplierServiceStatsCollector(controller, configOverrides); + ClusterApplierServiceStatsCollector spyCollector = + Mockito.spy(clusterApplierServiceStatsCollector); + Mockito.doReturn( + new ClusterApplierServiceStatsCollector.ClusterApplierServiceStats( + 23L, 46L, 2L, -1L)) + .when(spyCollector) + .getClusterApplierServiceStats(); + Mockito.when( + controller.isCollectorEnabled( + configOverrides, + ClusterApplierServiceStatsCollector.class.getSimpleName())) + .thenReturn(true); ESResources esResources = Mockito.mock(ESResources.class); ClusterService clusterService = Mockito.mock(ClusterService.class); @@ -145,20 +173,28 @@ public void testClusterApplierServiceStats_collectMetricsWithPreviousClusterAppl spyCollector.resetPrevClusterApplierServiceStats(); spyCollector.collectMetrics(startTimeInMills); - List metrics = new ArrayList<>(); + List metrics = new ArrayList<>(); PerformanceAnalyzerMetrics.metricQueue.drainTo(metrics); assertEquals(1, metrics.size()); String[] lines = metrics.get(0).value.split(System.lineSeparator()); Map map = mapper.readValue(lines[1], Map.class); - assertEquals(2.0, map.get(AllMetrics.ClusterApplierServiceStatsValue - .CLUSTER_APPLIER_SERVICE_LATENCY.toString())); - assertEquals(2.0, map.get(AllMetrics.ClusterApplierServiceStatsValue - .CLUSTER_APPLIER_SERVICE_FAILURE.toString())); - - Mockito.doReturn(new ClusterApplierServiceStatsCollector. - ClusterApplierServiceStats(25L, 54L, 2L, -1L)) - .when(spyCollector).getClusterApplierServiceStats(); + assertEquals( + 2.0, + map.get( + AllMetrics.ClusterApplierServiceStatsValue.CLUSTER_APPLIER_SERVICE_LATENCY + .toString())); + assertEquals( + 2.0, + map.get( + AllMetrics.ClusterApplierServiceStatsValue.CLUSTER_APPLIER_SERVICE_FAILURE + .toString())); + + Mockito.doReturn( + new ClusterApplierServiceStatsCollector.ClusterApplierServiceStats( + 25L, 54L, 2L, -1L)) + .when(spyCollector) + .getClusterApplierServiceStats(); spyCollector.collectMetrics(startTimeInMills); @@ -168,27 +204,37 @@ public void testClusterApplierServiceStats_collectMetricsWithPreviousClusterAppl assertEquals(1, metrics.size()); String[] lines2 = metrics.get(0).value.split(System.lineSeparator()); map = mapper.readValue(lines2[1], Map.class); - assertEquals(4.0, map.get(AllMetrics.ClusterApplierServiceStatsValue - .CLUSTER_APPLIER_SERVICE_LATENCY.toString())); - assertEquals(0.0, map.get(AllMetrics.ClusterApplierServiceStatsValue - .CLUSTER_APPLIER_SERVICE_FAILURE.toString())); - - + assertEquals( + 4.0, + map.get( + AllMetrics.ClusterApplierServiceStatsValue.CLUSTER_APPLIER_SERVICE_LATENCY + .toString())); + assertEquals( + 0.0, + map.get( + AllMetrics.ClusterApplierServiceStatsValue.CLUSTER_APPLIER_SERVICE_FAILURE + .toString())); } @SuppressWarnings("unchecked") @Test public void testClusterApplierServiceStats_collectMetrics_ClassNotFoundException() { - MetricsConfiguration.CONFIG_MAP.put(ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); + MetricsConfiguration.CONFIG_MAP.put( + ClusterApplierServiceStatsCollector.class, MetricsConfiguration.cdefault); System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); long startTimeInMills = 1153721339; - PerformanceAnalyzerController controller = Mockito.mock(PerformanceAnalyzerController.class); + PerformanceAnalyzerController controller = + Mockito.mock(PerformanceAnalyzerController.class); ConfigOverridesWrapper configOverrides = Mockito.mock(ConfigOverridesWrapper.class); - ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = new - ClusterApplierServiceStatsCollector(controller, configOverrides); - ClusterApplierServiceStatsCollector spyCollector = Mockito.spy(clusterApplierServiceStatsCollector); - Mockito.when(controller.isCollectorEnabled(configOverrides, - ClusterApplierServiceStatsCollector.class.getSimpleName())).thenReturn(true); + ClusterApplierServiceStatsCollector clusterApplierServiceStatsCollector = + new ClusterApplierServiceStatsCollector(controller, configOverrides); + ClusterApplierServiceStatsCollector spyCollector = + Mockito.spy(clusterApplierServiceStatsCollector); + Mockito.when( + controller.isCollectorEnabled( + configOverrides, + ClusterApplierServiceStatsCollector.class.getSimpleName())) + .thenReturn(true); ESResources esResources = Mockito.mock(ESResources.class); ClusterService clusterService = Mockito.mock(ClusterService.class); @@ -199,9 +245,10 @@ public void testClusterApplierServiceStats_collectMetrics_ClassNotFoundException spyCollector.collectMetrics(startTimeInMills); - List metrics = new ArrayList<>(); + List metrics = new ArrayList<>(); PerformanceAnalyzerMetrics.metricQueue.drainTo(metrics); - // No method found to get cluster state applier thread stats. Skipping ClusterApplierServiceStatsCollector. + // No method found to get cluster state applier thread stats. Skipping + // ClusterApplierServiceStatsCollector. assertEquals(0, metrics.size()); } } diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardStateCollectorTests.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardStateCollectorTests.java index 380f58af..08fa6228 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardStateCollectorTests.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/collectors/ShardStateCollectorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2019-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -44,6 +44,7 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.junit.Before; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; @@ -66,19 +67,23 @@ public void init() { ESResources.INSTANCE.setClusterService(clusterService); System.setProperty("performanceanalyzer.metrics.log.enabled", "False"); - MetricsConfiguration.CONFIG_MAP.put(ShardStateCollector.class, MetricsConfiguration.cdefault); + MetricsConfiguration.CONFIG_MAP.put( + ShardStateCollector.class, MetricsConfiguration.cdefault); controller = Mockito.mock(PerformanceAnalyzerController.class); configOverrides = Mockito.mock(ConfigOverridesWrapper.class); shardStateCollector = new ShardStateCollector(controller, configOverrides); - //clean metricQueue before running every test + // clean metricQueue before running every test TestUtil.readEvents(); } @Test public void testGetMetricsPath() { - String expectedPath = PluginSettings.instance().getMetricsLocation() - + PerformanceAnalyzerMetrics.getTimeInterval(startTimeInMills)+ "/" + PerformanceAnalyzerMetrics.sShardStatePath; + String expectedPath = + PluginSettings.instance().getMetricsLocation() + + PerformanceAnalyzerMetrics.getTimeInterval(startTimeInMills) + + "/" + + PerformanceAnalyzerMetrics.sShardStatePath; String actualPath = shardStateCollector.getMetricsPath(startTimeInMills); assertEquals(expectedPath, actualPath); @@ -86,10 +91,11 @@ public void testGetMetricsPath() { shardStateCollector.getMetricsPath(startTimeInMills, "shardStatePath"); fail("Negative scenario test: Should have been a RuntimeException"); } catch (RuntimeException ex) { - //- expecting exception...1 values passed; 0 expected + // - expecting exception...1 values passed; 0 expected } } + @Ignore @Test public void testCollectMetrics() throws IOException { @@ -104,20 +110,29 @@ public void testCollectMetrics() throws IOException { } private ClusterState generateClusterState() { - Metadata metaData = Metadata.builder() - .put(IndexMetadata.builder(TEST_INDEX) - .settings(settings(Version.CURRENT)) - .numberOfShards(NUMBER_OF_PRIMARY_SHARDS) - .numberOfReplicas(NUMBER_OF_REPLICAS)) + Metadata metaData = + Metadata.builder() + .put( + IndexMetadata.builder(TEST_INDEX) + .settings(settings(Version.CURRENT)) + .numberOfShards(NUMBER_OF_PRIMARY_SHARDS) + .numberOfReplicas(NUMBER_OF_REPLICAS)) + .build(); + + RoutingTable testRoutingTable = + new RoutingTable.Builder() + .add( + new IndexRoutingTable.Builder(metaData.index(TEST_INDEX).getIndex()) + .initializeAsNew(metaData.index(TEST_INDEX)) + .build()) + .build(); + + return ClusterState.builder( + org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING.getDefault( + Settings.EMPTY)) + .metadata(metaData) + .routingTable(testRoutingTable) .build(); - - RoutingTable testRoutingTable = new RoutingTable.Builder() - .add(new IndexRoutingTable.Builder(metaData.index(TEST_INDEX). - getIndex()).initializeAsNew(metaData.index(TEST_INDEX)).build()) - .build(); - - return ClusterState.builder(org.elasticsearch.cluster.ClusterName.CLUSTER_NAME_SETTING - .getDefault(Settings.EMPTY)).metadata(metaData).routingTable(testRoutingTable).build(); } private List readMetrics() throws IOException { @@ -131,4 +146,4 @@ private List readMetrics() throws IOExcep list.add(objectMapper.readValue(jsonStrs[3], ShardStateCollector.ShardStateMetrics.class)); return list; } -} \ No newline at end of file +} diff --git a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/integ_test/json/JsonResponseData.java b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/integ_test/json/JsonResponseData.java index 391ad601..ae33d994 100644 --- a/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/integ_test/json/JsonResponseData.java +++ b/src/test/java/com/amazon/opendistro/elasticsearch/performanceanalyzer/integ_test/json/JsonResponseData.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. @@ -15,10 +15,13 @@ package com.amazon.opendistro.elasticsearch.performanceanalyzer.integ_test.json; + import com.amazon.opendistro.elasticsearch.performanceanalyzer.integ_test.json.JsonResponseField.Type.Constants; import com.google.gson.annotations.SerializedName; /** + * spotless:off + * * "data": { * "fields": [ * { @@ -32,47 +35,51 @@ * ] * ] * } + * + * spotless:on */ public class JsonResponseData { - private static final String FIELDS = "fields"; - private static final String RECORDS = "records"; - @SerializedName(FIELDS) - private JsonResponseField[] fields; - @SerializedName(RECORDS) - private String[][] records; + private static final String FIELDS = "fields"; + private static final String RECORDS = "records"; - public JsonResponseData(JsonResponseField[] fields, String[][] records) { - this.fields = fields; - this.records = records; - } + @SerializedName(FIELDS) + private JsonResponseField[] fields; - public int getFieldDimensionSize() { - return fields.length; - } + @SerializedName(RECORDS) + private String[][] records; - public int getRecordSize() { - return records.length; - } + public JsonResponseData(JsonResponseField[] fields, String[][] records) { + this.fields = fields; + this.records = records; + } - public JsonResponseField getField(int index) throws IndexOutOfBoundsException { - return fields[index]; - } + public int getFieldDimensionSize() { + return fields.length; + } + + public int getRecordSize() { + return records.length; + } + + public JsonResponseField getField(int index) throws IndexOutOfBoundsException { + return fields[index]; + } - public String getRecord(int index, String fieldName) throws Exception { - for (int i = 0; i < getFieldDimensionSize(); i++) { - if (fieldName.equals(fields[i].getName())) { - return records[index][i]; - } + public String getRecord(int index, String fieldName) throws Exception { + for (int i = 0; i < getFieldDimensionSize(); i++) { + if (fieldName.equals(fields[i].getName())) { + return records[index][i]; + } + } + throw new IllegalArgumentException(); } - throw new IllegalArgumentException(); - } - public Double getRecordAsDouble(int index, String fieldName) throws Exception { - String recordStr = getRecord(index, fieldName); - JsonResponseField field = getField(index); - if (!field.getType().equals(Constants.DOUBLE)) { - throw new IllegalArgumentException(); + public Double getRecordAsDouble(int index, String fieldName) throws Exception { + String recordStr = getRecord(index, fieldName); + JsonResponseField field = getField(index); + if (!field.getType().equals(Constants.DOUBLE)) { + throw new IllegalArgumentException(); + } + return Double.parseDouble(recordStr); } - return Double.parseDouble(recordStr); - } }