canonical / canonical/haproxy-operator

HAProxy spams logs with pydantic validation error

Open
#379 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Python
Stars
4
Forks
12
Avg merge
1d 8h
Merged PRs (30d)
22

Description

### Bug Description

Again using the new MAAS spike from https://github.com/canonical/maas-charms/pull/571

Adding the HAProxy relation spams the debug log with pydantic validation errors on the port, before the relation has fully spun up and provided data, even though the port is provided in the MAAS charm at all staged of the relation.

I suspect HAProxy is too enthusiastic, and trying to configure before everything is ready.

### Impact

Low (minor issue or cosmetic problem)

### Impact Rationale

_No response_

### To Reproduce

deploy both charms such that the relation exists
`juju deploy haproxy --channel=2.8/edge`
`juju deploy maas-region --channel=latest/edge/haproxy-relation`

Integrate both relations with haproxy
`juju integrate maas-region:ingress-tcp haproxy:haproxy-route-tcp`

Watch the logs as the charm relation is added and data transferred.

### Environment

Environment deployed according to https://github.com/canonical/maas-terraform-modules

(Local juju, 3.6.3, with lxd vms, MAAS and HAProxy on the deployed channels as in the reproducer steps)

### Relevant log output

```shell
unit-haproxy-0: 14:50:35 ERROR unit.haproxy/0.juju-log haproxy-route-tcp:8: 1 validation error for TcpRequirerApplicationData
port
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
Traceback (most recent call last):
File "/var/lib/juju/agents/unit-haproxy-0/charm/lib/charms/haproxy/v1/haproxy_route_tcp.py", line 297, in load
return cls.model_validate_json(json.dumps(data))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/var/lib/juju/agents/unit-haproxy-0/charm/venv/lib/python3.12/site-packages/pydantic/main.py", line 766, in model_validate_json
return cls.__pydantic_validator__.validate_json(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for TcpRequirerApplicationData
port
Field required [type=missing, input_value={}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.12/v/missing
unit-haproxy-0: 14:50:35 ERROR unit.haproxy/0.juju-log haproxy-route-tcp:8: Invalid requirer application data for maas-region
```

### Additional context

MAAS defines the route as:
```python
self.haproxy_non_tls_route = HaproxyRouteTcpRequirer(
self,
HAPROXY_NON_TLS,
port=80,
backend_port=MAAS_HTTP_PORT,
**COMMON_DEFAULT_HAPROXY_ARGS,
)
````

and uses it with:
```python
self.haproxy_non_tls_route.provide_haproxy_route_tcp_requirements(
port=80, hosts=self.maas_ips, **COMMON_DEFAULT_HAPROXY_ARGS
)
```

At no point on the MAAS side is the port not provided.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.