Skip to content

Commit

Permalink
Merge pull request #184 from brharrington/defaultid-package-private
Browse files Browse the repository at this point in the history
change access of DefaultId to package private
  • Loading branch information
brharrington committed Aug 5, 2015
2 parents 5d2a1d1 + 6163d1f commit c5ead78
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
Binary file modified codequality/spectator-api-BASELINE.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import java.util.TreeMap;

/** Id implementation for the default registry. */
public final class DefaultId implements Id {
final class DefaultId implements Id {

private final String name;
private final TagList tags;
Expand Down Expand Up @@ -68,7 +68,7 @@ public DefaultId(String name) {
* Returns a new id with the tag list sorted by key and with no duplicate keys. This is equivalent to
* {@code rollup(Collections.<String>emptySet(), false)}.
*/
public DefaultId normalize() {
DefaultId normalize() {
return rollup(Collections.<String>emptySet(), false);
}

Expand All @@ -86,7 +86,7 @@ public DefaultId normalize() {
* @return
* New identifier after applying the rollup.
*/
public DefaultId rollup(Set<String> keys, boolean keep) {
DefaultId rollup(Set<String> keys, boolean keep) {
Map<String, String> ts = new TreeMap<>();
for (Tag t : tags) {
if (keys.contains(t.key()) == keep && !ts.containsKey(t.key())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public final class Utils {
private Utils() {
}

/**
* Returns a new id with the tag list sorted by key and with no duplicate keys.
*/
public static Id normalize(Id id) {
return (new DefaultId(id.name())).withTags(id.tags()).normalize();
}

/**
* Returns the value associated with with a given key or null if no such key is present in the
* set of tags.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package com.netflix.spectator.spark;

import com.netflix.spectator.api.DefaultId;
import com.netflix.spectator.api.DefaultRegistry;
import com.netflix.spectator.api.Id;
import com.netflix.spectator.api.Registry;
import com.netflix.spectator.api.Utils;
import com.typesafe.config.ConfigFactory;
import org.junit.Assert;
import org.junit.Test;
Expand All @@ -27,100 +28,88 @@
@RunWith(JUnit4.class)
public class SparkNameFunctionTest {

private final SparkNameFunction f = SparkNameFunction.fromConfig(ConfigFactory.load(), new DefaultRegistry());
private final Registry registry = new DefaultRegistry();
private final SparkNameFunction f = SparkNameFunction.fromConfig(ConfigFactory.load(), registry);

private void assertEquals(Id expected, Id actual) {
Assert.assertEquals(((DefaultId) expected).normalize(), ((DefaultId) actual).normalize());
Assert.assertEquals(Utils.normalize(expected), Utils.normalize(actual));
}

@Test
public void executorName() {
final String name = "app-20150309231421-0000.0.executor.filesystem.file.largeRead_ops";
final Id expected = new DefaultId("spark.filesystem.file.largeRead_ops")
final Id expected = registry.createId("spark.filesystem.file.largeRead_ops")
.withTag("role", "executor");
//.withTag("appId", "app-20150309231421-0000")
//.withTag("executorId", "0");
assertEquals(expected, f.apply(name));
}

@Test
public void executorName2() {
final String name = "20150626-185518-1776258826-5050-2845-S1.executor.filesystem.file.largeRead_ops";
final Id expected = new DefaultId("spark.filesystem.file.largeRead_ops")
final Id expected = registry.createId("spark.filesystem.file.largeRead_ops")
.withTag("role", "executor");
//.withTag("appId", "20150626-185518-1776258826-5050-2845-S1");
assertEquals(expected, f.apply(name));
}

@Test
public void executorName3() {
final String name = "12345.1.3.executor.filesystem.file.largeRead_ops";
final Id expected = new DefaultId("spark.filesystem.file.largeRead_ops")
final Id expected = registry.createId("spark.filesystem.file.largeRead_ops")
.withTag("role", "executor");
//.withTag("appId", "12345.1.3");
assertEquals(expected, f.apply(name));
}

@Test
public void driverName() {
final String name = "app-20150309231421-0000.driver.BlockManager.disk.diskSpaceUsed_MB";
final Id expected = new DefaultId("spark.disk.diskSpaceUsed")
final Id expected = registry.createId("spark.disk.diskSpaceUsed")
.withTag("role", "driver")
.withTag("source", "BlockManager");
//.withTag("appId", "app-20150309231421-0000");
assertEquals(expected, f.apply(name));
}

@Test
public void driverName2() {
final String name = "app-20150309231421-0000.driver.DAGScheduler.job.activeJobs";
final Id expected = new DefaultId("spark.job.activeJobs")
final Id expected = registry.createId("spark.job.activeJobs")
.withTag("role", "driver")
.withTag("source", "DAGScheduler");
//.withTag("appId", "app-20150309231421-0000");
assertEquals(expected, f.apply(name));
}

@Test
public void driverName3() {
final String name = "local-1429219722964.<driver>.DAGScheduler.job.activeJobs";
final Id expected = new DefaultId("spark.job.activeJobs")
final Id expected = registry.createId("spark.job.activeJobs")
.withTag("role", "driver")
.withTag("source", "DAGScheduler");
//.withTag("appId", "local-1429219722964");
assertEquals(expected, f.apply(name));
}

@Test
public void driverStreamingSimple() {
final String name = "app-20150527224111-0014.<driver>.SubscriptionEnded.StreamingMetrics.streaming.receivers";
final Id expected = new DefaultId("spark.streaming.receivers")
final Id expected = registry.createId("spark.streaming.receivers")
.withTag("role", "driver")
.withTag("source", "StreamingMetrics");
//.withTag("appId", "app-20150527224111-0014")
//.withTag("appName", "SubscriptionEnded");
assertEquals(expected, f.apply(name));
}

@Test
public void driverStreamingTotal() {
final String name = "app-20150527224111-0014.<driver>.SubscriptionEnded.StreamingMetrics.streaming.totalCompletedBatches";
final Id expected = new DefaultId("spark.streaming.totalCompletedBatches")
final Id expected = registry.createId("spark.streaming.totalCompletedBatches")
.withTag("role", "driver")
.withTag("source", "StreamingMetrics");
//.withTag("appId", "app-20150527224111-0014")
//.withTag("appName", "SubscriptionEnded");
assertEquals(expected, f.apply(name));
}

@Test
public void driverStreamingDelay() {
final String name = "app-20150527224111-0014.<driver>.SubscriptionEnded.StreamingMetrics.streaming.lastReceivedBatch_submissionDelay";
final Id expected = new DefaultId("spark.streaming.lastReceivedBatch_submissionDelay")
final Id expected = registry.createId("spark.streaming.lastReceivedBatch_submissionDelay")
.withTag("role", "driver")
.withTag("source", "StreamingMetrics");
//.withTag("appId", "app-20150527224111-0014")
//.withTag("appName", "SubscriptionEnded");
assertEquals(expected, f.apply(name));
}

Expand All @@ -133,7 +122,7 @@ public void driverStreamingTime() {
@Test
public void applicationName() {
final String name = "application.Spark shell.1425968061869.cores";
final Id expected = new DefaultId("spark.cores")
final Id expected = registry.createId("spark.cores")
.withTag("role", "application")
.withTag("appName", "Spark shell");
assertEquals(expected, f.apply(name));
Expand All @@ -142,7 +131,7 @@ public void applicationName() {
@Test
public void applicationName2() {
final String name = "application.SubscriptionEnded.1429226958083.runtime_ms";
final Id expected = new DefaultId("spark.runtime")
final Id expected = registry.createId("spark.runtime")
.withTag("role", "application")
.withTag("appName", "SubscriptionEnded");
assertEquals(expected, f.apply(name));
Expand All @@ -151,15 +140,15 @@ public void applicationName2() {
@Test
public void masterName() {
final String name = "master.apps";
final Id expected = new DefaultId("spark.apps")
final Id expected = registry.createId("spark.apps")
.withTag("role", "master");
assertEquals(expected, f.apply(name));
}

@Test
public void workerName() {
final String name = "worker.memFree_MB";
final Id expected = new DefaultId("spark.memFree")
final Id expected = registry.createId("spark.memFree")
.withTag("role", "worker");
assertEquals(expected, f.apply(name));
}
Expand Down

0 comments on commit c5ead78

Please sign in to comment.