|
| 1 | +// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License. |
| 2 | +// This product includes software developed at Datadog (https://www.datadoghq.com/). |
| 3 | +// Copyright 2019-Present Datadog, Inc. |
| 4 | + |
| 5 | +use serde::{Deserialize, Deserializer, Serialize, Serializer}; |
| 6 | + |
| 7 | +#[non_exhaustive] |
| 8 | +#[derive(Clone, Debug, Eq, PartialEq)] |
| 9 | +pub enum FormulaAndFunctionApmMetricStatName { |
| 10 | + ERRORS, |
| 11 | + ERROR_RATE, |
| 12 | + ERRORS_PER_SECOND, |
| 13 | + LATENCY_AVG, |
| 14 | + LATENCY_MAX, |
| 15 | + LATENCY_P50, |
| 16 | + LATENCY_P75, |
| 17 | + LATENCY_P90, |
| 18 | + LATENCY_P95, |
| 19 | + LATENCY_P99, |
| 20 | + LATENCY_P999, |
| 21 | + LATENCY_DISTRIBUTION, |
| 22 | + HITS, |
| 23 | + HITS_PER_SECOND, |
| 24 | + TOTAL_TIME, |
| 25 | + APDEX, |
| 26 | + UnparsedObject(crate::datadog::UnparsedObject), |
| 27 | +} |
| 28 | + |
| 29 | +impl ToString for FormulaAndFunctionApmMetricStatName { |
| 30 | + fn to_string(&self) -> String { |
| 31 | + match self { |
| 32 | + Self::ERRORS => String::from("errors"), |
| 33 | + Self::ERROR_RATE => String::from("error_rate"), |
| 34 | + Self::ERRORS_PER_SECOND => String::from("errors_per_second"), |
| 35 | + Self::LATENCY_AVG => String::from("latency_avg"), |
| 36 | + Self::LATENCY_MAX => String::from("latency_max"), |
| 37 | + Self::LATENCY_P50 => String::from("latency_p50"), |
| 38 | + Self::LATENCY_P75 => String::from("latency_p75"), |
| 39 | + Self::LATENCY_P90 => String::from("latency_p90"), |
| 40 | + Self::LATENCY_P95 => String::from("latency_p95"), |
| 41 | + Self::LATENCY_P99 => String::from("latency_p99"), |
| 42 | + Self::LATENCY_P999 => String::from("latency_p999"), |
| 43 | + Self::LATENCY_DISTRIBUTION => String::from("latency_distribution"), |
| 44 | + Self::HITS => String::from("hits"), |
| 45 | + Self::HITS_PER_SECOND => String::from("hits_per_second"), |
| 46 | + Self::TOTAL_TIME => String::from("total_time"), |
| 47 | + Self::APDEX => String::from("apdex"), |
| 48 | + Self::UnparsedObject(v) => v.value.to_string(), |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +impl Serialize for FormulaAndFunctionApmMetricStatName { |
| 54 | + fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> |
| 55 | + where |
| 56 | + S: Serializer, |
| 57 | + { |
| 58 | + match self { |
| 59 | + Self::UnparsedObject(v) => v.serialize(serializer), |
| 60 | + _ => serializer.serialize_str(self.to_string().as_str()), |
| 61 | + } |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +impl<'de> Deserialize<'de> for FormulaAndFunctionApmMetricStatName { |
| 66 | + fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
| 67 | + where |
| 68 | + D: Deserializer<'de>, |
| 69 | + { |
| 70 | + let s: String = String::deserialize(deserializer)?; |
| 71 | + Ok(match s.as_str() { |
| 72 | + "errors" => Self::ERRORS, |
| 73 | + "error_rate" => Self::ERROR_RATE, |
| 74 | + "errors_per_second" => Self::ERRORS_PER_SECOND, |
| 75 | + "latency_avg" => Self::LATENCY_AVG, |
| 76 | + "latency_max" => Self::LATENCY_MAX, |
| 77 | + "latency_p50" => Self::LATENCY_P50, |
| 78 | + "latency_p75" => Self::LATENCY_P75, |
| 79 | + "latency_p90" => Self::LATENCY_P90, |
| 80 | + "latency_p95" => Self::LATENCY_P95, |
| 81 | + "latency_p99" => Self::LATENCY_P99, |
| 82 | + "latency_p999" => Self::LATENCY_P999, |
| 83 | + "latency_distribution" => Self::LATENCY_DISTRIBUTION, |
| 84 | + "hits" => Self::HITS, |
| 85 | + "hits_per_second" => Self::HITS_PER_SECOND, |
| 86 | + "total_time" => Self::TOTAL_TIME, |
| 87 | + "apdex" => Self::APDEX, |
| 88 | + _ => Self::UnparsedObject(crate::datadog::UnparsedObject { |
| 89 | + value: serde_json::Value::String(s.into()), |
| 90 | + }), |
| 91 | + }) |
| 92 | + } |
| 93 | +} |
0 commit comments