Skip to content

Feat/yang push cache controller api - #125

Open
mboetschi wants to merge 2 commits into
network-analytics:mainfrom
mboetschi:feat/yang-push-cache-controller-api
Open

mboetschi wants to merge 2 commits into
network-analytics:mainfrom
mboetschi:feat/yang-push-cache-controller-api

Conversation

@mboetschi

@mboetschi mboetschi commented Nov 17, 2026 •

Copy link
Copy Markdown

Adds an optional HTTPS admin API to inspect and clear the YANG-Push validation cache.

It configures:

  • GET /v1/health: Returns 200 OK when the API is reachable.
  • GET /v1/yang-push/validation/cache[/{peer_ip}]: Returns the cache content of all or the specified peer
  • DELETE /v1/yang-push/validation/cache[/{peer_ip}]: Clears the cache content of the all or the specified peer. Peers with a schema fetch in progress are skipped when clearing all, while requesting to clear a specific peer with a pending fetch returns a conflict.

Requests must inclued an Authorization: Bearer header. The listen address, TLS cert/key
and token are set in the configs under admin_api. The token must be non-empty.

For authenticated requests to the YANG-Push cache endpoints, the API reports the following metrics:

  • #requests
  • #replies
  • #server errors
  • #client errors
  • request duration

@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch from 2274d73 to cc489c1 Compare November 17, 2026 10:43
@rodonile
rodonile requested a lite review from Copilot November 17, 2026 21:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Active critical and moderate findings leave authentication, startup failure handling, multi-actor cache coverage, and cache-clearing behavior unresolved.

5 open issues
What changed in this PR

Adds an optional HTTPS controller API for inspecting and clearing the YANG-Push validation cache, with bearer-token authentication, TLS configuration, and OpenTelemetry metrics.

Changes:

  • Adds serializable cache snapshots and actor commands for retrieving or clearing cache entries.
  • Introduces authenticated GET and DELETE endpoints for all-peer and peer-specific cache operations.
  • Adds controller configuration, lifecycle integration, metrics, and required dependencies.
File Description
crates/​yang-push/​src/​validation/​state.rs Defines serializable validation-cache snapshot types.
crates/​yang-push/​src/​validation/​processing.rs Exposes peer-cache gauge recording for cache operations.
crates/​yang-push/​src/​validation/​mod.rs Re-exports validation-cache snapshot types.
crates/​yang-push/​src/​validation/​actor.rs Adds actor commands and handle methods to inspect and clear cache data.
crates/​collector/​src/​lib.rs Integrates the optional controller with UDP-Notif collection startup and shutdown.
crates/​collector/​src/​controller.rs Implements HTTPS routes, authorization, error handling, and request metrics.
crates/​collector/​src/​config.rs Adds optional controller, TLS, and token configuration.
crates/​collector/​Cargo.toml Adds dependencies required by the controller and authentication.
Cargo.toml Declares workspace versions for the new dependencies.
Cargo.lock Records the resolved versions and checksums for the dependency graph.

Review effort: Lite

Comment thread crates/collector/src/config.rs Resolved
Comment thread crates/collector/src/controller.rs Resolved
Comment thread crates/collector/src/controller.rs Resolved
Comment thread crates/collector/src/lib.rs Resolved
@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch 2 times, most recently from b9be538 to f57c278 Compare November 23, 2026 16:01
@mboetschi
mboetschi marked this pull request as ready for review November 23, 2026 16:19

@mxyns mxyns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

could be nice if you could add a .md doc explaining the architecture of the admin controllers to understand directly what's happening

seems like you were preparing to support multiple handles, not sure if it is out of scope for this PR and will be part of a future PR?

sorry for being annoying but it's easier for me to read when you have some newlines in between ifs, before function returns, in between enum variant definitions when there is derive macros, etc.
some of this is inherited from previous code (type hint, ValidationActorError, etc.) though and not on you 🙂

i don't know why cargo fmt doesn't have code breathability options 🙁

Comment thread crates/collector/src/admin_api/mod.rs Resolved
Comment thread crates/collector/src/admin_api/mod.rs Resolved
Comment thread crates/collector/src/config.rs Resolved
Comment thread crates/collector/src/lib.rs Resolved
Comment thread crates/collector/src/main.rs Resolved
@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch from f57c278 to eefa260 Compare November 24, 2026 16:30
@mboetschi
mboetschi requested a lite review from Copilot November 24, 2026 16:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread crates/collector/src/admin_api.rs Resolved
Comment thread crates/collector/src/config.rs Resolved
Comment thread crates/collector/src/lib.rs Resolved
@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch from eefa260 to 102f6c4 Compare November 25, 2026 17:10
Comment thread crates/collector/src/main.rs Resolved
Comment thread crates/collector/src/admin_api.rs Resolved
Comment thread crates/collector/src/admin_api.rs Resolved
Comment thread crates/collector/src/config.rs Resolved
@riccardo-negri

Copy link
Copy Markdown
Member

We tested in lab the admin_api and everything works as expected.

@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch 2 times, most recently from 2b24fef to 3628f8b Compare November 30, 2026 13:34

@mxyns mxyns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

apart from the /health endpoint all is good for me. i'll accept after this is resolved 🙂

Comment thread crates/collector/src/admin_api.rs Resolved
@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch from 3628f8b to d28684a Compare December 3, 2026 08:32
@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch 2 times, most recently from 74e527b to 04a50e1 Compare December 3, 2026 08:47

@mxyns mxyns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry I lied (not on purpose)
This one is the actual last one

Comment thread crates/collector/src/admin_api.rs Resolved
riccardo-negri
riccardo-negri previously approved these changes Dec 3, 2026

@riccardo-negri riccardo-negri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice design overall, cool use of axum middleware

Comment thread crates/collector/src/admin_api/mod.rs Resolved
@mxyns

mxyns commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

(Just edited the PR description)

@rodonile rodonile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Even though we for now only have specific yang-push commands, might still be worth to already clean up the structure a bit, e.g.

crates/collector/src/
  admin_api/
    mod.rs        serve(), router(), middleware, AdminApiState, AdminApiError,..
    yang_push.rs  ValidationActors extractor, handlers, per-actor response types

then in the future we can just add other modules

And even some registry module with actor identification (see comment for lib)

Comment on lines +220 to +246
Some(ValidationActorCommand::GetYangPushCache(peer_ip, resp_tx)) => {
if resp_tx.is_closed() {
warn!("Skipping YANG-Push cache request, requester left");
continue;
}
None => {
let msg = "YANG-Push validation actor terminated due to command channel closing";
warn!(msg);
Ok(msg.to_string())

debug!("Received request to get YANG-Push cache");

let snapshot = self.validator.cache_snapshot(peer_ip).map_err(Into::into);
if resp_tx.send(snapshot).is_err() {
warn!("Failed to send YANG-Push cache snapshot to requester");
}
}
}

Some(ValidationActorCommand::ClearYangPushCache(peer_ip, resp_tx)) => {
if resp_tx.is_closed() {
warn!("Skipping YANG-Push cache clear request, requester left");
continue;
}

debug!("Received request to clear YANG-Push cache");

let clear_result = self.validator.clear_cache(peer_ip).map_err(Into::into);
if resp_tx.send(clear_result).is_err() {
warn!("Failed to send cleared YANG-Push cache peers to requester");
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

General remark here for biased tokio select. Commands here block messages on the fast path. We need to pay attention that they should not take to much time. E.g. when lots of routers with lots of subscriptions are in the cache this might be problematic.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree we should keep that in mind. Do you have an estimate of how many peers and subscriptions we expect there to be in the cache in prod? It could be interesting to do some measurements with nl6 to see how long it takes with more peers.

@rodonile rodonile Dec 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we have 20-30 subscriptions per router on avg I would say. What will matter is the number of peers that we will able to handle per shard (i.e. by one single actor), I would say 1-2k peers per shard would be probably a good initial start to have an idea. Easier for you to do a benchmark would probably be artificially populating YangPushCacheSnapshot and then checking how much time snapshot_all takes.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I’ve tested it quickly locally by artificially populating the peer cache. For 2k peers with 30 subscriptions each, it took around 45 ms to create the snapshot in the actor.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perfect then that's fine as is

Comment on lines +790 to +802

if validation_handles.len() > 1 {
warn!(
count = validation_handles.len(),
"Multiple validation handles exist; only the first is exposed through the Admin API"
);
}

udp_notif_handles
.validation
.set(validation_handles.first().cloned())
.map_err(|_| anyhow::anyhow!("Admin API validation handle was already initialized"))?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Already today nothing prevents someone to configure multiple groups or endpoints (even though we don't do it), and every time we would randomly get one of those handles (since those are hashmaps). With sharding then (assuming we implement it the same way as we did for flow), each endpoint would get n validation actors, and this api would only query one.

It might already make sense to flood instead of sending to one and to register handles with id, e.g.

pub struct ActorId { pub group: String, pub endpoint: String, pub shard: Option<usize>}

then when we flood the request we would know who answered.

Ok for me if you want to tackle in a next PR where more commands are being added.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I’ve split the admin API into mod.rs and yang_push.rs. I would prefer to add multi-actor handling (actor IDs, the extractor, and per-actor responses) in a later PR when I add flow template commands. Or what do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Makes sense to me

@mboetschi
mboetschi force-pushed the feat/yang-push-cache-controller-api branch from c86b095 to d39bbf8 Compare December 4, 2026 13:44
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.

5 participants