-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L34
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L36
|
||
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L40
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L42-L44
|
||
} | ||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L48
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L50
|
||
} | ||
} | ||
Check warning on line 52 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L52
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L55-L57
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L59
|
||
} | ||
} | ||
Check warning on line 61 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L61
|
||
|
||
@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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L66-L71
|
||
} | ||
} | ||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L77-L82
|
||
} | ||
} | ||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseConnectionReflects.java#L88-L93
|
||
} | ||
} | ||
} |
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L44
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L46-L48
|
||
|
||
@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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L59-L61
|
||
|
||
return new HBaseMetricsAdapter( | ||
Check warning on line 63 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L63
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L66-L67
|
||
} | ||
return null; | ||
Check warning on line 69 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/config/HbaseMetricsConfiguration.java#L69
|
||
} | ||
|
||
} |
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L20
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L24-L28
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L31
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L35-L36
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L38
|
||
} 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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L40
|
||
} 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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L42
|
||
} 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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L44
|
||
} | ||
}); | ||
Check warning on line 46 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L46
|
||
} | ||
} | ||
} | ||
Check warning on line 49 in collector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L48-L49
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L52-L55
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L58-L61
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L64-L67
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L70-L73
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L77
|
||
} | ||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L79-L80
|
||
} | ||
|
||
|
||
@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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/HBaseMetricsAdapter.java#L86
|
||
"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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java#L27
|
||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java#L34
|
||
} | ||
} | ||
|
||
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 Codecov / codecov/patchcollector-monitor/src/main/java/com/navercorp/pinpoint/collector/monitor/dao/hbase/MetricNameExtractor.java#L52
|
||
} | ||
} | ||
|
||
} |
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); | ||
} | ||
|
||
} |