cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
684
Views
2
Helpful
3
Replies

From NSO Service lifecycle callback: generate diff / diff so far

atreyulovesyou
Level 1
Level 1

hi,

I am introducing a bunch of telemetry into our NSO repos.  we are python based.  

I've looked, and can't find reasonable examples of what to me seems common:
 - immediately before or after commit (dry run or not, revert or not, <type_one_of_those_ncs.dp.op.types.probably>) I want to capture a data structure I can interpret to see what I'd get as output at the cli.

 - I want this so I can include the EXACT delta in my structured logging, and fire it off to a collector with the rest. the point of this being a drive of the operator / developer to be able to diagnose runtime use of system and generate stats on it etc.

think we want ncs.cdb.diff_iterate()?  but I cannot find a reasonable example of how to implement this - I've seen some things such as a cisco example for 'blast_radius' on github.... but there's nothing showing how I actually say like iterator.get_next().

so if you will, quiz me this:
- i have a service: 'serviceABC', it sets snmp community, and a description.
 ->>> from WITHIN that nso application/service, at which point of the lifecycle is important, immediately after or before a commit, you tell me --->> I need to capture the diff.

- so in 'serviceABC' - two values I'd need a diff iterator to 'see'

 - the changes come at the callbacks in HKeyPaths? other/else?
  those as locations of modification I presume...  I inspect these in my debugging IDE, but there's nothing upon them.  It is not clear to me WHAT I need to do to:
 
---->>> generate a ["config_key": {'before',: 'beforeVal', 'after': 'afterVal'}] kind of thing that matches the return on a commit/commit dry-run

A recent, concise, explained code-with-commentary of the doing of this would probably be useful to a lot of people tracking use of NSO programmatically, and would certainly improve content easily searchable here.

Anyone know?

happy Friday, community!

PS - cisco people, implement opentelemetry instrumentation on your sdks, please.

 

PPS - is it true (it is true by lore at my work) that it is strictly forbidden to modify the ncs SDKs - in that it'll knock you out of a supportable status?

3 Replies 3

jvikman
Cisco Employee
Cisco Employee

Hi,

It sounds like you could use a CDB Subscriber. Take a look at the examples collection and the examples.ncs/getting-started/1-cdb-py. There you have an application that uses the CDB API to see before and after values:

class MyIter(object):
def pre_iterate(self):
return []

def iterate(self, kp, op, oldv, newv, state):
if op is ncs.MOP_VALUE_SET:
state.append(newv)
return ncs.ITER_RECURSE

def post_iterate(self, state):
for item in state:
print(item)

def should_post_iterate(self, state):
return state != []

 

And yes, If you change the NCS SDKs and have a problem using that SDK, you cannot expect support for that.

I hope this helps!

/Johan

atreyulovesyou
Level 1
Level 1

just got hands on the cisco observability exporter stuff.  there's an implementation of iterating diffs in there.

fortuitous!  I'd literally just implemented first party tracing with opentelemetry sdk for python in our projects, so attaching the nso stuff (it sees as far as 'i called your service at a callback') by sharing root trace ID should gimme nice end-to-end.

this stuff should be up on github.  I mean even if you had it in private repos, and invited us if we were verified (I know you like to keep the binaries paid for in a way other than license checking) ---> you'd end up with community source contribution.

stupidly simple example - you don't compile regex in your python implementation.  for me / my team, I'm going to adapt it quite a bit.  It'd be lovely to be able to share back....

...and, relevant here, have the damned iterator pattern clearly shown!  as a community user/person trying to dev against these sdk - I don't know if I'll get in trouble if I post elements to github or whatnot.  

its most confusing, and I end up being passed files from my manager who has more download capabilities than me.  sorta (entirely) defeats the purpose of version control.

anyhow, my 2c, and ty for replying jvikman.

jvikman
Cisco Employee
Cisco Employee

Hi atreyulovesyou,

Great that you got something that works for you!

Regarding contributions, please submit enhancement requests through your support channel. And we very much appreciate contributions to our NSO Developer space on GitLab.

Great input, thanks!

/Johan