Skip to content

Support IPv6 for egress metrics #333

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

Merged
merged 6 commits into from
Jun 16, 2025
Merged

Conversation

terassyi
Copy link
Contributor

@terassyi terassyi commented Jun 11, 2025

This PR adds a IPv6 support for following egress related metrics.

  • coil_egress_nftables_masqueraded_packets_total
  • coil_egress_nftables_masqueraded_bytes_total
  • coil_egress_nftables_invalid_packets_total
  • coil_egress_nftables_invalid_bytes_total

I introduced a new label named protocol for these metrics, which can take ipv4 or ipv6.

Signed-off-by: terashima [email protected]

@terassyi terassyi self-assigned this Jun 11, 2025
terassyi added 3 commits June 11, 2025 09:17
Signed-off-by: terashima <[email protected]>
Signed-off-by: terashima <[email protected]>
Signed-off-by: terashima <[email protected]>
@terassyi
Copy link
Contributor Author

We can get metrics like this.

kubectl -n internet exec -it egress-697d96cf57-k24hm -- curl http://localhost:8080/metrics | grep nftables
# HELP coil_egress_nftables_invalid_bytes_total the number of bytes that are dropped as invalid packets by nftables
# TYPE coil_egress_nftables_invalid_bytes_total gauge
coil_egress_nftables_invalid_bytes_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv4"} 0
coil_egress_nftables_invalid_bytes_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv6"} 0
# HELP coil_egress_nftables_invalid_packets_total the number of packets that are dropped as invalid packets by nftables
# TYPE coil_egress_nftables_invalid_packets_total gauge
coil_egress_nftables_invalid_packets_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv4"} 0
coil_egress_nftables_invalid_packets_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv6"} 0
# HELP coil_egress_nftables_masqueraded_bytes_total the number of bytes that are masqueraded by nftables
# TYPE coil_egress_nftables_masqueraded_bytes_total gauge
coil_egress_nftables_masqueraded_bytes_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv4"} 60
coil_egress_nftables_masqueraded_bytes_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv6"} 640
# HELP coil_egress_nftables_masqueraded_packets_total the number of packets that are masqueraded by nftables
# TYPE coil_egress_nftables_masqueraded_packets_total gauge
coil_egress_nftables_masqueraded_packets_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv4"} 1
coil_egress_nftables_masqueraded_packets_total{egress="egress",namespace="internet",pod="egress-697d96cf57-k24hm",protocol="ipv6"} 8

@terassyi terassyi requested review from Copilot and yokaze June 12, 2025 04:13
@terassyi terassyi marked this pull request as ready for review June 12, 2025 04:13
Copilot

This comment was marked as outdated.

Signed-off-by: terashima <[email protected]>
@terassyi terassyi requested a review from Copilot June 12, 2025 04:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances egress metrics by adding IPv6 support and a new protocol label on existing nftables metrics, enabling separate tracking for IPv4 and IPv6.

  • Add a protocol label to all masquerade and invalid packet/byte metrics.
  • Extend NewEgressCollector to accept a list of protocols and instantiate per-protocol metric collectors.
  • Introduce stringToTableFamily helper and update NAT/invalid counter methods to select IPv4 or IPv6 tables.
  • Update the CLI runner to detect local IPs and pass supported protocols; update docs to include protocol column.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
v2/pkg/metrics/egress.go Updated metric definitions, collector logic, helper
v2/cmd/coil-egress/sub/run.go Pass detected protocols to the collector
docs/cmd-coil-egress.md Documented new protocol label
Comments suppressed due to low confidence (3)

v2/pkg/metrics/egress.go:23

  • Typo in metric and variable name: ‘Connctrack’ should be ‘Conntrack’ (e.g. NfConntrackCount) for clarity and consistency.
NfConnctrackCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{

v2/cmd/coil-egress/sub/run.go:40

  • Update registration to match the corrected metric name ‘NfConntrackCount’ after fixing the typo in the variable.
metrics.Registry.MustRegister(egressMetrics.NfConnctrackCount)

v2/pkg/metrics/egress.go:217

  • Add unit tests for stringToTableFamily and the protocol-specific branches in getNfTablesNATCounter/getNfTablesInvalidCounter to verify IPv6 behavior.
func stringToTableFamily(protocol string) (nftables.TableFamily, error) {

@terassyi terassyi requested a review from yokaze June 13, 2025 01:48
@terassyi terassyi force-pushed the support-ipv6-for-egress-metrics branch from 6513c7d to 4e7a01f Compare June 13, 2025 07:08
@terassyi terassyi requested a review from yokaze June 13, 2025 07:38
Signed-off-by: terashima <[email protected]>
@terassyi terassyi force-pushed the support-ipv6-for-egress-metrics branch from 4e7a01f to 8b907cd Compare June 13, 2025 08:14
Copy link
Contributor

@yokaze yokaze left a comment

Choose a reason for hiding this comment

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

LGTM!

@terassyi terassyi merged commit b5a90dc into main Jun 16, 2025
29 checks passed
@terassyi terassyi deleted the support-ipv6-for-egress-metrics branch June 16, 2025 00:38
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.

2 participants