This repository has been archived by the owner on Aug 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add UT for NodeStatsFixedShardsMetricsCollectorTests * add UT for NodeDetailsCollectorTests * add UT for CacheConfigMetricsCollectorTests * don't ignore ThreadPoolMetricsCollectorTests * run jacoco task before integration test * change min jacoco coverage to 0.31 * clean code * add newLine * add negative scenario tests * use @mock annotation for codebase consistency
- Loading branch information
Showing
7 changed files
with
237 additions
and
35 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
66 changes: 66 additions & 0 deletions
66
...distro/elasticsearch/performanceanalyzer/collectors/CacheConfigMetricsCollectorTests.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 @@ | ||
package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors; | ||
|
||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.CacheConfigMetricsCollector.CacheMaxSizeStatus; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.CacheType; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader_writer_shared.Event; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.util.TestUtil; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.module.paranamer.ParanamerModule; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.elasticsearch.indices.IndicesService; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class CacheConfigMetricsCollectorTests extends ESSingleNodeTestCase { | ||
private static final String TEST_INDEX = "test"; | ||
private CacheConfigMetricsCollector collector; | ||
|
||
@Before | ||
public void init() { | ||
IndicesService indicesService = getInstanceFromNode(IndicesService.class); | ||
ESResources.INSTANCE.setIndicesService(indicesService); | ||
|
||
MetricsConfiguration.CONFIG_MAP.put(CacheConfigMetricsCollector.class, MetricsConfiguration.cdefault); | ||
collector = new CacheConfigMetricsCollector(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
} | ||
|
||
@Test | ||
public void testCollectMetrics() throws IOException { | ||
long startTimeInMills = 1153721339; | ||
|
||
createIndex(TEST_INDEX); | ||
collector.collectMetrics(startTimeInMills); | ||
|
||
List<CacheMaxSizeStatus> metrics = readMetrics(); | ||
assertEquals(2, metrics.size()); | ||
CacheMaxSizeStatus filedDataCache = metrics.get(0); | ||
CacheMaxSizeStatus shardRequestCache = metrics.get(1); | ||
assertEquals(CacheType.FIELD_DATA_CACHE.toString(), filedDataCache.getCacheType()); | ||
assertEquals(CacheType.SHARD_REQUEST_CACHE.toString(), shardRequestCache.getCacheType()); | ||
} | ||
|
||
private List<CacheMaxSizeStatus> readMetrics() throws IOException { | ||
List<Event> metrics = TestUtil.readEvents(); | ||
assert metrics.size() == 1; | ||
ObjectMapper objectMapper = new ObjectMapper().registerModule(new ParanamerModule()); | ||
|
||
List<CacheMaxSizeStatus> list = new ArrayList<>(); | ||
String[] jsonStrs = metrics.get(0).value.split("\n"); | ||
assert jsonStrs.length == 3; | ||
for (int i = 1; i < 3; i++) { | ||
list.add(objectMapper.readValue(jsonStrs[i], CacheMaxSizeStatus.class)); | ||
} | ||
return list; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...on/opendistro/elasticsearch/performanceanalyzer/collectors/NodeDetailsCollectorTests.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,80 @@ | ||
package com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors; | ||
|
||
import static org.mockito.MockitoAnnotations.initMocks; | ||
|
||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.ESResources; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.collectors.NodeDetailsCollector.NodeDetailsStatus; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.config.overrides.ConfigOverridesWrapper; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.AllMetrics.NodeRole; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.metrics.MetricsConfiguration; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.reader_writer_shared.Event; | ||
import com.amazon.opendistro.elasticsearch.performanceanalyzer.util.TestUtil; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.module.paranamer.ParanamerModule; | ||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.node.DiscoveryNodeRole; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.test.ClusterServiceUtils; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.threadpool.TestThreadPool; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mock; | ||
|
||
public class NodeDetailsCollectorTests extends ESTestCase { | ||
private static final String NODE_ID = "testNode"; | ||
private NodeDetailsCollector collector; | ||
private ThreadPool threadPool; | ||
|
||
@Mock | ||
private ConfigOverridesWrapper configOverrides; | ||
|
||
@Before | ||
public void init() { | ||
initMocks(this); | ||
|
||
DiscoveryNode testNode = new DiscoveryNode(NODE_ID, ESTestCase.buildNewFakeTransportAddress(), Collections | ||
.emptyMap(), | ||
DiscoveryNodeRole.BUILT_IN_ROLES, Version.CURRENT); | ||
|
||
threadPool = new TestThreadPool("test"); | ||
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool, testNode); | ||
ESResources.INSTANCE.setClusterService(clusterService); | ||
|
||
MetricsConfiguration.CONFIG_MAP.put(NodeDetailsCollector.class, MetricsConfiguration.cdefault); | ||
collector = new NodeDetailsCollector(configOverrides); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
threadPool.shutdownNow(); | ||
super.tearDown(); | ||
} | ||
|
||
@Test | ||
public void testCollectMetrics() throws IOException { | ||
long startTimeInMills = 1153721339; | ||
collector.collectMetrics(startTimeInMills); | ||
NodeDetailsStatus nodeDetailsStatus = readMetrics(); | ||
|
||
assertEquals(NODE_ID, nodeDetailsStatus.getID()); | ||
assertEquals("0.0.0.0", nodeDetailsStatus.getHostAddress()); | ||
assertEquals(NodeRole.DATA.role(), nodeDetailsStatus.getRole()); | ||
assertTrue(nodeDetailsStatus.getIsMasterNode()); | ||
} | ||
|
||
private NodeDetailsStatus readMetrics() throws IOException { | ||
List<Event> metrics = TestUtil.readEvents(); | ||
assert metrics.size() == 1; | ||
ObjectMapper objectMapper = new ObjectMapper().registerModule(new ParanamerModule()); | ||
String[] jsonStrs = metrics.get(0).value.split("\n"); | ||
assert jsonStrs.length == 4; | ||
return objectMapper.readValue(jsonStrs[3], NodeDetailsStatus.class); | ||
} | ||
} |
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