Skip to content

feat(netconf-proto): add global YANG module cache - #22

Open
riccardo-negri wants to merge 1 commit into
network-analytics:mainfrom
riccardo-negri:add-yang-modules-cache
Open

feat(netconf-proto): add global YANG module cache#22
riccardo-negri wants to merge 1 commit into
network-analytics:mainfrom
riccardo-negri:add-yang-modules-cache

Conversation

@riccardo-negri

Copy link
Copy Markdown
Member

Add YangModuleCache, a thread-safe cache of raw module texts shared by all SSH sessions so get_yang_module skips redundant get-schema RPCs for a given (name, revision). Only versioned modules are cached; values are stored as Arc<str> for cheap hits. Exposes hit/miss/size counters via OTel, and renames YangSchemaFormat -> GetSchemaFormat per RFC 6022.

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.

Pull request overview

Introduces a globally shared, thread-safe YANG module text cache in netconf-proto and wires it through the NETCONF SSH client and YANG push caching pipeline so repeated (module name, revision) fetches can avoid redundant get-schema RPCs. Also renames the NETCONF monitoring “format” enum to align terminology with RFC 6022.

Changes:

  • Added YangModuleCache (shared across SSH sessions) and integrated it into NetConfSshClient::get_yang_module.
  • Plumbed the shared cache through the collector → yang-push cache actor/fetcher and exposed cache hit/miss/size metrics via OTel callbacks.
  • Renamed YangSchemaFormat to GetSchemaFormat in the NETCONF protocol layer.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/yang-push/src/cache/fetcher.rs Injects a shared YangModuleCache into per-session NETCONF connect configs.
crates/yang-push/src/cache/actor.rs Registers OTel observable instruments that read YangModuleCache atomic stats.
crates/netconf-proto/src/yang_module_cache.rs Adds the new global cache implementation + unit tests and exposed stats.
crates/netconf-proto/src/protocol.rs Renames schema format enum to GetSchemaFormat and updates (de)serialization.
crates/netconf-proto/src/lib.rs Exposes the new yang_module_cache module publicly.
crates/netconf-proto/src/client.rs Adds module cache plumbing to connect/client and implements cached get_yang_module.
crates/collector/src/lib.rs Creates a single shared cache instance and passes it into the yang-push cache actor/fetcher.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread crates/netconf-proto/src/yang_module_cache.rs
Comment thread crates/yang-push/src/cache/actor.rs Outdated
Comment thread crates/netconf-proto/src/client.rs
@riccardo-negri
riccardo-negri force-pushed the add-yang-modules-cache branch from 6db86e4 to 0941ce2 Compare August 3, 2026 09:28
Add `YangModuleCache`, a thread-safe cache of raw module texts shared by
all SSH sessions so `get_yang_module` skips redundant `get-schema` RPCs
for a given `(name, revision)`. Only versioned modules are cached; values
are stored as `Arc<str>` for cheap hits. Exposes hit/miss/size counters
via OTel, and renames `YangSchemaFormat` -> `GetSchemaFormat` per RFC 6022.
@riccardo-negri
riccardo-negri force-pushed the add-yang-modules-cache branch from 0941ce2 to 38bad9c Compare August 3, 2026 11:41
}

fn make_key(name: &str, revision: &str) -> String {
format!("{name}@{revision}")

@ustorbeck ustorbeck Aug 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.

why concatenating the strings to create the key?
better use them in a tuple instead, that's more robust:

type ModuleCacheKey = (String, String);
fn make_key(name: &str, revision: &str) -> ModuleCacheKey {
    (name.to_owned(), revision.to_owned())
}

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.

3 participants