Skip to content

Commit f8caf41

Browse files
committed
Added cardinality warning to IPAddr/SocketAddr implementations
1 parent 4259d73 commit f8caf41

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/encoding/text.rs

+36
Original file line numberDiff line numberDiff line change
@@ -207,20 +207,38 @@ impl Encode for () {
207207
}
208208
}
209209

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

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

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

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

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

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

0 commit comments

Comments
 (0)