|
10 | 10 | use anyhow::{Context, Result};
|
11 | 11 | use chrono::{DateTime, Utc};
|
12 | 12 | use cockroach_admin_client::Client;
|
| 13 | +use cockroach_admin_types::NodeId; |
13 | 14 | use futures::stream::{FuturesUnordered, StreamExt};
|
14 | 15 | use parallel_task_set::ParallelTaskSet;
|
15 | 16 | use serde::{Deserialize, Serialize};
|
@@ -760,93 +761,6 @@ impl PrometheusMetrics {
|
760 | 761 | }
|
761 | 762 | }
|
762 | 763 |
|
763 |
| -/// CockroachDB Node ID |
764 |
| -/// |
765 |
| -/// This field is stored internally as a String to avoid questions |
766 |
| -/// about size, signedness, etc - it can be treated as an arbitrary |
767 |
| -/// unique identifier. |
768 |
| -#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize)] |
769 |
| -pub struct NodeId(pub String); |
770 |
| - |
771 |
| -impl NodeId { |
772 |
| - pub fn new(id: String) -> Self { |
773 |
| - Self(id) |
774 |
| - } |
775 |
| - |
776 |
| - pub fn as_str(&self) -> &str { |
777 |
| - &self.0 |
778 |
| - } |
779 |
| -} |
780 |
| - |
781 |
| -impl std::fmt::Display for NodeId { |
782 |
| - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
783 |
| - write!(f, "{}", self.0) |
784 |
| - } |
785 |
| -} |
786 |
| - |
787 |
| -impl std::str::FromStr for NodeId { |
788 |
| - type Err = std::convert::Infallible; |
789 |
| - |
790 |
| - fn from_str(s: &str) -> Result<Self, Self::Err> { |
791 |
| - Ok(Self(s.to_string())) |
792 |
| - } |
793 |
| -} |
794 |
| - |
795 |
| -// When parsing the underlying NodeId, we force it to be interpreted |
796 |
| -// as a String. Without this custom Deserialize implementation, we |
797 |
| -// encounter parsing errors when querying endpoints which return the |
798 |
| -// NodeId as an integer. |
799 |
| -impl<'de> serde::Deserialize<'de> for NodeId { |
800 |
| - fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> |
801 |
| - where |
802 |
| - D: serde::Deserializer<'de>, |
803 |
| - { |
804 |
| - use serde::de::{Error, Visitor}; |
805 |
| - use std::fmt; |
806 |
| - |
807 |
| - struct NodeIdVisitor; |
808 |
| - |
809 |
| - impl<'de> Visitor<'de> for NodeIdVisitor { |
810 |
| - type Value = NodeId; |
811 |
| - |
812 |
| - fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result { |
813 |
| - formatter |
814 |
| - .write_str("a string or integer representing a node ID") |
815 |
| - } |
816 |
| - |
817 |
| - fn visit_str<E>(self, value: &str) -> Result<Self::Value, E> |
818 |
| - where |
819 |
| - E: Error, |
820 |
| - { |
821 |
| - Ok(NodeId(value.to_string())) |
822 |
| - } |
823 |
| - |
824 |
| - fn visit_string<E>(self, value: String) -> Result<Self::Value, E> |
825 |
| - where |
826 |
| - E: Error, |
827 |
| - { |
828 |
| - Ok(NodeId(value)) |
829 |
| - } |
830 |
| - |
831 |
| - fn visit_i64<E>(self, value: i64) -> Result<Self::Value, E> |
832 |
| - where |
833 |
| - E: Error, |
834 |
| - { |
835 |
| - Ok(NodeId(value.to_string())) |
836 |
| - } |
837 |
| - |
838 |
| - fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> |
839 |
| - where |
840 |
| - E: Error, |
841 |
| - { |
842 |
| - Ok(NodeId(value.to_string())) |
843 |
| - } |
844 |
| - } |
845 |
| - |
846 |
| - deserializer.deserialize_any(NodeIdVisitor) |
847 |
| - } |
848 |
| -} |
849 |
| - |
850 | 764 | /// CockroachDB node liveness status
|
851 | 765 | ///
|
852 | 766 | /// From CockroachDB's [NodeLivenessStatus protobuf enum](https://github.com/cockroachdb/cockroach/blob/release-21.1/pkg/kv/kvserver/liveness/livenesspb/liveness.proto#L107-L138)
|
@@ -1281,16 +1195,16 @@ sql_exec_latency_bucket{le="0.01"} 25
|
1281 | 1195 | assert!(result.unwrap().metrics.is_empty());
|
1282 | 1196 |
|
1283 | 1197 | // Malformed lines (missing values, extra spaces, etc.)
|
1284 |
| - let malformed_input = r#" |
| 1198 | + let malformed_input = " |
1285 | 1199 | metric_name_no_value
|
1286 |
| -metric_name_with_space |
| 1200 | +metric_name_with_space\x20 |
1287 | 1201 | metric_name_multiple spaces here
|
1288 | 1202 | = value_no_name
|
1289 | 1203 | leading_space_metric 123
|
1290 |
| -trailing_space_metric 456 |
| 1204 | +trailing_space_metric 456\x20 |
1291 | 1205 | metric{label=value} 789
|
1292 | 1206 | metric{malformed=label value} 999
|
1293 |
| -"#; |
| 1207 | +"; |
1294 | 1208 | let result = PrometheusMetrics::parse(malformed_input);
|
1295 | 1209 | assert!(result.is_ok());
|
1296 | 1210 | // Should ignore malformed lines gracefully
|
|
0 commit comments