-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Do not instrument "hello" #4994
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
base: main
Are you sure you want to change the base?
Conversation
When MongoObservationCommandListener is enabled according to documentation, there is a race in metrics registration: > The meter (MeterId{name='spring.data.mongodb.command.active', tags=[tag(db.name=test),tag(db.operation=hello),tag(db.system=mongodb),tag(net.peer.name=localhost),tag(net.peer.port=27017),tag(net.transport=IP.TCP),tag(spring.data.mongodb.cluster_id=6840b93dabcd29b2f0526362)]}) registration has failed: ... Prometheus does not allow register metric with different tags. The problem is that healthcheck calls Mongo command "hello" which does not refer to any collection. Consequently, tag "db.mongodb.collection" is absent for "hello" but present in regular commands. Event if regular commands always wins the race (and metrics always has tag "collection"), the race must be removed. My proposal is skip "hello" instrumentation, like "admin" commands Signed-off-by: michaldo <[email protected]>
BTW, micrometer has different solution for this problem. (Maybe better?) io.micrometer.core.instrument.binder.mongodb.DefaultMongoCommandTagsProvider:
|
The collection may be absent for a wide number of commands. Clearly, a I suggest that you implement a Paging @jonatan-ivanov for further guidance |
I'm not sure what you mean by "race" but this is not a race condition. Order does not matter here, if you try to create something with the same name but different set of tags (e.g.: a tag is sometimes there, sometimes not), this is happening in Prometheus.
I think if you want to solve this issue, the solution is not removing instrumentation but improving it. This means that if a value is missing, use a value that signals that it is missing, e.g. instead of: if (collection != null) {
observation.lowCardinalityKeyValue("collection", collection);
} this can work: observation.lowCardinalityKeyValue("collection", collection != null ? collection : KeyValue.NONE_VALUE); I think, this is the interesting part for this exact issue: Lines 63 to 66 in ba15b53
I think a fix could be something like this? if (!ObjectUtils.isEmpty(context.getCollectionName())) {
keyValues = keyValues.and(MONGODB_COLLECTION.withValue(context.getCollectionName()));
}
else {
keyValues = keyValues.and(MONGODB_COLLECTION.withValue(KeyValue.NONE_VALUE));
} I think not instrumenting hello is a different question but regardless if it is valid or not, I think this might be a bug that could be fixed in patch versions while nit instrumenting hello can be a breaking change so it should rather happen in a minor version. Also, other than @mp911de's suggestion to use an
|
@jonatan-ivanov thanks for clarification, I will update my PR
By race I mean that code
if visible on http://localhost:8080/actuator/prometheus?includedNames=t1
But code
shows
It means who first registers metrics, decided which tags are present If tags match, both counters work
|
Signed-off-by: michaldo <[email protected]>
When MongoObservationCommandListener is enabled according to documentation, there is a race in metrics registration:
Prometheus does not allow register metric with different tags. The problem is that healthcheck calls Mongo command "hello" which does not refer to any collection. Consequently, tag "db.mongodb.collection" is absent for "hello" but present in regular commands.
Event if regular commands always wins the race (and metrics always has tag "collection"), the race must be removed.
My proposal is skip "hello" instrumentation, like "admin" commands