Skip to content

Commit

Permalink
Added cardinality warning to IPAddr/SocketAddr implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
rnijveld committed Oct 14, 2022
1 parent 63c23da commit cbd2ba2
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/encoding/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,20 +207,38 @@ impl Encode for () {
}
}

/// Warning: Using an IP address as a label is only useful when the number of
/// distinct values is low (i.e. low cardinality). In all other cases you should
/// combine your metrics into a single metric instead. Especially bad examples
/// are: storing separate metrics for each client connecting to your public
/// service or having a large fleet of servers and storing individual binding
/// addresses.
impl Encode for Ipv4Addr {
fn encode(&self, writer: &mut dyn Write) -> Result<(), std::io::Error> {
writer.write_all(self.to_string().as_bytes())?;
Ok(())
}
}

/// Warning: Using an IP address as a label is only useful when the number of
/// distinct values is low (i.e. low cardinality). In all other cases you should
/// combine your metrics into a single metric instead. Especially bad examples
/// are: storing separate metrics for each client connecting to your public
/// service or having a large fleet of servers and storing individual binding
/// addresses.
impl Encode for Ipv6Addr {
fn encode(&self, writer: &mut dyn Write) -> Result<(), std::io::Error> {
writer.write_all(self.to_string().as_bytes())?;
Ok(())
}
}

/// Warning: Using an IP address as a label is only useful when the number of
/// distinct values is low (i.e. low cardinality). In all other cases you should
/// combine your metrics into a single metric instead. Especially bad examples
/// are: storing separate metrics for each client connecting to your public
/// service or having a large fleet of servers and storing individual binding
/// addresses.
impl Encode for IpAddr {
fn encode(&self, writer: &mut dyn Write) -> Result<(), std::io::Error> {
match self {
Expand All @@ -230,20 +248,38 @@ impl Encode for IpAddr {
}
}

/// Warning: Using a socket address as a label is only useful when the number of
/// distinct values is low (i.e. low cardinality). In all other cases you should
/// combine your metrics into a single metric instead. Especially bad examples
/// are: storing separate metrics for each client connecting to your public
/// service or having a large fleet of servers and storing individual binding
/// addresses.
impl Encode for SocketAddrV4 {
fn encode(&self, writer: &mut dyn Write) -> Result<(), std::io::Error> {
writer.write_all(self.to_string().as_bytes())?;
Ok(())
}
}

/// Warning: Using a socket address as a label is only useful when the number of
/// distinct values is low (i.e. low cardinality). In all other cases you should
/// combine your metrics into a single metric instead. Especially bad examples
/// are: storing separate metrics for each client connecting to your public
/// service or having a large fleet of servers and storing individual binding
/// addresses.
impl Encode for SocketAddrV6 {
fn encode(&self, writer: &mut dyn Write) -> Result<(), std::io::Error> {
writer.write_all(self.to_string().as_bytes())?;
Ok(())
}
}

/// Warning: Using a socket address as a label is only useful when the number of
/// distinct values is low (i.e. low cardinality). In all other cases you should
/// combine your metrics into a single metric instead. Especially bad examples
/// are: storing separate metrics for each client connecting to your public
/// service or having a large fleet of servers and storing individual binding
/// addresses.
impl Encode for SocketAddr {
fn encode(&self, writer: &mut dyn Write) -> Result<(), std::io::Error> {
match self {
Expand Down

0 comments on commit cbd2ba2

Please sign in to comment.