-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Move Dynatrace metrics exporter for API v1 to a separate package #2553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Dynatrace metrics exporter for API v1 to a separate package #2553
Conversation
|
@pirgeo Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
b97024d to
db46f58
Compare
|
@pirgeo Thank you for signing the Contributor License Agreement! |
...meter-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v1/DynatraceCustomMetric.java
Show resolved
Hide resolved
...egistry-dynatrace/src/main/java/io/micrometer/dynatrace/v1/DynatraceMeterRegistryImplV1.java
Outdated
Show resolved
Hide resolved
...ons/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceConfig.java
Outdated
Show resolved
Hide resolved
...ons/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceConfig.java
Outdated
Show resolved
Hide resolved
...registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceMeterRegistryImplBase.java
Outdated
Show resolved
Hide resolved
...r-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v1/DynatraceNamingConvention.java
Outdated
Show resolved
Hide resolved
...meter-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v1/DynatraceCustomMetric.java
Show resolved
Hide resolved
...micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java
Outdated
Show resolved
Hide resolved
...try-dynatrace/src/test/java/io/micrometer/dynatrace/v1/DynatraceMeterRegistryImplV1Test.java
Outdated
Show resolved
Hide resolved
...egistry-dynatrace/src/main/java/io/micrometer/dynatrace/v1/DynatraceMeterRegistryImplV1.java
Outdated
Show resolved
Hide resolved
74a088c to
b222b9d
Compare
| check("technologyType", DynatraceConfig::technologyType).andThen(Validated::nonBlank) | ||
| ); | ||
| // Currently only v1 is implemented. This check will be extended once more versions are added. | ||
| if (apiVersion() == DynatraceApiVersion.V1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is an enum now, this check is not necessary, enums are type-safe and since there is only one value: V1 this can't be anything else than V1 unless somebody overrides it but in that case they will overwrite validate too.
What I would do here is the following:
@Override
default Validated<?> validate() {
return checkAll(this,
c -> StepRegistryConfig.validate(c),
checkRequired("apiToken", DynatraceConfig::apiToken),
checkRequired("uri", DynatraceConfig::uri),
checkRequired("deviceId", DynatraceConfig::deviceId),
check("technologyType", DynatraceConfig::technologyType).andThen(Validated::nonBlank),
check("apiVersion", DynatraceConfig::apiVersion)
);
}
Because of the version is an enum, this will try to convert it (by calling apiVersion) and if that call won't be successful (e.g.: invalid value), it will make the result invalid. Please see my comment on the test class of this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is much easier, and I adopted it for the v1 exporter. However, for the v2 exporter, we will only require the API version and checking these four required parameters with a .andThen(v -> v.invalidateWhen(<check-version-here>) construct for v1 seems a bit hard to read. Is there another way to make this more concise?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InfluxConfix does something similar though, in this case, I would create a validateV1 and a validateV2 method (the current validate becomes validateV1). With them you can do:
@Override
default Validated<?> validate() {
return apiVersion() == V1 ? validateV1() : validateV2();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I split it out to a separate function, and also removed the invalidVersion test, as the test data is invalid and can never happen in a non-test environment. If the spring boot app is started with an application property of v-INVALID, for example, it will just crash on startup and provide all valid values (which is just V1) in this case.
Another way to get around this would be to explicitly validate the apiVersion before accessing it, something like the following:
@Override
default Validated<?> validate() {
Validated<DynatraceApiVersion> apiVersionValidation = checkRequired("apiVersion", DynatraceConfig::apiVersion).apply(this);
if (apiVersionValidation.isInvalid()) {
return apiVersionValidation;
}
return apiVersion() == V1 ? validateV1() : validateV2();
}
which seems a bit unnecessary if this case never actually appears during use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized that that is only the case when using micrometer with Spring Boot. I think the solution I posted above (with the additional step of validating the apiVersion) should work, if i just access the apiVersion() method without validation first I recieve a ValidationException. I added the additional validation step.
...ons/micrometer-registry-dynatrace/src/main/java/io/micrometer/dynatrace/DynatraceConfig.java
Outdated
Show resolved
Hide resolved
...micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java
Outdated
Show resolved
Hide resolved
...micrometer-registry-dynatrace/src/test/java/io/micrometer/dynatrace/DynatraceConfigTest.java
Outdated
Show resolved
Hide resolved
...r-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v1/DynatraceNamingConvention.java
Show resolved
Hide resolved
...ter-registry-dynatrace/src/test/java/io/micrometer/dynatrace/v1/DynatraceExporterV1Test.java
Outdated
Show resolved
Hide resolved
c7c40a3 to
2aca20e
Compare
|
Hi @jonatan-ivanov, I think I addressed all the comments above. Please let me know if there's anything missing so we can move on with this. Thanks! |
4fd760d
into
micrometer-metrics:move-dynatrace-registry-v1
|
@pirgeo Sorry for not getting back to you earlier. I merged your PR but not yet into master. I'm going to try/fix a few things (validation*) on the validation*: I totally forgot that Java only supports private methods in interfaces from Java 9. I'm not sure we should have a public validateV1 method on the config interface. |
|
@jonatan-ivanov Thanks a lot, these changes look good to me! |
* Move Dynatrace metrics exporter for API v1 to a separate package (#2553) * Move Dynatrace metrics exporter for API v1 to a separate package * rename dynatrace exporter * use an enum for Dynatrace API versions. * make DynatraceNamingConvention public * fix formatting * rename classes to have version at the end, move enum to uppercase, remove thread factory from exporter * move naming convention and delegate to the v1 implementation * update config validation and tests * rename variables in test files * remove unused imports * split out validation * re-add the apiVersion check and test * update misleading comment and remove duplicate apiVersion check * Adding validation logic into validate in DynatraceConfig Unfortunately Java 8 does not support private methods in interfaces (9+ does) and I'm not sure we should have a public validateV1 method * Polishing Dynatrace V1 refactor - javadoc - ctor/method reordering (to be consistent and ease diffing) - get the logger based on Class not by String - start the threadpool at the last step in the ctor - license - static imports * Breaking circular dependency between DynatraceMeterRegistry and DynatraceExporterV1 Co-authored-by: Georg Pirklbauer <[email protected]>
* Move Dynatrace metrics exporter for API v1 to a separate package (#2553) * Move Dynatrace metrics exporter for API v1 to a separate package * rename dynatrace exporter * use an enum for Dynatrace API versions. * make DynatraceNamingConvention public * fix formatting * rename classes to have version at the end, move enum to uppercase, remove thread factory from exporter * move naming convention and delegate to the v1 implementation * update config validation and tests * rename variables in test files * remove unused imports * split out validation * re-add the apiVersion check and test * update misleading comment and remove duplicate apiVersion check * Adding validation logic into validate in DynatraceConfig Unfortunately Java 8 does not support private methods in interfaces (9+ does) and I'm not sure we should have a public validateV1 method * Polishing Dynatrace V1 refactor - javadoc - ctor/method reordering (to be consistent and ease diffing) - get the logger based on Class not by String - start the threadpool at the last step in the ctor - license - static imports * Breaking circular dependency between DynatraceMeterRegistry and DynatraceExporterV1 * Add an exporter for the Dynatrace metrics API v2 Co-authored-by: Armin Ruech <[email protected]> * remove a comma that might lead to invalid ingestion result parsing * Address code review comments * Use new library features to make the exporter code more concise * Making dependency configuration calls consistent (Parenthesis is not a must in Groovy) * Clean-up comments in DynatraceConfig (no validation changes) * Fixing license header in DynatraceExporterV2 * Converting config field to local variable in ctor of DynatraceMeterRegistry * DynatraceExporterV2 refactor: renamings, method order/visibility * Simplify DynatraceExporterV2 * Adding back partitioning for Dynatrace V1 * More formatting for DynatraceExporterV2 * Simplifying toMeterLine and createMeterLine methods * Improving naming and error messages * Fixing tests after refactor * Implement fallback for config uri. (cherry picked from commit 46f2b77b747b017ba37a0ef585b98d0dc65c3c02) * add a warning on unlikely configurations and check if the token needs to be sent (cherry picked from commit 2c43bddc5e260d44dbc0f8f0b479e08fd18c3771) Co-authored-by: Georg Pirklbauer <[email protected]> * Fix/improve DynatraceExporterV2Test, round one: - Using MockClock instead of Thread.sleep - Improve test setup - Fix/improve tests for: Gauge, TimeGauge, Counter, FunctionCounter, Timer, FunctionTimer, LongTaskTimer, DistributionSummary * Fix/improve DynatraceExporterV2Test, round two: - Custom Meter - Invalid cases (also dedupe) * DynatraceExporterV2Test: static imports, nullable problems * Initialize DynatraceExporterV2Test the JUnit way * Improving DynatraceExporterV2Test and test the interaction with the http client * Fixing overwriting user-defined percentiles. * re-enabling empty tag tests * Adding DynatraceMeterRegistryTest * +javadoc * Rename blank tag tests, part one Co-authored-by: Georg Pirklbauer <[email protected]> * Rename blank tag tests, part two Co-authored-by: Georg Pirklbauer <[email protected]> * Removing artificially added 0th percentile meters Co-authored-by: Georg Pirklbauer <[email protected]> Co-authored-by: Armin Ruech <[email protected]>
This is a PR in preparation for the Dynatrace API v2 exporter (#2295). It moves the current v1 implementation into the v1 package while keeping the interface unchanged, making this a compatible change.