-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding observation in messaging and data
- Loading branch information
Showing
11 changed files
with
258 additions
and
105 deletions.
There are no files selected for viewing
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
81 changes: 81 additions & 0 deletions
81
...g/dapr-spring-data/src/main/java/io/dapr/spring/data/observation/DaprKeyValueContext.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,81 @@ | ||
package io.dapr.spring.data.observation; | ||
|
||
import io.micrometer.observation.transport.SenderContext; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
|
||
/** | ||
* {@link SenderContext} for Dapr KeyValue context. | ||
* | ||
*/ | ||
public final class DaprKeyValueContext extends SenderContext<DaprKeyValueContext.KeyValueHolder> { | ||
|
||
private final String beanName; | ||
|
||
private final String keyValueStore; | ||
|
||
|
||
private DaprKeyValueContext(KeyValueHolder keyValueHolder, String keyValueStore, String beanName) { | ||
super((carrier, key, value) -> keyValueHolder.property(key, value)); | ||
setCarrier(keyValueHolder); | ||
this.beanName = beanName; | ||
this.keyValueStore = keyValueStore; | ||
} | ||
|
||
/** | ||
* Create a new context. | ||
* @param kvStore KVStore to be used | ||
* @param beanName name of the bean used usually (typically a {@code DaprMessagingTemplate}) | ||
* @return DaprMessageSenderContext | ||
*/ | ||
public static DaprKeyValueContext newContext(String kvStore, String beanName) { | ||
KeyValueHolder keyValueHolder = new KeyValueHolder(); | ||
return new DaprKeyValueContext(keyValueHolder, kvStore, beanName); | ||
} | ||
|
||
public Map<String, String> properties() { | ||
return getCarrier().properties(); | ||
} | ||
|
||
|
||
/** | ||
* The name of the bean sending the message (typically a {@code DaprMessagingTemplate}). | ||
* @return the name of the bean sending the message | ||
*/ | ||
public String getBeanName() { | ||
return this.beanName; | ||
} | ||
|
||
/** | ||
* The destination topic for the message. | ||
* @return the topic the message is being sent to | ||
*/ | ||
public String getKeyValueStore() { | ||
return this.keyValueStore; | ||
} | ||
|
||
|
||
/** | ||
* Acts as a carrier for a Dapr KeyValue and records the propagated properties for | ||
* later access by the Dapr. | ||
*/ | ||
public static final class KeyValueHolder { | ||
|
||
private final Map<String, String> properties = new HashMap<>(); | ||
|
||
private KeyValueHolder() { | ||
} | ||
|
||
public void property(String key, String value) { | ||
this.properties.put(key, value); | ||
} | ||
|
||
public Map<String, String> properties() { | ||
return this.properties; | ||
} | ||
|
||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
...g-data/src/main/java/io/dapr/spring/data/observation/DaprKeyValueTemplateObservation.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 @@ | ||
package io.dapr.spring.data.observation; | ||
|
||
import io.micrometer.common.docs.KeyName; | ||
import io.micrometer.observation.Observation; | ||
import io.micrometer.observation.Observation.Context; | ||
import io.micrometer.observation.ObservationConvention; | ||
import io.micrometer.observation.docs.ObservationDocumentation; | ||
|
||
/** | ||
* An {@link Observation} for {@link io.dapr.spring.data.DaprKeyValueTemplate}. | ||
* | ||
*/ | ||
public enum DaprKeyValueTemplateObservation implements ObservationDocumentation { | ||
|
||
/** | ||
* Observation created when a Dapr template interacts with a KVStore. | ||
*/ | ||
TEMPLATE_OBSERVATION { | ||
|
||
@Override | ||
public Class<? extends ObservationConvention<? extends Context>> getDefaultConvention() { | ||
return DefaultDaprKeyValueTemplateObservationConvention.class; | ||
} | ||
|
||
@Override | ||
public String getPrefix() { | ||
return "spring.dapr.data.template"; | ||
} | ||
|
||
@Override | ||
public KeyName[] getLowCardinalityKeyNames() { | ||
return TemplateLowCardinalityTags.values(); | ||
} | ||
|
||
}; | ||
|
||
/** | ||
* Low cardinality tags. | ||
*/ | ||
public enum TemplateLowCardinalityTags implements KeyName { | ||
|
||
/** | ||
* Bean name of the template that interacts with the kv store. | ||
*/ | ||
BEAN_NAME { | ||
|
||
@Override | ||
public String asString() { | ||
return "spring.dapr.data.template.name"; | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/io/dapr/spring/data/observation/DaprKeyValueTemplateObservationConvention.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,23 @@ | ||
package io.dapr.spring.data.observation; | ||
|
||
|
||
import io.micrometer.observation.Observation.Context; | ||
import io.micrometer.observation.ObservationConvention; | ||
|
||
/** | ||
* {@link ObservationConvention} for Dapr KV template . | ||
* | ||
*/ | ||
public interface DaprKeyValueTemplateObservationConvention extends ObservationConvention<DaprKeyValueContext> { | ||
|
||
@Override | ||
default boolean supportsContext(Context context) { | ||
return context instanceof DaprKeyValueContext; | ||
} | ||
|
||
@Override | ||
default String getName() { | ||
return "spring.dapr.data.template"; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...ava/io/dapr/spring/data/observation/DefaultDaprKeyValueTemplateObservationConvention.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,35 @@ | ||
package io.dapr.spring.data.observation; | ||
|
||
import io.micrometer.common.KeyValues; | ||
|
||
/** | ||
* Default {@link DefaultDaprKeyValueTemplateObservationConvention} for Dapr template key values. | ||
* | ||
*/ | ||
public class DefaultDaprKeyValueTemplateObservationConvention implements DaprKeyValueTemplateObservationConvention { | ||
|
||
/** | ||
* A singleton instance of the convention. | ||
*/ | ||
public static final DefaultDaprKeyValueTemplateObservationConvention INSTANCE = | ||
new DefaultDaprKeyValueTemplateObservationConvention(); | ||
|
||
@Override | ||
public KeyValues getLowCardinalityKeyValues(DaprKeyValueContext context) { | ||
return KeyValues.of(DaprKeyValueTemplateObservation.TemplateLowCardinalityTags.BEAN_NAME.asString(), | ||
context.getBeanName()); | ||
} | ||
|
||
// Remove once addressed: | ||
// https://github.com/micrometer-metrics/micrometer-docs-generator/issues/30 | ||
@Override | ||
public String getName() { | ||
return "spring.dapr.data.template"; | ||
} | ||
|
||
@Override | ||
public String getContextualName(DaprKeyValueContext context) { | ||
return context.getKeyValueStore() + " store"; | ||
} | ||
|
||
} |
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.