-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
chore(metrics): Align error_type enum values #4848
Conversation
14082f1
to
c563424
Compare
e46a6a3
to
cb2a890
Compare
cb2a890
to
22db078
Compare
This seems really close to #978. I'm wondering if we'd want to make these classifications part of the error event directly? |
22db078
to
c8359ae
Compare
@binarylogic That's certainly a possibility as part of a more comprehensive refactor of how we do this. I would say, though, that this PR wouldn't fundamentally impede such an effort; in fact, such an undertaking could use the same |
Sounds good. |
@bruceg @JeanMertz I'm happy to defer to both of you on this. To summarize, the two questions on the table:
But I have no dog in this fight, so I'm also happy to restrict this PR to just renaming the various |
I agree here. Anywhere we want to restrict the cardinality of something, we should be trying to use an enum. It would be nice to take it a step further yet, by only accepting those enums. This could be introducing a step where the enum is either enforced by type (ie a function for emitting the error counter) or a macro that accepts an identifier instead of an expression (so strings aren't usable).
This doesn't seem to make as much sense. Each error struct will result in a single |
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.
Two minor nits, but nothing blocking, and I agree with @bruceg's comments, but would defer enum enforcement to a follow-up PR, since this seems (almost) good to go as-is.
src/internal_events/mod.rs
Outdated
// Possible values for the "error_type" tag | ||
pub enum ErrorTypes { | ||
FieldMissing, | ||
InvalidMetric, | ||
MappingFailed, | ||
MatchFailed, | ||
ParseFailed, | ||
RenderError, | ||
SerializationFailed, | ||
TargetFieldExists, | ||
TemplateError, | ||
TypeConversionFailed, | ||
ValueInvalid, | ||
} | ||
|
||
impl ErrorTypes { | ||
fn to_str(&self) -> &str { | ||
match self { | ||
ErrorTypes::FieldMissing => "field_missing", | ||
ErrorTypes::InvalidMetric => "invalid_metric", | ||
ErrorTypes::MappingFailed => "mapping_failed", | ||
ErrorTypes::MatchFailed => "match_failed", | ||
ErrorTypes::ParseFailed => "parse_failed", | ||
ErrorTypes::RenderError => "render_error", | ||
ErrorTypes::SerializationFailed => "serialization_failed", | ||
ErrorTypes::TargetFieldExists => "target_field_exists", | ||
ErrorTypes::TemplateError => "template_error", | ||
ErrorTypes::TypeConversionFailed => "type_conversion_failed", | ||
ErrorTypes::ValueInvalid => "value_invalid", | ||
} | ||
} | ||
} | ||
|
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'm not sure this type of structure has any real benefits over a set of constants, at least without further work on emitting these errors. It doesn't enforce (in the compiler) that we only use these values, and requires extra code at each invocation (which admittedly will be completely inlined in release builds). It does add a namespace (ErrorTypes
) but that can also be provided with a module.
Signed-off-by: Luc Perkins <luc@timber.io>
c8359ae
to
c205797
Compare
Signed-off-by: Luc Perkins <luc@timber.io>
@bruceg @JeanMertz Oops, I made the changes requested by Jean without reading Bruce's comment. I have no strong feelings re: enum vs. const. Happy to defer on that if either of you feels particularly strongly. If the enum approach is okay, I'll fix the current errors; otherwise, I'll revamp. |
There doesn't seem to be consensus around the right way to do this, and I suspect there will at some point be a broader effort to standardize, so I'm going to close this. Happy to revisit and help out at any point. |
When working on Cue configuration for internal metrics in PR #4820, I noticed some discrepancies in the possible values for
error_type
(a tag for theprocessing_errors_total
metric). This PR provides a convenient enum mechanism for keeping these values aligned.