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

feat: explicit gce interface ipv4 address metadata #8978

Merged

Conversation

jfreeland
Copy link
Contributor

@jfreeland jfreeland commented Jun 22, 2021

Always add GCE interface IPv4 address metadata for all interfaces. In cases where you have multiple interfaces, this can then be used, for instance, to rewrite the address label to target metrics on a separate interface.

This utilizes the Google Compute API's instances metadata, https://cloud.google.com/compute/docs/reference/rest/v1/instances, using the networkInterfaces[].networkIP field which according to the documentation will return an IPv4 address.

networkInterfaces[].networkIP | string | An IPv4 internal IP address to assign to the instance for this network interface. If not specified by the user, an unused internal IP is assigned by the system.
networkInterfaces[].ipv6Address | string | [Output Only] An IPv6 internal network address for this network interface.

In GCP a TCP load balancer (and probably others) can only forward traffic to nic0. A snippet from https://cloud.google.com/load-balancing/docs/network/setting-up-network-backend-service#configuring_the_load_balancer:

  • "If you are using an image provided by Compute Engine, your instances are automatically configured to handle this IP address. If you are using any other image, you must configure this address as an alias on nic0 or as a loopback on each instance."

In some cases this may mean that you need to move functions that historically ran on nic0 to another interface. For instance, some network software vendors typically run their management interface, where one scrapes metrics and manages the machine on nic0, however in GCP this requires moving the management interface to nic1 or some other interface. Take for instance https://github.com/memes/terraform-google-f5-bigip/blob/main/modules/metadata/files/multiNicMgmtSwap.sh.

Testing this requires that you set up 2 instances in GCE:

  • a node named <node_prefix>-N that has 2 interfaces and is exposing metrics on the relevant IP and port, e.g. node_exporter --web.listen-address="<management_ip>:9090"
    • the primary interface, e.g. nic0, should be in some network that is not your default network
    • the second interface, e.g. nic1, should be in some 'management' subnet
  • a prometheus node with an interface in the management subnet where you can download, build, and run prometheus from this branch, that (ideally) is running with a service account that has access to the GCP metadata service.

I used the following prometheus.conf and this worked as intended.

global:
  scrape_interval:     15s
  evaluation_interval: 30s

scrape_configs:
- job_name: prometheus

  honor_labels: true

  gce_sd_configs:
  - project: <my project>
    zone: us-central1-a
    filter: "name:<node_prefix>-*"

  relabel_configs:
    - source_labels: [__meta_gce_interface_ipv4_nic1]
      target_label: __address__
      replacement: "${1}:9090"

Related to #7406.

@jfreeland jfreeland force-pushed the feat/additional-gce-interfaces branch from e74dd5c to b3ce7e4 Compare June 22, 2021 04:12
@jfreeland jfreeland changed the title WIP: feat: gce metadata for additional interfaces feat(7406): gce metadata for additional interfaces Jun 22, 2021
@jfreeland jfreeland marked this pull request as ready for review June 22, 2021 04:28
@jfreeland jfreeland changed the title feat(7406): gce metadata for additional interfaces feat: gce metadata for additional interfaces Jun 22, 2021
Signed-off-by: Joey Freeland <joey@free.land>
@jfreeland jfreeland force-pushed the feat/additional-gce-interfaces branch from b3ce7e4 to 77e25cf Compare June 22, 2021 04:37
discovery/gce/gce.go Outdated Show resolved Hide resolved
discovery/gce/gce.go Outdated Show resolved Hide resolved
discovery/gce/gce.go Outdated Show resolved Hide resolved
@SuperQ
Copy link
Member

SuperQ commented Jun 22, 2021

The GCE networkInterfaces JSON includes a name attribute, we could possibly us that instead of assuming ethX

@jfreeland
Copy link
Contributor Author

The GCE networkInterfaces JSON includes a name attribute, we could possibly us that instead of assuming ethX

🤦 . updated.

@jfreeland jfreeland requested a review from SuperQ June 28, 2021 01:12
@roidelapluie
Copy link
Member

Thanks for your PR. For legal reasons, we require that all commits are signed with a DCO before we can merge them. See this blog post for considerations around this.

This means that the last line of your commit message should read like:

Signed-Off-By: Your Name <your@email.address>

If you are using GitHub through the web interface, it's quickest to close this PR and open a new one with the appropriate line.

If you are using Git on the command line, it is probably quickest to amend and force push. You can do that with

git commit --amend --signoff
git push -f $remote $remote_branch_for_pr

As always, be careful when force-pushing.

@jfreeland jfreeland force-pushed the feat/additional-gce-interfaces branch from 1ea51e0 to 74574f0 Compare June 29, 2021 15:59
Signed-off-by: Joey Freeland <joey@free.land>
@jfreeland jfreeland force-pushed the feat/additional-gce-interfaces branch from 74574f0 to 8017dd7 Compare June 29, 2021 16:01
@jfreeland
Copy link
Contributor Author

Thanks for your PR. For legal reasons, we require that all commits are signed with a DCO before we can merge them. See this blog post for considerations around this.

This means that the last line of your commit message should read like:

Signed-Off-By: Your Name <your@email.address>

If you are using GitHub through the web interface, it's quickest to close this PR and open a new one with the appropriate line.

If you are using Git on the command line, it is probably quickest to amend and force push. You can do that with

git commit --amend --signoff
git push -f $remote $remote_branch_for_pr

As always, be careful when force-pushing.

Sorry. Updated.

@jfreeland jfreeland changed the title feat: gce metadata for additional interfaces feat: gce interface ipv4 address metadata Jun 29, 2021
@jfreeland jfreeland changed the title feat: gce interface ipv4 address metadata feat: explicit gce interface ipv4 address metadata Jun 29, 2021
@roidelapluie
Copy link
Member

I like this change. Does the api guarantees we would only get ipv4?

@jfreeland
Copy link
Contributor Author

I like this change. Does the api guarantees we would only get ipv4?

We are using the networkIP field from https://cloud.google.com/compute/docs/reference/rest/v1/instances. There is a separate field for IPv6 address.

networkInterfaces[].networkIP | string | An IPv4 internal IP address to assign to the instance for this network interface. If not specified by the user, an unused internal IP is assigned by the system.
networkInterfaces[].ipv6Address | string | [Output Only] An IPv6 internal network address for this network interface.
{
  "id": string,
  "creationTimestamp": string,
  "name": string,
...
  },
...
  "networkInterfaces": [
    {
...
      "networkIP": string,
      "ipv6Address": string,

Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

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

I will let a few more hours for @SuperQ to review, otherwise I will merge this tomorrow.

Many thanks.

@jfreeland
Copy link
Contributor Author

I like this change. Does the api guarantees we would only get ipv4?

We are using the networkIP field from https://cloud.google.com/compute/docs/reference/rest/v1/instances. There is a separate field for IPv6 address.

Description updated for completeness.

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM, nice

Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

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

Thanks! One last nit.

discovery/gce/gce.go Outdated Show resolved Hide resolved
@roidelapluie
Copy link
Member

(I missed it in my last review, sorry)

Co-authored-by: Julien Pivotto <roidelapluie@gmail.com>
Signed-off-by: Joey Freeland <joey@free.land>
@jfreeland jfreeland force-pushed the feat/additional-gce-interfaces branch from ffefdd1 to 5d0a128 Compare July 6, 2021 11:57
@roidelapluie roidelapluie merged commit dcba645 into prometheus:main Jul 26, 2021
@roidelapluie
Copy link
Member

Thanks!

@jfreeland jfreeland deleted the feat/additional-gce-interfaces branch July 27, 2021 05:29
valyala added a commit to VictoriaMetrics/VictoriaMetrics that referenced this pull request Aug 3, 2021
valyala added a commit to VictoriaMetrics/VictoriaMetrics that referenced this pull request Aug 3, 2021
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.

None yet

3 participants