Skip to content

Commit

Permalink
♻️ Refactoring metrics plugin classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ujibang committed Aug 7, 2023
1 parent 7cc46b3 commit 89ac724
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
</encoder>
</appender>

<root level="info">
<root level="debug">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</root>

<statusListener class="ch.qos.logback.core.status.NopStatusListener" />

</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayDeque;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -55,20 +56,10 @@ public void testMetricNameAndLabelsSerialization() {
var nameAndLabelsAsString = nameAndLabelsFromConstructor.toString();

LOG.debug("string representation {}", nameAndLabelsAsString);
LOG.debug("toString representation {}", nameAndLabelsFromConstructor);

var nameAndLabelsFromString = MetricNameAndLabels.fromString(nameAndLabelsAsString);

assertEquals(nameAndLabelsFromConstructor, nameAndLabelsFromString);
}

@Test
public void xxx() {
var ml = new MetricLabel("xxx_*", "foo");
var eml = escapeMetricLabel(ml);
LOG.info(eml.toString());
}

private MetricLabel escapeMetricLabel(MetricLabel label) {
return new MetricLabel(label.name().replaceAll("\\*", "STAR"), label.value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import org.restheart.plugins.StringService;
import static org.restheart.utils.BsonUtils.array;
import org.restheart.utils.HttpStatus;

import com.codahale.metrics.SharedMetricRegistries;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.common.TextFormat;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ MetricFamilySamples fromCounter(String dropwizardName, Counter counter) {
/**
* Export gauge as a prometheus gauge.
*/
MetricFamilySamples fromGauge(String dropwizardName, Gauge gauge) {
MetricFamilySamples fromGauge(String dropwizardName, Gauge<?> gauge) {
Object obj = gauge.getValue();
double value;
if (obj instanceof Number) {
Expand Down Expand Up @@ -157,6 +157,7 @@ MetricFamilySamples fromMeter(String dropwizardName, Meter meter) {
}

@Override
@SuppressWarnings("rawtypes")
public List<MetricFamilySamples> collect() {
Map<String, MetricFamilySamples> mfSamplesMap = new HashMap<String, MetricFamilySamples>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

package org.restheart.metrics;

import com.codahale.metrics.SharedMetricRegistries;
import io.undertow.util.PathTemplate;
import io.undertow.util.PathTemplateMatcher;
import io.undertow.util.PathTemplateMatcher.PathMatchResult;
Expand All @@ -36,6 +35,9 @@
import static org.restheart.metrics.MetricsService.METRICS_REGISTRIES_PREFIX;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codahale.metrics.SharedMetricRegistries;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashSet;
Expand Down
41 changes: 0 additions & 41 deletions metrics/src/main/java/org/restheart/metrics/TestService.java

This file was deleted.

3 changes: 3 additions & 0 deletions restheart.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
},
{
"path": "metrics"
},
{
"path": ".settings"
}
],
"settings": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public DigestAuthMechanism(final String realmName, final String domain, final St
this(Collections.singletonList(DigestAlgorithm.MD5), Collections.singletonList(DigestQop.AUTH), realmName, domain, new SimpleNonceManager(), mechanismName, identityManager);
}

@SuppressWarnings("removal")
@SuppressWarnings({"removal", "deprecated"})
private IdentityManager getIdentityManager(SecurityContext securityContext) {
return identityManager != null ? identityManager : securityContext.getIdentityManager();
}
Expand Down

0 comments on commit 89ac724

Please sign in to comment.