Categories
Uncategorised

List of dicts to table with PrettyTable

Given:

summaryList = [{"Event Name": "Pod_Service_MTTR_Notify", "Count": 1}, {"Event Name": "Pod_Service_No_2_alert", "Count": 20}]
if summaryList:
    summaryTable = PrettyTable(summaryList[0])
    for i in summaryList:
        summaryTable.add_row(i.values())
Categories
Uncategorised

Rate Limiter / Cool Down timer in python3 and redis

My main source of data… jira service desk… cannot be trusted. Oh yes, 90% of the time it acts sane, but once in a while, someone misconfigures a big panda alert and we get 1000 new incidents in moments.

My colleague got flooded with pager duties and emails one Saturday, and I’m sure it made him cry. I need to rate limit these actions.

My plan is to use incr function to increment a redis key. The idea is that you create a new key every x seconds, with an expiry (equal to x) and then when you increment redis will respond with the current value, so you can just test the if loop.

First things first. I know how to do something every second int(time)) but every 10 minutes?

from time import time, sleep
while True:
     everyXSeconds = 10
     curTime = int(time())
     key = curTime - curTime % everyXSeconds
     print(key)
     sleep(1)

I’m only calling time() once because calling time() twice in the mod actually give different nanosecond values… and I just know I am going to hit some corner case where that crosses a second boundary and messes up EVERYTHING

BUT… the above is actually crap and not needed at all. That is a crap way to rate limit cause, for example, if I am trying to stop an email flood it will still send 10 emails every X seconds. As in, the count will be reset every X seconds.

To me the following makes a bit more sense:

while True:
    curTime = time()
    print(f"curTime is {curTime}")
    everyXSeconds = 10
    rateBeginTime = curTime - everyXSeconds
    count = red.zcount(queueName, rateBeginTime, curTime)
    print(f"current hit queue is :{count}")
    limitMap = {curTime: curTime}
    red.zadd(queueName, limitMap)
    sleep(1)
    remove = red.zremrangebyscore(queueName, 0, rateBeginTime)
    print(f"removed {remove} keys")

So thats just what I used to test…. but basically you are using a sorted list and adding and removing as needed

Categories
Uncategorised

Cryptomnicon (spoiler warning)

It has been a long time since I felt the need to write about a book I read.

Particular items of note:

Ityme A: There are some very funny bits in it. I got a good chuckle from some bits of it. It was a bit more funny than termination shock.

Ityme B: It doesn’t shy away from sex. It is still a bit awkward (as anything from an American/ British writer is going to be really) but better than most writers of this ilk.

Ityme C: I liked the Andrew Lobe bit at the end. I actually forgot he was the lawyer until I google him afterwards… A passionate Lawyer indeed. Yes some of the criticism of the character could be valid but when taken as part of the book as a whole I think it fits in nicely in it’s current treatment.

Ityme D: I read numerous reviews before hand saying the first half of the book didn’t have a plot. It clearly does, it’s just temporally non-contiguous .

Ityme E: It is a good book. I also enjoyed Termination shock without realising it was the same author. I stopped “reading” (listening) to the vagabond one but now I have more of a sense of Stephensons style I will go back to it as I find it enjoyable.

Ityme F: The books do not come to an abrupt stop; to quote one person ,”It is as if the publisher called him and said “ok finish up, we need the manuscript tomorrow”. The story has a lovely natural ending, and I found it most satisfactory (I imagine it is hard to end an epic)

Ityme G: I want some of the websites and servers mentioned in the book to still work!

Categories
Uncategorised

XXX and other such texts.

A Marlon Brando of a whale shat on me today.