This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
forked from jaegertracing/jaeger-client-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes jaegertracing#338 - Deprecated StatsReporter
Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
- Loading branch information
1 parent
4009b2d
commit 7871952
Showing
13 changed files
with
500 additions
and
67 deletions.
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
jaeger-core/src/main/java/com/uber/jaeger/metrics/InMemoryMetricsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (c) 2017, The Jaeger Authors | ||
* | ||
* 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.uber.jaeger.metrics; | ||
|
||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
/** | ||
* An ephemeral metrics factory, storing data in memory. This metrics factory is not meant to be used for production | ||
* purposes. | ||
*/ | ||
public class InMemoryMetricsFactory implements MetricsFactory { | ||
private Map<String, AtomicLong> counters = new ConcurrentHashMap<String, AtomicLong>(); | ||
private Map<String, AtomicLong> timers = new ConcurrentHashMap<String, AtomicLong>(); | ||
private Map<String, AtomicLong> gauges = new ConcurrentHashMap<String, AtomicLong>(); | ||
|
||
@Override | ||
public Counter createCounter(String name, Map<String, String> tags) { | ||
final AtomicLong value = new AtomicLong(0); | ||
counters.put(Metrics.addTagsToMetricName(name, tags), value); | ||
|
||
return new Counter() { | ||
@Override | ||
public void inc(long delta) { | ||
synchronized (value) { | ||
value.addAndGet(delta); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Timer createTimer(final String name, final Map<String, String> tags) { | ||
final AtomicLong value = new AtomicLong(0); | ||
timers.put(Metrics.addTagsToMetricName(name, tags), value); | ||
|
||
return new Timer() { | ||
@Override | ||
public void durationMicros(long time) { | ||
synchronized (value) { | ||
value.addAndGet(time); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Gauge createGauge(final String name, final Map<String, String> tags) { | ||
final AtomicLong value = new AtomicLong(0); | ||
gauges.put(Metrics.addTagsToMetricName(name, tags), value); | ||
|
||
return new Gauge() { | ||
@Override | ||
public void update(long amount) { | ||
value.addAndGet(amount); | ||
} | ||
}; | ||
} | ||
|
||
/** | ||
* Returns the counter value information for the counter with the given metric name. | ||
* Note that the metric name is not the counter name, as a metric name usually includes the tags. | ||
* | ||
* @see Metrics#addTagsToMetricName(String, Map) | ||
* @param name the metric name, which includes the tags | ||
* @return the counter value or -1, if no counter exists for the given metric name | ||
*/ | ||
public long getCounter(String name) { | ||
return getValue(counters, name); | ||
} | ||
|
||
/** | ||
* Returns the current value for the gauge with the given metric name. Note that the metric name is not the gauge | ||
* name, as a metric name usually includes the tags. | ||
* | ||
* @see Metrics#addTagsToMetricName(String, Map) | ||
* @param name the metric name, which includes the tags | ||
* @return the gauge value or -1, if no gauge exists for the given metric name | ||
*/ | ||
public long getGauge(String name) { | ||
return getValue(gauges, name); | ||
} | ||
|
||
/** | ||
* Returns the current accumulated timing information for the timer with the given metric name. | ||
* Note that the metric name is not the timer name, as a metric name usually includes the tags. | ||
* | ||
* @see Metrics#addTagsToMetricName(String, Map) | ||
* @param name the metric name, which includes the tags | ||
* @return the timer value or -1, if no timer exists for the given metric name | ||
*/ | ||
public long getTimer(String name) { | ||
return getValue(timers, name); | ||
} | ||
|
||
private long getValue(Map<String, AtomicLong> collection, String name) { | ||
AtomicLong value = collection.get(name); | ||
if (null == value) { | ||
return -1; | ||
} else { | ||
return value.get(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
jaeger-core/src/main/java/com/uber/jaeger/metrics/MetricsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2017, The Jaeger Authors | ||
* | ||
* 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.uber.jaeger.metrics; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Provides a standardized way to create metrics-related objects, like {@link Counter}, {@link Timer} and {@link Gauge}. | ||
* | ||
*/ | ||
public interface MetricsFactory { | ||
/** | ||
* Creates a counter with the given gauge name and set of tags. The actual metric name is a combination of those two | ||
* values. The counter starts at 0. | ||
* | ||
* @see Metrics#addTagsToMetricName(String, Map) | ||
* @param name the counter name | ||
* @param tags the tags to add to the counter | ||
* @return a {@link Counter} with a metric name following the counter name and tags | ||
*/ | ||
Counter createCounter(String name, Map<String, String> tags); | ||
|
||
/** | ||
* Creates a timer with the given timer name and set of tags. The actual metric name is a combination of those two | ||
* values. The timer starts at 0. | ||
* | ||
* @see Metrics#addTagsToMetricName(String, Map) | ||
* @param name the timer name | ||
* @param tags the tags to add to the timer | ||
* @return a {@link Timer} with a metric name following the counter name and tags | ||
*/ | ||
Timer createTimer(String name, Map<String, String> tags); | ||
|
||
/** | ||
* Creates a gauge with the given gauge name and set of tags. The actual metric name is a combination of those two | ||
* values. The timer starts at 0. | ||
* | ||
* @see Metrics#addTagsToMetricName(String, Map) | ||
* @param name the timer name | ||
* @param tags the tags to add to the timer | ||
* @return a {@link Gauge} with a metric name following the gauge name and tags | ||
*/ | ||
Gauge createGauge(String name, Map<String, String> tags); | ||
} |
49 changes: 49 additions & 0 deletions
49
jaeger-core/src/main/java/com/uber/jaeger/metrics/NoopMetricsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2017, The Jaeger Authors | ||
* | ||
* 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.uber.jaeger.metrics; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* A metrics factory that implements NOOP counters, timers and gauges. | ||
*/ | ||
public class NoopMetricsFactory implements MetricsFactory { | ||
@Override | ||
public Counter createCounter(String name, Map<String, String> tags) { | ||
return new Counter() { | ||
@Override | ||
public void inc(long delta) { | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Timer createTimer(final String name, final Map<String, String> tags) { | ||
return new Timer() { | ||
@Override | ||
public void durationMicros(long time) { | ||
} | ||
}; | ||
} | ||
|
||
@Override | ||
public Gauge createGauge(final String name, final Map<String, String> tags) { | ||
return new Gauge() { | ||
@Override | ||
public void update(long amount) { | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.