Skip to content

Conversation

dstevensson
Copy link
Contributor

Describe Your Changes

  • Add support in GCE service discovery for finding IPv6 address

Hi! Long time user, first time contributor. 👋
This change will expose any IPv6 address assigned to an instance under the meta label __meta_gce_ipv6. In GCE an instance can either have a native IPv6 address or an unique local address (ULA) but not both. I have not updated the tests because it's unfortunately outside of my ability (I'm not a programmer nor very familiar with golang). I've compiled and run vmagent against my own GCP project where I have instances without IPv6, with native IPv6 and with ULA IPv6 running. See result below (I've masked and replaced identifying information)

## With native IPv6
{__address__="10.4.0.13:80",__meta_gce_instance_id="123213213123",__meta_gce_instance_name="with-native-ipv6",__meta_gce_instance_status="RUNNING",__meta_gce_interface_ipv4_nic0="10.4.0.13",__meta_gce_ipv6="2600:1900::::::", __meta_gce_machine_type="https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-b/machineTypes/e2-micro",__meta_gce_network="https://www.googleapis.com/compute/v1/projects/myproject/global/networks/my-network",__meta_gce_private_ip="10.4.0.13",__meta_gce_project="myproject",__meta_gce_public_ip="1.1.1.1",__meta_gce_subnetwork="https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/subnetworks/subnet-europe-west1",__meta_gce_zone="https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-b",__metrics_path__="/metrics",__scheme__="http",__scrape_interval__="30s",__scrape_timeout__="10s",job="gce"}

## With ULA IPv6
{__address__="10.0.0.115:80",__meta_gce_instance_id="123213213123",__meta_gce_instance_name="with-ula-ipv6",__meta_gce_instance_status="RUNNING",__meta_gce_interface_ipv4_nic0="10.0.0.115",__meta_gce_ipv6="fd20:dee:edd:3800:0:15a:0:0"__meta_gce_machine_type="https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-b/machineTypes/e2-micro",__meta_gce_network="https://www.googleapis.com/compute/v1/projects/myproject/global/networks/my-network",__meta_gce_private_ip="10.0.0.115",__meta_gce_project="myproject",__meta_gce_subnetwork="https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/subnetworks/my-subnet",__meta_gce_zone="https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-d",__metrics_path__="/metrics",__scheme__="http",__scrape_interval__="30s",__scrape_timeout__="10s",job="gce"}

## Without IPv6
{__address__="10.4.0.31:80",__meta_gce_instance_id="123213213123",__meta_gce_instance_name="without-ipv6",__meta_gce_instance_status="RUNNING",__meta_gce_interface_ipv4_nic0="10.4.0.31",__meta_gce_machine_type="https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-b/machineTypes/e2-micro",__meta_gce_network="https://www.googleapis.com/compute/v1/projects/myproject/global/networks/my-network",__meta_gce_private_ip="10.4.0.31",__meta_gce_project="myproject",__meta_gce_public_ip="1.1.1.1",__meta_gce_subnetwork="https://www.googleapis.com/compute/v1/projects/myproject/regions/europe-west1/subnetworks/subnet-europe-west1",__meta_gce_zone="https://www.googleapis.com/compute/v1/projects/myproject/zones/europe-west1-b",__metrics_path__="/metrics",__scheme__="http",__scrape_interval__="30s",__scrape_timeout__="10s",job="gce"}

Checklist

The following checks are mandatory:

if len(iface.Ipv6AccessConfigs) > 0 {
ac := iface.Ipv6AccessConfigs[0]
if ac.Type == "DIRECT_IPV6" {
m.Add("__meta_gce_ipv6", ac.ExternalIpv6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be added as __meta_gce_public_ipv6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it's a matter of taste. Looking at the other service discovery they seem to handle it all different. Eg:
__meta_digitalocean_public_ipv6
__meta_ec2_ipv6_addresses
__meta_hetzner_public_ipv6_network
__meta_ovhcloud_vps_ipv6
__meta_ovhcloud_dedicated_server_ipv6
__meta_vultr_instance_main_ipv6
In the case of GCE it can only have a native IPv6 range attached to it or a ULA address so there's won't ever be a conflict (unless Google break their APIs). That said, I have no strong opinions on this and would be fine with something like __meta_gce_public_ipv6 and __meta_gce_private_ipv6 if the project prefers it.

Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing, that concerns me is possible label duplicate. If ULA is defined and iface.Ipv6Address != "" is not empty, multiple values for the __meta_gce_ipv6 label will be added.

There is already a case for GCE ipv4 address - __meta_gce_public_ip. And I wonder, should be follow this naming pattern for nat related IPs?

Copy link
Contributor

Choose a reason for hiding this comment

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

According to the google API docs https://cloud.google.com/compute/docs/reference/rest/beta/instances/addNetworkInterface:

ipv6Address - An IPv6 internal network address for this network interface. To use a static internal IP address, it must be unused and in the same region as the instance's zone. If not specified, Google Cloud will automatically assign an internal IPv6 address from the instance's subnetwork.

ipv6AccessConfigs[].externalIpv6 - Applies to ipv6AccessConfigs only. The first IPv6 address of the external IPv6 range associated with this instance, prefix length is stored in externalIpv6PrefixLength in ipv6AccessConfig. To use a static external IP address, it must be unused and in the same region as the instance's zone. If not specified, Google Cloud will automatically assign an external IPv6 address from the instance's subnetwork.

So I changed metadata labels according to it. Feel free to add your input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I apologize for the radio silence, I've been away and I continue to be away from a computer for another couple of weeks. Thank you for taking care of this, the changes lgtm.

f41gh7 added 2 commits July 28, 2025 15:59
Copy link
Contributor

@f41gh7 f41gh7 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@f41gh7 f41gh7 left a comment

Choose a reason for hiding this comment

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

LGTM

@f41gh7 f41gh7 requested review from makasim and zekker6 July 28, 2025 14:16
Copy link

codecov bot commented Jul 28, 2025

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 54.86%. Comparing base (8aaa828) to head (0f1debf).
⚠️ Report is 3507 commits behind head on master.

Files with missing lines Patch % Lines
lib/promscrape/discovery/gce/instance.go 0.00% 6 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9370      +/-   ##
==========================================
- Coverage   60.37%   54.86%   -5.52%     
==========================================
  Files         411      526     +115     
  Lines       76609    81926    +5317     
==========================================
- Hits        46253    44947    -1306     
- Misses      27794    34611    +6817     
+ Partials     2562     2368     -194     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@f41gh7 f41gh7 merged commit 7dd9407 into VictoriaMetrics:master Jul 31, 2025
10 checks passed
@f41gh7
Copy link
Contributor

f41gh7 commented Jul 31, 2025

Thanks for contribution!

@f41gh7 f41gh7 added the waiting for release The change was merged to upstream, but wasn't released yet. label Jul 31, 2025
f41gh7 pushed a commit that referenced this pull request Jul 31, 2025
This change will expose any IPv6 addresses assigned to an instance under
the meta labels:
* `__meta_gce_public_ipv6` -native IPv6 address, globally routed
* `__meta_gce_internal_ipv6` - unique local address (ULA).

Fixes #9370
@f41gh7
Copy link
Contributor

f41gh7 commented Aug 5, 2025

The feature was included into v1.123.0 release

@f41gh7 f41gh7 removed the waiting for release The change was merged to upstream, but wasn't released yet. label Aug 5, 2025
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