Skip to content

Commit

Permalink
[#11267] Add Hbase client side metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
intr3p1d committed Sep 20, 2024
1 parent ed3b57c commit f45d066
Show file tree
Hide file tree
Showing 7 changed files with 357 additions and 0 deletions.
2 changes: 2 additions & 0 deletions collector-monitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@
</dependency>
</dependencies>

<profiles>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.collector.monitor.config;

import org.apache.hadoop.hbase.client.AsyncConnectionImpl;
import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.MetricsConnection;
import org.apache.hadoop.hbase.shaded.com.codahale.metrics.MetricRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;

/**
* @author intr3p1d
*/
public class HbaseConnectionReflects {

Check warning on line 34 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L34

Added line #L34 was not covered by tests

private static final Logger logger = LogManager.getLogger(HbaseConnectionReflects.class);

Check warning on line 36 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L36

Added line #L36 was not covered by tests


static List<MetricRegistry> getRegistriesFromConnections(ClusterConnection conn, AsyncConnectionImpl asyncConn) {
List<MetricRegistry> registries = new ArrayList<>();

Check warning on line 40 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L40

Added line #L40 was not covered by tests

addMetricRegistryFromConnection(registries, conn);
addMetricRegistryFromAsyncConnection(registries, asyncConn);
return registries;

Check warning on line 44 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L42-L44

Added lines #L42 - L44 were not covered by tests
}

static void addMetricRegistryFromConnection(List<MetricRegistry> registries, ClusterConnection conn) {
MetricRegistry metricRegistry = getMetricRegistry(getMetricsConnection(conn));

Check warning on line 48 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L48

Added line #L48 was not covered by tests
if (metricRegistry != null) {
registries.add(metricRegistry);

Check warning on line 50 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L50

Added line #L50 was not covered by tests
}
}

Check warning on line 52 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L52

Added line #L52 was not covered by tests

static void addMetricRegistryFromAsyncConnection(List<MetricRegistry> registries, AsyncConnectionImpl asyncConn) {
MetricsConnection metricsConnection = getMetricsConnection(asyncConn)
.orElseThrow(() -> new NoSuchElementException("MetricsConnection not present"));
MetricRegistry metricRegistry = getMetricRegistry(metricsConnection);

Check warning on line 57 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L55-L57

Added lines #L55 - L57 were not covered by tests
if (metricRegistry != null) {
registries.add(metricRegistry);

Check warning on line 59 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L59

Added line #L59 was not covered by tests
}
}

Check warning on line 61 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L61

Added line #L61 was not covered by tests

@SuppressWarnings("unchecked")
static Optional<MetricsConnection> getMetricsConnection(AsyncConnectionImpl asyncConnection) {
try {
Method method = asyncConnection.getClass().getDeclaredMethod("getConnectionMetrics");
method.setAccessible(true);
return (Optional<MetricsConnection>) method.invoke(asyncConnection);
} catch (Exception e) {
logger.warn(e);
return Optional.empty();

Check warning on line 71 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L66-L71

Added lines #L66 - L71 were not covered by tests
}
}

static MetricsConnection getMetricsConnection(ClusterConnection connectionImplementation) {
try {
Method method = connectionImplementation.getClass().getDeclaredMethod("getConnectionMetrics");
method.setAccessible(true);
return (MetricsConnection) method.invoke(connectionImplementation);
} catch (Exception e) {
logger.warn(e);
return null;

Check warning on line 82 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L77-L82

Added lines #L77 - L82 were not covered by tests
}
}

static MetricRegistry getMetricRegistry(MetricsConnection metricsConnection) {
try {
Method method = metricsConnection.getClass().getDeclaredMethod("getMetricRegistry");
method.setAccessible(true);
return (MetricRegistry) method.invoke(metricsConnection);
} catch (Exception e) {
logger.warn(e);
return null;

Check warning on line 93 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L88-L93

Added lines #L88 - L93 were not covered by tests
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.collector.monitor.config;

import com.navercorp.pinpoint.collector.monitor.dao.hbase.HBaseMetricsAdapter;
import io.micrometer.core.instrument.MeterRegistry;
import org.apache.hadoop.hbase.client.AsyncConnection;
import org.apache.hadoop.hbase.client.AsyncConnectionImpl;
import org.apache.hadoop.hbase.client.ClusterConnection;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.shaded.com.codahale.metrics.MetricRegistry;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

import static com.navercorp.pinpoint.collector.monitor.config.HbaseConnectionReflects.getRegistriesFromConnections;

/**
* @author intr3p1d
*/
@Configuration
@ConditionalOnProperty(value = "pinpoint.modules.collector.hbase-client-metric.enabled", havingValue = "true")
public class HbaseMetricsConfiguration {

private final Logger logger = LogManager.getLogger(HbaseMetricsConfiguration.class);

Check warning on line 44 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L44

Added line #L44 was not covered by tests

public HbaseMetricsConfiguration() {
logger.info("Install {}", HbaseMetricsConfiguration.class.getSimpleName());
}

Check warning on line 48 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L46-L48

Added lines #L46 - L48 were not covered by tests

@Bean
public HBaseMetricsAdapter collectHBaseMetrics(
MeterRegistry meterRegistry,
@Qualifier("hbaseConnection")
FactoryBean<Connection> connectionFactoryBean,
@Qualifier("hbaseAsyncConnection")
FactoryBean<AsyncConnection> asyncConnectionFactoryBean
) {
try {
ClusterConnection conn = (ClusterConnection) connectionFactoryBean.getObject();
AsyncConnectionImpl asyncConn = (AsyncConnectionImpl) asyncConnectionFactoryBean.getObject();
List<MetricRegistry> registries = getRegistriesFromConnections(conn, asyncConn);

Check warning on line 61 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L59-L61

Added lines #L59 - L61 were not covered by tests

return new HBaseMetricsAdapter(

Check warning on line 63 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L63

Added line #L63 was not covered by tests
meterRegistry, registries
);
} catch (Exception e) {
logger.error("HbaseMetricsConfiguration Error: ", e);

Check warning on line 67 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L66-L67

Added lines #L66 - L67 were not covered by tests
}
return null;

Check warning on line 69 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L69

Added line #L69 was not covered by tests
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package com.navercorp.pinpoint.collector.monitor.dao.hbase;

import io.micrometer.core.instrument.DistributionSummary;
import io.micrometer.core.instrument.MeterRegistry;
import org.apache.hadoop.hbase.shaded.com.codahale.metrics.Counter;
import org.apache.hadoop.hbase.shaded.com.codahale.metrics.Gauge;
import org.apache.hadoop.hbase.shaded.com.codahale.metrics.Histogram;
import org.apache.hadoop.hbase.shaded.com.codahale.metrics.MetricRegistry;
import org.apache.hadoop.hbase.shaded.com.codahale.metrics.Timer;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Collection;

import static com.navercorp.pinpoint.collector.monitor.dao.hbase.MetricNameExtractor.extractName;
import static com.navercorp.pinpoint.collector.monitor.dao.hbase.MetricNameExtractor.extractTags;


public class HBaseMetricsAdapter {
private final Logger logger = LogManager.getLogger(HBaseMetricsAdapter.class);

Check warning on line 20 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L20

Added line #L20 was not covered by tests
private final MeterRegistry meterRegistry;
private final Collection<MetricRegistry> metricRegistries;

public HBaseMetricsAdapter(MeterRegistry meterRegistry, Collection<MetricRegistry> metricRegistries) {
this.meterRegistry = meterRegistry;
this.metricRegistries = metricRegistries;
initialize();
}

Check warning on line 28 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L24-L28

Added lines #L24 - L28 were not covered by tests

private void initialize() {
logger.info("initialize metricRegistries: {}", metricRegistries);

Check warning on line 31 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L31

Added line #L31 was not covered by tests

for (MetricRegistry metricRegistry : metricRegistries) {
if (metricRegistry != null) {
logger.info(metricRegistry);
metricRegistry.getMetrics().forEach((name, metric) -> {

Check warning on line 36 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L35-L36

Added lines #L35 - L36 were not covered by tests
if (metric instanceof Counter counter) {
registerCounterMetric(name, counter);

Check warning on line 38 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L38

Added line #L38 was not covered by tests
} else if (metric instanceof Timer timer) {
registerTimerMetric(name, timer);

Check warning on line 40 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L40

Added line #L40 was not covered by tests
} else if (metric instanceof Gauge<?> gauge) {
registerGaugeMetric(name, gauge);

Check warning on line 42 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L42

Added line #L42 was not covered by tests
} else if (metric instanceof Histogram histogram) {
registerHistogramMetric(name, histogram);

Check warning on line 44 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L44

Added line #L44 was not covered by tests
}
});

Check warning on line 46 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L46

Added line #L46 was not covered by tests
}
}
}

Check warning on line 49 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L48-L49

Added lines #L48 - L49 were not covered by tests

private void registerCounterMetric(String name, Counter counter) {
io.micrometer.core.instrument.Gauge.builder(extractName(name), counter, Counter::getCount)
.tags(extractTags(name))
.register(meterRegistry);
}

Check warning on line 55 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L52-L55

Added lines #L52 - L55 were not covered by tests

private void registerTimerMetric(String name, Timer timer) {
io.micrometer.core.instrument.Gauge.builder(extractName(name), timer, Timer::getCount)
.tags(extractTags(name))
.register(meterRegistry);
}

Check warning on line 61 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L58-L61

Added lines #L58 - L61 were not covered by tests

private void registerGaugeMetric(String name, Gauge<?> gauge) {
io.micrometer.core.instrument.Gauge.builder(extractName(name), gauge, HBaseMetricsAdapter::doubleValue)
.tags(extractTags(name))
.register(meterRegistry);
}

Check warning on line 67 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L64-L67

Added lines #L64 - L67 were not covered by tests

private void registerHistogramMetric(String name, Histogram histogram) {
DistributionSummary.builder(extractName(name))
.tags(extractTags(name))
.register(meterRegistry);
}

Check warning on line 73 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L70-L73

Added lines #L70 - L73 were not covered by tests

public static double doubleValue(Gauge<?> gauge) {
if (gauge == null || gauge.getValue() == null) {
return Double.NaN;

Check warning on line 77 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L77

Added line #L77 was not covered by tests
}
Object value = gauge.getValue();
return Double.parseDouble(value.toString());

Check warning on line 80 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L79-L80

Added lines #L79 - L80 were not covered by tests
}


@Override
public String toString() {
return "HBaseMetricsAdapter{" +

Check warning on line 86 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L86

Added line #L86 was not covered by tests
"logger=" + logger +
", meterRegistry=" + meterRegistry +
", metricRegistries=" + metricRegistries +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.collector.monitor.dao.hbase;

import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* @author intr3p1d
*/
public class MetricNameExtractor {

Check warning on line 27 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java#L27

Added line #L27 was not covered by tests

static String extractName(String name) {
int atIndex = name.lastIndexOf('.');
if (atIndex != -1) {
return name.substring(0, atIndex);
} else {
return name;

Check warning on line 34 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java#L34

Added line #L34 was not covered by tests
}
}

static Tags extractTags(String name) {
String regex = ".*\\.([0-9a-fA-F\\-]{36})@([0-9a-fA-F]+)$";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(name);

if (matcher.matches()) {
String uuid = matcher.group(1);
String hash = matcher.group(2);

return Tags.of(
Tag.of("clusterId", uuid),
Tag.of("connectionHash", hash)
);
} else {
return Tags.empty();

Check warning on line 52 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java

View check run for this annotation

Codecov / codecov/patch

collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java#L52

Added line #L52 was not covered by tests
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.navercorp.pinpoint.collector.monitor.dao.hbase;

import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.Tags;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* @author intr3p1d
*/
class MetricNameExtractorTest {

static final String METRIC_NAME = "org.apache.hadoop.hbase.client.MetricsConnection.executorPoolActiveThreads";
static final String DUMMY_CLUSTER_ID = "f72a0b6a-8141-4df9-96a3-754aac08e173";
static final String DUMMY_HASH = "10579683cf";

@Test
public void testCustomName() {
String example = METRIC_NAME + "." + DUMMY_CLUSTER_ID + "@" + DUMMY_HASH;
String actual = MetricNameExtractor.extractName(example);

Assertions.assertEquals(METRIC_NAME, actual);
}

@Test
public void testExtractTags() {
String example = METRIC_NAME + "." + DUMMY_CLUSTER_ID + "@" + DUMMY_HASH;
Tags expected = Tags.of(
Tag.of("clusterId", DUMMY_CLUSTER_ID),
Tag.of("connectionHash", DUMMY_HASH)
);
Tags actual = MetricNameExtractor.extractTags(example);

Assertions.assertEquals(expected, actual);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.navercorp.pinpoint.collector.grpc.config.GrpcStatConfiguration;
import com.navercorp.pinpoint.collector.grpc.config.GrpcStatReceiverConfiguration;
import com.navercorp.pinpoint.collector.monitor.MonitoredThreadPoolExecutorFactoryProvider;
import com.navercorp.pinpoint.collector.monitor.config.HbaseMetricsConfiguration;
import com.navercorp.pinpoint.collector.monitor.config.MicrometerConfiguration;
import com.navercorp.pinpoint.collector.monitor.MonitoringExecutors;
import com.navercorp.pinpoint.common.server.executor.ExecutorCustomizer;
Expand Down Expand Up @@ -55,6 +56,7 @@
GrpcKeepAliveScheduler.class,

MicrometerConfiguration.class,
HbaseMetricsConfiguration.class,

ChannelzConfiguration.class
})
Expand Down

0 comments on commit f45d066

Please sign in to comment.