newrelic / newrelic/newrelic-python-agent

Error in K8S ipv6 addresses validation `CommonUtilization.valid_chars()` / `VALID_CHARS_RE`

Open
#1,001 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Python
Stars
210
Forks
137
Avg merge
4d 19h
Merged PRs (30d)
12

Description

Description
When running in K8S with ipv6 addresses, client fails with error like Invalid "kubernetes" data ("kubernetes_service_host"): "fd95:b6e3:daad::1"

Expected Behavior
Agent should accept ipv6 addresses

Troubleshooting or NR Diag results
After looking at code and at environment, I found that K8S injects the following variables:

...
KUBERNETES_SERVICE_HOST=fd95:b6e3:daad::1
KUBERNETES_PORT_443_TCP_PORT=443
KUBERNETES_PORT_443_TCP_ADDR=fd95:b6e3:daad::1
...

The error happens in KubernetesUtilization class in detection process:
Detection https://github.com/newrelic/newrelic-python-agent/blob/main/newrelic/common/utilization.py#L153-L157 consist of fetching the data (reading envvar KUBERNETES_SERVICE_HOST) then validating it for correctness, one of the steps https://github.com/newrelic/newrelic-python-agent/blob/main/newrelic/common/utilization.py#L127 is checking valid chars https://github.com/newrelic/newrelic-python-agent/blob/main/newrelic/common/utilization.py#L27 , the agent does not expect : and fails

Steps to Reproduce
Run in K8S with ipv6

Your Environment
EKS with ipv6

Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in newrelic/common/utilization.py at VALID_CHARS_RE (line 27), valid_chars() (line 127), and KubernetesUtilization detection (lines 153-157). Reproduce with KUBERNETES_SERVICE_HOST set to fd95:b6e3:daad::1 and verify that IPv6 Kubernetes addresses are accepted while existing validation remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
kubernetes, python
Domain
infrastructure, observability-sre
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.