Skip to content

Conversation

@pvragov
Copy link

@pvragov pvragov commented Oct 25, 2025

Problem: Context cancellation errors are not distinguished in current metrics.

Solution: Introduce a new canceled metric attribute.

Rationale: This is a non-breaking change. Extending the existing status attribute would break backward compatibility.

@jit-ci
Copy link

jit-ci bot commented Oct 25, 2025

Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset.

In case there are security findings, they will be communicated to you as a comment inside the PR.

Hope you’ll enjoy using Jit.

Questions? Comments? Want to learn more? Get in touch with us.

@pvragov pvragov changed the title Add a 'canceled' metrics attribute to separate context metrics Add a 'canceled' metrics attribute to separate context errors Oct 25, 2025
@pvragov pvragov force-pushed the add_canceled_metrics-attr branch from c528798 to 5eaacc5 Compare October 25, 2025 11:08
@ndyakov
Copy link
Member

ndyakov commented Oct 25, 2025

Hello, @pvragov and thank you for your contribution. Will review next week.

@ndyakov
Copy link
Member

ndyakov commented Oct 28, 2025

p.s. the name canceled may be a bit misleading. what do you think if it is named something like context_errtype and can be canceled, deadline or none ? In general, won't it make more sense to have the err type and not only the context err type?

@pvragov
Copy link
Author

pvragov commented Oct 28, 2025

p.s. the name canceled may be a bit misleading. what do you think if it is named something like context_errtype and can be canceled, deadline or none ? In general, won't it make more sense to have the err type and not only the context err type?

It could be tricky to define the list of error types and support it. I think there are two ways to solve this problem we should discuss.

  • Create a new counter (i.e., db.client.commands) with result attribute: ok, failed, canceled.
  • Extend the values of the state attribute to: ok, error, canceled. In this case, semantically it's okay that the state of operation is canceled. But we can break backward compatibility in cases where clients want to see all errors occurred. Anyway in real life it's more useful to separate canceled and error cases in metrics and may be we improve the users experience

p.s I used the 'canceled' attribute to solve the problem so as not to create a new metric and not break the backward compatibility and I completely agree that it's not the best solution of the problem.

@ndyakov
Copy link
Member

ndyakov commented Oct 28, 2025

@pvragov I am fine with having attribute here, but why should it be a boolean one? Can't it be a string ? Even if we decide to only cover the context errors let's have more information about the type. Having it named canceled when it includes timeout errors as well sounds incorrect in my mind.

@pvragov
Copy link
Author

pvragov commented Oct 28, 2025

@pvragov I am fine with having attribute here, but why should it be a boolean one? Can't it be a string ? Even if we decide to only cover the context errors let's have more information about the type. Having it named canceled when it includes timeout errors as well sounds incorrect in my mind.

Yes, it can. What about an 'result' attribute: success, fail, canceled, timeout ?

p.s. Technically timeout means cancelation by timeout and there is no problem to name this case as 'canceled'

@ndyakov
Copy link
Member

ndyakov commented Oct 28, 2025 via email

@pvragov
Copy link
Author

pvragov commented Oct 28, 2025

The main idea is separate context errors from others. As for me is enough to have one attribute 'result': success, fail, canceled and use it instead of state attribute. The 'state' attribute could be deprecated.

It's ok to mark network timeouts by the 'fail' value.

Anyway I'm ready to implement the solution you like. Please just describe it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants