cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
424
Views
0
Helpful
0
Replies

Tales From The Crypt: ODD Chapter 1

npetrele
Cisco Employee
Cisco Employee

Observability-Driven Development (ODD) is the latest buzz phrase. One of the goals of ODD is to integrate observability measures into your code. Here's what could be the world's simplest sample, which makes it possible to identify the very line of code that may be causing performance problems.

When writing Python, measure the time it takes for a REST operation and log it.

import time
import requests

perflog = open("perflog.log","a+")

tic = time.perf_counter()
x = requests.get('https://w3schools.com')
toc = time.perf_counter()

perflog.write("Get https://w3schools.com\n")
perflog.write(f"{toc - tic:0.4f}\n")
perflog.close()

Sample log (time is in seconds):

Get https://w3schools.com
0.8114

The "a+" in the open statement tells the program to append data to an existing file, and create the file if it doesn't exist.

"tic" records the time before the GET operation, and "toc" records the time afterward. Write the operation you're timing to the log, and then write the time it took to perform the operation.

You could add code to check the time and create an alarm if the GET takes too long, or you can simply write it to a log and write a separate log analyzer (live or otherwise) that raises an alarm whenever an operation takes too long.

(Note: I call this "Tales From The Crypt" because the heat has returned in Texas. Last week, the weather was nice so I opened the windows. With the heat back, I closed the window, but something in the garden was reflecting the sun. It was so bright it could strike a Venetian blind. So I closed the drapes again and my home office once again like a crypt.)

0 Replies 0