Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add probe_ip_addr_hash to detect if the IP changes #584

Merged
merged 3 commits into from
Mar 18, 2020

Conversation

Wing924
Copy link
Contributor

@Wing924 Wing924 commented Mar 18, 2020

WHAT

add probe_ip_addr_hash metrics to specify the hash of IP address

WHY

We want to detect if the IP is changed by change(probe_ip_addr_hash[10h])

Use Case

Assume you use CDN and you want to monitoring your web server.

blackbox_exporter --> CDN edge server --> origin server

if the edge server failover, blackbox exporter returns error and the IP address will be changed.
With probe_ip_addr_hash, we can tell the error happen due to edge failover.

@brian-brazil
Copy link
Contributor

Can we use a better hash?

@Wing924
Copy link
Contributor Author

Wing924 commented Mar 18, 2020

@brian-brazil this hash is copied from java's String.hashCode().
http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/java/lang/String.java#l1452

Why I use this simple hash instead of SHA256:

  • we don't need slow cryptographic hash function because IP address is not secret
  • we can't set 256bit to value because value is float64
  • unsigned 32bit integer looks good when you convert to float64

But I'm not have strong opinion on using this simple hash.
Do you have any recommendation?

@brian-brazil
Copy link
Contributor

Use any hash that Go provides and truncate it to 32 bits.

Signed-off-by: Wing924 <[email protected]>
@Wing924
Copy link
Contributor Author

Wing924 commented Mar 18, 2020

@brian-brazil I've changed the hash func to Go provided.

prober/utils.go Outdated
@@ -37,8 +38,20 @@ func chooseProtocol(ctx context.Context, IPProtocol string, fallbackIPProtocol b
Name: "probe_ip_protocol",
Help: "Specifies whether probe ip protocol is IP4 or IP6",
})

probeIPAddr := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This IP could have high cardinality, it's not safe to expose it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I've removed that.

Signed-off-by: Wing924 <[email protected]>
@brian-brazil brian-brazil merged commit a677fdb into prometheus:master Mar 18, 2020
@brian-brazil
Copy link
Contributor

Thanks!

@Wing924 Wing924 deleted the export_ip branch March 18, 2020 12:35
@basroovers
Copy link

Looking for some documentation on the metric on how this can be used lead me to this pull request.
I just wanted to share how an alert rule would work (1st post already showed it but this won't work since "change" is a non-existent function, "changes" is):

changes(probe_ip_addr_hash[10h])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants