Skip to content

Commit

Permalink
Convert type errors to single error with type.
Browse files Browse the repository at this point in the history
  • Loading branch information
dygfloyd authored and pront committed Nov 15, 2023
1 parent 5f80a21 commit 62b275a
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 156 deletions.
62 changes: 5 additions & 57 deletions src/internal_events/log_to_metric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,25 @@ impl<'a> InternalEvent for MetricMetadataInvalidFieldValueError<'a> {
}
}

pub struct MetricMetadataParseFloatError<'a> {
pub struct MetricMetadataParseError<'a> {
pub field: &'a str,
pub kind: &'a str,
}

impl<'a> InternalEvent for MetricMetadataParseFloatError<'a> {
impl<'a> InternalEvent for MetricMetadataParseError<'a> {
fn emit(self) {
let reason = "Failed to parse field as float.";
error!(
message = reason,
field = %self.field,
error_code = "failed_parsing_float",
error_code = format!("failed_parsing_{}", self.kind),
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING,
internal_log_rate_limit = true
);
counter!(
"component_errors_total", 1,
"error_code" => "failed_parsing_float",
"error_code" => format!("failed_parsing_{}", self.kind),
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
"field" => self.field.to_string(),
Expand All @@ -117,59 +118,6 @@ impl<'a> InternalEvent for MetricMetadataParseFloatError<'a> {
}
}

pub struct MetricMetadataParseIntError<'a> {
pub field: &'a str,
}

impl<'a> InternalEvent for MetricMetadataParseIntError<'a> {
fn emit(self) {
let reason = "Failed to parse field as int.";
error!(
message = reason,
field = %self.field,
error_code = "failed_parsing_int",
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING,
internal_log_rate_limit = true
);
counter!(
"component_errors_total", 1,
"error_code" => "failed_parsing_int",
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
"field" => self.field.to_string(),
);

emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
}
}

pub struct MetricMetadataParseArrayError<'a> {
pub field: &'a str,
}

impl<'a> InternalEvent for MetricMetadataParseArrayError<'a> {
fn emit(self) {
let reason = "Failed to parse field as array.";
error!(
message = reason,
field = %self.field,
error_code = "failed_parsing_array",
error_type = error_type::PARSER_FAILED,
stage = error_stage::PROCESSING,
internal_log_rate_limit = true
);
counter!(
"component_errors_total", 1,
"error_code" => "failed_parsing_array",
"error_type" => error_type::PARSER_FAILED,
"stage" => error_stage::PROCESSING,
"field" => self.field.to_string(),
);

emit!(ComponentEventsDropped::<UNINTENTIONAL> { count: 1, reason })
}
}
pub struct MetricMetadataMetricDetailsNotFoundError {}

impl InternalEvent for MetricMetadataMetricDetailsNotFoundError {
Expand Down
Loading

0 comments on commit 62b275a

Please sign in to comment.