Files
cozystack/packages
Aleksei Sviridkin d380f2e8fc fix(tenant): ship sub-tenant logs and metrics to the ancestor monitoring (#5257)
## What this PR does

A tenant (and the guest clusters inside it) whose monitoring resolves to
an ancestor runs monitoring agents (Fluent Bit + VMAgent) that write to
the owner tenant's `vlinsert` (logs) and `vminsert` (metrics). The
generated tenant Cilium egress dropped part of this traffic:

- The egress never opened `vlinsert`, so log shipping was always dropped
at the source (fluent-bit `no upstream connections available to
vlinsert-generic.<owner>.svc:9481`).
- For metrics, the egress derived the target by walking the namespace
prefix. The walk reaches an ancestor only when its namespace is a prefix
of the writer's, so it never reaches `tenant-root` from below the first
level. In the common layout where only `tenant-root` has monitoring and
descendants inherit it, a guest two levels deep had its metrics dropped
on egress (a first-level tenant, or an intermediate monitoring owner
that is a prefix, still worked).

This change replaces the prefix walk with a single egress rule that
targets the monitoring owner namespace directly. The owner is the value
already computed in `namespace.yaml` and inherited through
`_namespace.monitoring`, so it resolves to the real owner at any depth
and covers both `vminsert` and `vlinsert` in one rule. The rule is
skipped when the tenant owns its monitoring (writes stay in-namespace)
or when no ancestor owns it.

No ingress policy is added on the owner side: the owner tenant already
accepts the traffic through its `allow-external-communication` rule
(`fromEntities: [world, cluster]`), which matches every pod in the
cluster.

Helm unittests cover the owner-targeted egress one level down, the deep
case targeting `tenant-root`, the self-owned case (the `monitoring:
true` override wins over the inherited owner, no cross-namespace rule),
and the no-owner case (monitoring disabled with the inherited owner
absent or empty, no rule rendered).

Fixes #5256

### Downstream repositories

- [x] No downstream repository is affected by this change

### Release note

```release-note
fix(tenant): sub-tenant monitoring agents now ship logs and metrics to the monitoring owner tenant's VictoriaLogs/VictoriaMetrics at any nesting depth. Previously the generated Cilium egress never opened vlinsert, so logs were always dropped, and it reached vminsert only by walking the namespace prefix, so metrics were dropped when the monitoring owner was tenant-root and the writer sat below the first level.
```


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Updates**
* Tenant monitoring write traffic now targets the configured monitoring
owner’s namespace for `vminsert` and `vlinsert`, including when the
owner is not the tenant’s parent.
* Tenants that own their monitoring, or have no configured monitoring
owner, do not receive a separate cross-namespace monitoring egress rule.
* Network access rules continue to allow required connections to
ancestor namespaces, including etcd and ingress endpoints.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-12-03 17:43:20 +03:00
..