Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ private NetflixTagging() {
tagKeys.add("nf.stack");
tagKeys.add("nf.vmtype");
tagKeys.add("nf.zone");
// Stratum function tagging. fnFqName is intentionally excluded — fully-qualified
// class names are high-cardinality and churn with refactors, so they are kept for
// logs/traces only.
tagKeys.add("fnGroup");
tagKeys.add("shortFnName");

DEFAULT_ATLAS_TAG_KEYS = Collections.unmodifiableSet(tagKeys);
}
Expand Down Expand Up @@ -145,22 +140,6 @@ public static Map<String, String> commonTags(Function<String, String> getenv) {
putIfNotEmptyOrNull(getenv, tags, "mantisWorkerStageNumber", "MANTIS_WORKER_STAGE_NUMBER");
putIfNotEmptyOrNull(getenv, tags, "mantisUser", "MANTIS_USER");

// Stratum function info. shortFnName is composed from group + name to match the
// FunctionNameSummarizer used elsewhere in the Stratum stack; it is only emitted
// when both pieces are present. fnFqName is included for logs/traces but excluded
// from the Atlas tag set (see DEFAULT_ATLAS_TAG_KEYS). isEmptyOrNull treats
// whitespace-only values as absent, so the composed value cannot have a leading
// or trailing dash from a whitespace-only piece.
String fnGroup = getenv.apply("STRATUM_FUNCTION_GROUP");
String fnName = getenv.apply("STRATUM_FUNCTION_NAME");
if (!isEmptyOrNull(fnGroup)) {
tags.put("fnGroup", fnGroup.trim());
if (!isEmptyOrNull(fnName)) {
tags.put("shortFnName", fnGroup.trim() + "-" + fnName.trim());
}
}
putIfNotEmptyOrNull(getenv, tags, "fnFqName", "STRATUM_FUNCTION_FQNAME");

return tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,97 +225,4 @@ public void commonTagsTitusOverridesEc2InstanceId() {
Map<String, String> actual = NetflixTagging.commonTags(vars::get);
Assertions.assertEquals(expected, actual);
}

@Test
public void commonTagsStratumAllPresent() {
Map<String, String> vars = sampleEnvironmentVars();
vars.put("STRATUM_FUNCTION_GROUP", "foo-group");
vars.put("STRATUM_FUNCTION_NAME", "bar");
vars.put("STRATUM_FUNCTION_FQNAME", "com.example.foo.BarFn");
Map<String, String> expected = sampleExpectedTags();
expected.put("fnGroup", "foo-group");
expected.put("shortFnName", "foo-group-bar");
expected.put("fnFqName", "com.example.foo.BarFn");
Map<String, String> actual = NetflixTagging.commonTags(vars::get);
Assertions.assertEquals(expected, actual);
}

@Test
public void commonTagsStratumGroupOnly() {
// Only the group is present; shortFnName requires both group and name, so it
// should not be emitted. fnGroup still is.
Map<String, String> vars = sampleEnvironmentVars();
vars.put("STRATUM_FUNCTION_GROUP", "foo-group");
Map<String, String> expected = sampleExpectedTags();
expected.put("fnGroup", "foo-group");
Map<String, String> actual = NetflixTagging.commonTags(vars::get);
Assertions.assertEquals(expected, actual);
}

@Test
public void commonTagsStratumNameOnly() {
// Only the name is present; neither shortFnName nor fnGroup should appear.
Map<String, String> vars = sampleEnvironmentVars();
vars.put("STRATUM_FUNCTION_NAME", "bar");
Map<String, String> expected = sampleExpectedTags();
Map<String, String> actual = NetflixTagging.commonTags(vars::get);
Assertions.assertEquals(expected, actual);
}

@Test
public void commonTagsStratumNonePresent() {
// None of the Stratum vars set — no Stratum tags emitted.
Map<String, String> vars = sampleEnvironmentVars();
Map<String, String> expected = sampleExpectedTags();
Map<String, String> actual = NetflixTagging.commonTags(vars::get);
Assertions.assertEquals(expected, actual);
Assertions.assertFalse(actual.containsKey("shortFnName"));
Assertions.assertFalse(actual.containsKey("fnGroup"));
Assertions.assertFalse(actual.containsKey("fnFqName"));
}

@Test
public void commonTagsStratumWhitespaceTrimmed() {
// Leading/trailing whitespace in either var must be trimmed before composing
// shortFnName so we don't end up with " group - name ".
Map<String, String> vars = sampleEnvironmentVars();
vars.put("STRATUM_FUNCTION_GROUP", " foo-group ");
vars.put("STRATUM_FUNCTION_NAME", "\tbar\n");
Map<String, String> expected = sampleExpectedTags();
expected.put("fnGroup", "foo-group");
expected.put("shortFnName", "foo-group-bar");
Map<String, String> actual = NetflixTagging.commonTags(vars::get);
Assertions.assertEquals(expected, actual);
}

@Test
public void commonTagsForAtlasStratum() {
// Atlas filter: shortFnName and fnGroup are included; fnFqName is excluded
// because it is not in DEFAULT_ATLAS_TAG_KEYS (high-cardinality FQ class name).
Map<String, String> vars = sampleEnvironmentVars();
vars.put("STRATUM_FUNCTION_GROUP", "foo-group");
vars.put("STRATUM_FUNCTION_NAME", "bar");
vars.put("STRATUM_FUNCTION_FQNAME", "com.example.foo.BarFn");
Map<String, String> expected = atlasExpectedTags();
expected.put("fnGroup", "foo-group");
expected.put("shortFnName", "foo-group-bar");
Map<String, String> actual = NetflixTagging.commonTagsForAtlas(vars::get);
Assertions.assertEquals(expected, actual);
Assertions.assertFalse(actual.containsKey("fnFqName"));
}

@Test
public void commonTagsForAtlasStratumSanitizes() {
// Group/name values containing characters outside the Atlas-safe set should be
// sanitized by fixTagString when filtered through commonTagsForAtlas. Colons
// and slashes are not in [-._A-Za-z0-9~^] and should become underscores.
Map<String, String> vars = sampleEnvironmentVars();
vars.put("STRATUM_FUNCTION_GROUP", "foo:group");
vars.put("STRATUM_FUNCTION_NAME", "bar/v2");
Map<String, String> expected = atlasExpectedTags();
expected.put("fnGroup", "foo_group");
expected.put("shortFnName", "foo_group-bar_v2");
Map<String, String> actual = NetflixTagging.commonTagsForAtlas(vars::get);
Assertions.assertEquals(expected, actual);
}
}