Skip to content

Commit

Permalink
Merge pull request #177 from gestalt-config/feat/metrics
Browse files Browse the repository at this point in the history
Feat/metrics
  • Loading branch information
credmond-git authored Apr 4, 2024
2 parents ff270d9 + 57552b7 commit 5da5c05
Show file tree
Hide file tree
Showing 77 changed files with 4,036 additions and 502 deletions.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -993,6 +993,66 @@ By default, the builder has several rules predefined [here](https://github.com/g

# Additional Modules

## Micrometer Metrics
Gestalt exposes several metrics and provides a implementation for micrometer.

To import the micrometer implementation add `gestalt-micrometer` to your build files.

In Maven:
```xml
<dependency>
<groupId>com.github.gestalt-config</groupId>
<artifactId>gestalt-micrometer</artifactId>
<version>${version}</version>
</dependency>
```
Or in Gradle
```kotlin
implementation("com.github.gestalt-config:gestalt-micrometer:${version}")
```

Then when building gestalt, you need to register the module config `MicrometerModuleConfig` using the `MicrometerModuleConfigBuilder`.

An example of using the registering the `MicrometerModuleConfig` using the `MicrometerModuleConfigBuilder`.

```java
SimpleMeterRegistry registry = new SimpleMeterRegistry();

GestaltBuilder builder = new GestaltBuilder();
Gestalt gestalt = builder
.addSource(MapConfigSourceBuilder.builder().setCustomConfig(configs).build())
.setMetricsEnabled(true)
.addModuleConfig(MicrometerModuleConfigBuilder.builder()
.setMeterRegistry(registry)
.setPrefix("myApp")
.build())
.build();

gestalt.loadConfigs();
```

There are several options to configure the micrometer module.

| Option | Description | Default |
|-----------------|---------------------------------------------------------------------------------------------------------------------------|---------------------|
| meterRegistry | Provide the micrometer registry to submit metrics. | SimpleMeterRegistry |
| includePath | When getting a config include the path in the metrics tags. This can be a high cardinality metric so is not recommended. | false |
| includeClass | When getting a config include the class in the metrics tags. This can be a high cardinality metric so is not recommended. | false |
| includeOptional | When getting a config include if the configuration is optional or default as a true or false in the metrics tags. | false |
| includeTags | When getting a config include the tags in the request in the metrics tags. | false |
| prefix | Add a prefix to the metrics to better group your metrics. | gestalt |

The following metrics are exposed

| Metric | Description | Type | tags |
|--------------------|-------------------------------------------------------------------------------------------------------------|----------|---------------------------------------------------------------------------------------------------------------|
| config.get | Recorded when we request a configuration from gestalt that is not cached. | Timer | default:true if a default or optional value is returned. exception:exception class if there was an exception. |
| reload | Recorded when a configuration is reloaded. | Timer | source:source name. exception:exception class if there was an exception. |
| get.config.missing | Incremented for each missing configuration, if decoding a class this can be more than one. | Counter | optional: true or false depending if the optional value is optional or has a default. |
| get.config.error | Incremented for each error while getting a configuration, if decoding a class this can be more than one. | Counter | |
| get.config.warning | Incremented for warning error while getting a configuration, if decoding a class this can be more than one. | Counter | |
| cache.hit | Incremented for each request served from the cache. A cache miss would be recorded in the metric config.get | Counter | |


## Guice dependency injection.
Allow Gestalt to inject configuration directly into your classes using Guice using the `@InjectConfig` annotation on any class fields. This does not support constructor injection (due to Guice limitation)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {

allprojects {
group = "com.github.gestalt-config"
version = "0.25.3"
version = "0.26.0"
}


Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ void hash() throws GestaltException {
}

@Test
@SuppressWarnings("removal")
void tags() throws GestaltException {
S3ConfigSource source = new S3ConfigSource(s3Client, BUCKET_NAME, UPLOAD_FILE_NAME, Tags.of("toy", "ball"));
Assertions.assertEquals(Tags.of("toy", "ball"), source.getTags());
Expand Down
Loading

0 comments on commit 5da5c05

Please sign in to comment.