Skip to content

Commit

Permalink
Add resourceGroup as a tag in the emitted metrics
Browse files Browse the repository at this point in the history
Related to apache#3991
  • Loading branch information
dlmarion committed Nov 28, 2023
1 parent f32981d commit a724224
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ public class MetricsUtil {
private static Pattern camelCasePattern = Pattern.compile("[a-z][A-Z][a-z]");

public static void initializeMetrics(final AccumuloConfiguration conf, final String appName,
final HostAndPort address) throws ClassNotFoundException, InstantiationException,
IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchMethodException, SecurityException {
final HostAndPort address, final String resourceGroup) throws ClassNotFoundException,
InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
initializeMetrics(conf.getBoolean(Property.GENERAL_MICROMETER_ENABLED),
conf.getBoolean(Property.GENERAL_MICROMETER_JVM_METRICS_ENABLED),
conf.get(Property.GENERAL_MICROMETER_FACTORY), appName, address);
conf.get(Property.GENERAL_MICROMETER_FACTORY), appName, address, resourceGroup);
}

private static void initializeMetrics(boolean enabled, boolean jvmMetricsEnabled,
String factoryClass, String appName, HostAndPort address) throws ClassNotFoundException,
InstantiationException, IllegalAccessException, IllegalArgumentException,
InvocationTargetException, NoSuchMethodException, SecurityException {
String factoryClass, String appName, HostAndPort address, String resourceGroup)
throws ClassNotFoundException, InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException, NoSuchMethodException,
SecurityException {

LOG.info("initializing metrics, enabled:{}, class:{}", enabled, factoryClass);

Expand All @@ -78,7 +79,7 @@ private static void initializeMetrics(boolean enabled, boolean jvmMetricsEnabled

List<Tag> tags = new ArrayList<>();
tags.add(Tag.of("process.name", processName));

tags.add(Tag.of("resource.group", resourceGroup));
if (address != null) {
if (!address.getHost().isEmpty()) {
tags.add(Tag.of("host", address.getHost()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ public void run() {

try {
MetricsUtil.initializeMetrics(getContext().getConfiguration(), this.applicationName,
clientAddress);
clientAddress, this.getResourceGroup());
pausedMetrics = new PausedCompactionMetrics();
MetricsUtil.initializeProducers(this, pausedMetrics);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ public void run() {
}

try {
MetricsUtil.initializeMetrics(getContext().getConfiguration(), this.applicationName, address);
MetricsUtil.initializeMetrics(getContext().getConfiguration(), this.applicationName, address,
this.getResourceGroup());
MetricsUtil.initializeProducers(this, new GcMetrics(this));
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException | NoSuchMethodException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ public void run() {
ManagerMetrics mm = new ManagerMetrics(getConfiguration(), this);
try {
MetricsUtil.initializeMetrics(getContext().getConfiguration(), this.applicationName,
sa.getAddress());
sa.getAddress(), this.getResourceGroup());
MetricsUtil.initializeProducers(this, mm);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| IllegalArgumentException | InvocationTargetException | NoSuchMethodException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public void run() {

try {
MetricsUtil.initializeMetrics(getContext().getConfiguration(), this.applicationName,
clientAddress);
clientAddress, this.getResourceGroup());
scanMetrics = new TabletServerScanMetrics();
MetricsUtil.initializeProducers(this, scanMetrics);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ public void run() {
}

try {
MetricsUtil.initializeMetrics(context.getConfiguration(), this.applicationName,
clientAddress);
MetricsUtil.initializeMetrics(context.getConfiguration(), this.applicationName, clientAddress,
this.getResourceGroup());

metrics = new TabletServerMetrics(this);
updateMetrics = new TabletServerUpdateMetrics();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

Expand Down Expand Up @@ -162,7 +163,7 @@ private void doWorkToGenerateMetrics() throws Exception {
writer.addMutation(m);
}
}
client.tableOperations().compact(tableName, new CompactionConfig());
client.tableOperations().compact(tableName, new CompactionConfig().setWait(true));
try (Scanner scanner = client.createScanner(tableName)) {
scanner.forEach((k, v) -> {});
}
Expand Down Expand Up @@ -195,6 +196,9 @@ public void metricTags() throws Exception {
// check hostname is always set and is valid
assertNotEquals("0.0.0.0", a.getTags().get("host"));

// check resource.group tag exists
assertNotNull(a.getTags().get("resource.group"));

// check the length of the tag value is sane
final int MAX_EXPECTED_TAG_LEN = 128;
a.getTags().forEach((k, v) -> assertTrue(v.length() < MAX_EXPECTED_TAG_LEN));
Expand Down

0 comments on commit a724224

Please sign in to comment.