Skip to content

Commit

Permalink
add self reference to TaggedMetricInstrument
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Schneider <johannes.schneider@bosch.io>
  • Loading branch information
jokraehe committed Aug 25, 2021
1 parent 835f4a6 commit 7156777
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
public interface TaggedMetricInstrument<T extends MetricInstrument> extends MetricInstrument {

/**
* @return this instance.
*/
T self();

/**
* Adds the given tag to the timer.
* Already existing tags with the same key will be overridden.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
public interface Counter extends ResettableMetricInstrument, TaggedMetricInstrument<Counter> {

@Override
default Counter self() {
return this;
}

/**
* Increments the value of the counter by one.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
public interface Gauge extends ResettableMetricInstrument, TaggedMetricInstrument<Gauge> {

@Override
default Gauge self() {
return this;
}

/**
* Increments the value of the gauge by one.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
public interface Histogram extends ResettableMetricInstrument, TaggedMetricInstrument<Histogram> {

@Override
default Histogram self() {
return this;
}

/**
* Records the specified value in the histogram.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
*/
public interface PreparedTimer extends Timer, ResettableMetricInstrument, TaggedMetricInstrument<PreparedTimer> {

@Override
default PreparedTimer self() {
return this;
}

/**
* Starts the Timer. This method is package private so only {@link Timers} can start
* this timer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.eclipse.ditto.internal.utils.metrics.instruments.TaggedMetricInstrument;

Expand All @@ -24,6 +23,11 @@
*/
public interface StartedTimer extends Timer, TaggedMetricInstrument<StartedTimer> {

@Override
default StartedTimer self() {
return this;
}

/**
* Stops the timer and all its segments.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
*/
public interface PreparedTrace extends TaggedMetricInstrument<PreparedTrace>, TraceTags<PreparedTrace> {

@Override
default PreparedTrace self() {
return this;
}

/**
* Starts the trace at the current instant.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
public interface StartedTrace extends TaggedMetricInstrument<StartedTrace>, TraceTags<StartedTrace> {

@Override
default StartedTrace self() {
return this;
}

/**
* Finishes the trace. Any method called after the trace is finished has no effect.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
package org.eclipse.ditto.internal.utils.tracing.instruments.trace;

import javax.annotation.Nullable;

import org.eclipse.ditto.internal.utils.metrics.instruments.TaggedMetricInstrument;
import org.eclipse.ditto.internal.utils.tracing.TracingTags;

Expand All @@ -28,7 +30,10 @@ public interface TraceTags<T extends TaggedMetricInstrument<T>> extends TaggedMe
* @param correlationId the correlation ID to add to the trace
* @return the new TaggedMetricInstrument instance containing the tag
*/
default T correlationId(final CharSequence correlationId) {
default T correlationId(@Nullable final CharSequence correlationId) {
if (null == correlationId) {
return self();
}
return tag(TracingTags.CORRELATION_ID, correlationId.toString());
}

Expand All @@ -38,7 +43,10 @@ default T correlationId(final CharSequence correlationId) {
* @param connectionId the connection ID to add to the trace
* @return the new TaggedMetricInstrument instance containing the tag
*/
default T connectionId(final CharSequence connectionId) {
default T connectionId(@Nullable final CharSequence connectionId) {
if (null == connectionId) {
return self();
}
return tag(TracingTags.CONNECTION_ID, connectionId.toString());
}

Expand All @@ -48,7 +56,10 @@ default T connectionId(final CharSequence connectionId) {
* @param connectionType the connection type to add to the trace
* @return the new TaggedMetricInstrument instance containing the tag
*/
default T connectionType(final CharSequence connectionType) {
default T connectionType(@Nullable final CharSequence connectionType) {
if (null == connectionType) {
return self();
}
return tag(TracingTags.CONNECTION_TYPE, connectionType.toString());
}

Expand Down

0 comments on commit 7156777

Please sign in to comment.