-
Notifications
You must be signed in to change notification settings - Fork 962
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
[Dynatrace] Logging verbosity: Move metadata discrepancy logging to WarnThenDebug #4583
Merged
shakuzen
merged 2 commits into
micrometer-metrics:1.12.x
from
dynatrace-oss-contrib:dynatrace-metadata-verbosity
Jan 31, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
55 changes: 55 additions & 0 deletions
55
...ter-registry-dynatrace/src/main/java/io/micrometer/dynatrace/v2/WarnThenDebugLoggers.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,55 @@ | ||
/* | ||
* Copyright 2024 VMware, Inc. | ||
* | ||
* 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 | ||
* | ||
* https://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 io.micrometer.dynatrace.v2; | ||
|
||
import io.micrometer.common.util.internal.logging.WarnThenDebugLogger; | ||
|
||
/** | ||
* This internal class holds loggers that are used in {@link DynatraceExporterV2}. They | ||
* are all just extending the default {@link WarnThenDebugLogger}. It is necessary to | ||
* extend them, because the {@link WarnThenDebugLogger} does not allow creating a new | ||
* logger with just a name (a class object has to be passed). If the WarnThenDebugLogger | ||
* is created with the same class type multiple times, the same instance will be returned. | ||
* This would mean that in a scenario with multiple loggers, only the first call would log | ||
* the warning, and all subsequent calls will log at debug. | ||
*/ | ||
class WarnThenDebugLoggers { | ||
|
||
static class StackTraceLogger extends WarnThenDebugLogger { | ||
|
||
public StackTraceLogger() { | ||
super(StackTraceLogger.class); | ||
} | ||
|
||
} | ||
|
||
static class NanGaugeLogger extends WarnThenDebugLogger { | ||
|
||
public NanGaugeLogger() { | ||
super(NanGaugeLogger.class); | ||
} | ||
|
||
} | ||
|
||
static class MetadataDiscrepancyLogger extends WarnThenDebugLogger { | ||
|
||
public MetadataDiscrepancyLogger() { | ||
super(MetadataDiscrepancyLogger.class); | ||
} | ||
|
||
} | ||
|
||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't think that's accurate. The two instances will use the same logger but the level is still controlled by the instance flag in each.
I wrote the following test:
And the log output is:
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 think you are right, the description is off. I wanted to assert on the different
WarnThenDebugLogger
s, to ensure that all warning messages are triggered. Initially, I was using three separateWarnThenDebugLogger
s to do that (without the subclasses). There is only one constructor for WarnThenDebugLogger and it takes aClass
parameter:micrometer/micrometer-core/src/main/java/io/micrometer/core/util/internal/logging/WarnThenDebugLogger.java
Lines 37 to 39 in 16dadc0
Since there is no obvious choice of which Class type to put there, I at first put
WarnThenDebugLogger.class
.In the tests, we are using the
MockLoggerFactory
toget
these Loggers. There, I have two choices of how to retrieve the Loggers:micrometer/micrometer-test/src/main/java/io/micrometer/core/util/internal/logging/MockLoggerFactory.java
Lines 46 to 48 in 16dadc0
micrometer/micrometer-test/src/main/java/io/micrometer/core/util/internal/logging/MockLoggerFactory.java
Lines 57 to 59 in 16dadc0
Since there is no way of creating the
WarnThenDebugLogger
with a name instead of theClass
object, all three used theWarnThenDebugLogger.class
to create, and then the sameWarnThenDebugLogger.class
to retrieve them from theMockLoggerFactory
. But: theMockLoggerFactory
cannot distinguish between these instances, since they all have the same name. Consequently, the tests were very flaky, because it is not clear whichWarnThenDebugLogger
was being returned bymockLoggerFactory.getLogger(WarnThenDebugLogger.class)
.In order to work around this, I created the new classes that basically set a specific "name" (by using the
Class
type of the subclass) to the separateWarnThenDebugLogger
s. This way, there will be three separateWarnThenDebugLogger
s in theMockLoggerFactory
(each with a different name), and I can pull the right one to assert on.Do you think this is the wrong approach? Alternatively, I could add API surface to the WarnThenDebugLogger to allow creating one with a specific name. Happy to discuss other alternatives as well!
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.
Updated the description in f05701b
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.
Thanks. Perhaps we can look at improving the usability of MockLoggerFactory or some other way to make testing this easier. /cc @jonatan-ivanov
The changes are mostly internal, though the class that will be logged is different with this change. I assume you're okay with that, and if so, I'm okay to merge the changes.
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.
Yep, sounds good! Thank you!