Don't worry, ASAB and the universe can be fixed

Don't worry, ASAB and the universe can be fixed

🇨🇿 Česká verze je níže / Czech version is below.

I joined the TeskaLabs backend team at the beginning of January. My journey into programming was definitely not a straight path and I was actually only at its very beginning. The tasks I have received so far in TeskaLabs can be characterized primarily by the fact that I had no idea at the beginning what would happen at the end.

"I sent you an issue. It's pretty simple," my boss Aleš told me just the first week. "We want to integrate metrics with Prometheus. It's a time-series database. We just need to add an endpoint in the ASAB." Seeing my puzzled face, Aleš dropped his enthusiastic smile and struggled to find the right words to introduce the whole thing to me. "It's like Influx, but in the other way round...." I felt awkward asking what the metrics were, so I asked about Influx instead.

After half an hour, Aleš sighed "Is it at least a little clear?"

"Not really," I said, " but I'll just start and see."

A friend who listens

Since that first episode, Prometheus and I have often called each other. Well, he calls me and listens only to responses in OpenMetrics format. It's plain text with a strictly defined structure. The OpenMetrics protocol looks strongly similar to citation standards – that's my game, I can handle this.

Soon we were friends. I counted unicorns in ASAB, Prometheus kept asking me every ten seconds how many unicorns I had and plotted the time series. When my unicorns finally stopped disappearing somewhere on their way, that was the time for a pull request.

My first real contribution!

"Jakub," I whined, "Aleš gave me approval to merge this Prometheus, but I'm afraid I'll break ASAB, Github, the universe and everything!"

"Don't worry, at least ASAB and the universe can be fixed quickly," replies Jakub, encouraging as always. "Github was bought by Microsoft, so unfortunately that one probably not.... But seriously, don't be afraid."

Why metrics?

A few days later, I was about to find out why it's a good idea to count unicorns in ASAB. I met SeaCat Auth and Robin. Robin is a dowser in this story, guiding me through the code and showing me where to find the spring for my metrics. Where I saw only a desert, Robin heard the murmur of logins, sessions, and tenants. SeaCat Auth is an app built on ASAB providing access wherever it's needed, e.g., to medical software with patient data. It works with data and events that we want to quantify and track over time - numbers of logins, the number of users logged in, etc. That already sounds pretty important, no?

It took me two days to add five lines of code to make SeaCat Auth count successful and unsuccessful logins. I could track in Prometheus how many of my imaginary users failed to log in per minute. I was almost about to celebrate, but the numbers didn't match.

At least Github and the universe are still okay.

Don't Flush Your Counter

I taught ASAB to translate two types of metrics to Prometheus, Gauge and Counter. While Gauge always gives the current value (how many unicorns I have at any given time), Counter adds and returns the total value (the number of failed SeaCat Auth logins). The glitch occurs exactly once a minute, when all the metrics in ASAB are reset, and they start counting again. In Gauge-type metrics, no big problem arises. However, if Prometheus gets data from a Counter that hasn't reached its maximum yet, it gets completely meaningless numbers.

Fortunately, I'm not the first one who faces this problem. There are several time-series databases and ASAB already communicates with Influx. You can find articles that compare Influx to Prometheus from many angles, but I find crucial their different way of collecting data. Influx with its "push model" simply waits for new data, so it's not so hard to synchronize ASAB sending metrics to Influx when resetting them. However, Prometheus, using the "pull model", can ask for the metrics status anytime. So, I had to make ASAB remember the last Counter values before the "flush" event and send them to Prometheus when it calls.

I naively thought that the point of this story would be a solved case. Metrics uncovered. And me! A genius programmer! The truth is that every iteration opens up new perspectives and challenges. What parameters to use to make the data useful? How about turning off the metrics reset? Gauge or Counter? Or some other type? How to calculate active users? And how to improve readability? I don't know whether this is a satisfying conclusion to this blog post, but these questions spark excitement in me. By seeking the answers, I uncover a fascinating piece of the digital world, and also, hopefully, I create a small part of a meaningful product.

Visit and follow TeskaLabs GitHub here: github.com/TeskaLabs

🇨🇿 Neboj, ASAB a vesmír půjdou spravit

Na začátku ledna jsem nastoupila do backend týmu TeskaLabs. Moje cesta k programování rozhodně nevedla přímo a vlastně jsem sotva vykročila. Úkoly, které dostávám, se vyznačují zejména tím, že na jejich začátku netuším, co bude na konci.

„Poslal jsem ti issue. Je to úplně jednoduchý,“ začal Aleš, můj nový šéf, zlehka. „Chceme integrovat metriky s Prometheem. To je taková time-series databáze. Je jenom potřeba přidat endpoint v ASABu.“ Při pohledu na můj nechápavý výraz padá Alešovi úsměv a s námahou hledá slova, jak mi to celé přiblížit. „Je to jako Influx, ale naopak….“ Je mi trapný zeptat se, co to jsou metriky, tak se ptám, co je Influx.

Po půl hodině si Aleš povzdechne: „Je to aspoň trochu jasný?“

„Ani ne, ale prostě někde začnu.“

Kamarád, co naslouchá

Od té doby si s Prometheem často voláme. Tedy on volá mně a poslouchá jedině odpovědi ve formátu OpenMetrics. Jde o prostý text s přesně definovanou strukturou. Protokol OpenMetrics nápadně připomíná citační normy – jsem doma, to zvládnu.

Brzy jsme kamarádi. Já počítám v ASABu jednorožce, Prometheus se mě každých deset vteřin ptá, kolik jich mám, a zaznamenává časovou řadu. Když se mi konečně přestanou jednorožci ztrácet někde po cestě, je čas na pull request.

Můj první příspěvek do něčeho opravdickýho!

„Jakube,“ nervuju, „Aleš píše, abych toho Promethea mergla. Mám strach, že rozbiju ASAB, Github, vesmír a vůbec!“

„Neboj, minimálně ASAB a vesmír půjdou rychle spravit,“ odpovídá Jakub jako vždy povzbudivě. „Github koupil Microsoft, takže ten asi bohužel ne…. Ale vážně, neboj se toho.“

K čemu metriky?

Proč je dobré počítat jednorožce v ASABu se dozvídám o pár dní později. Poznala jsem SeaCat Auth a Robina. Robin je v tomto příběhu proutkařem, který mě provádí kódem a ukazuje mi, kde najít pramen pro mé metriky. Tam, kde já vidím jen poušť, slyší Robin šumění loginů, sessions a tenantů. SeaCat Auth je appka postavená na ASABu, která zabezpečuje přístup všude, kde je třeba, například ke zdravotnickým softwarům s údaji pacientů. Pracuje s daty a událostmi, jejichž množství chceme vyčíslit a sledovat v čase – počty přihlášení, množství přihlášených uživatelů atd. To už zní docela vážně, ne?

Přidat pět řádků kódu mi zabralo dva dny a SeaCat Auth začal počítat úspěšná a neúspěšná přihlášení do systému. Sledovala jsem v Prometheovi, kolik mých imaginárních uživatelů se nezvládlo přihlásit za minutu. Skoro už jsem začínala slavit, jenže čísla neseděla.

Aspoň Github a vesmír jsou zatím v pohodě.

Nespláchnout si Counter

Naučila jsem ASAB překládat Prometheovi dva typy metrik, Gauge a Counter. Zatímco Gauge vždy udává aktuální hodnotu (kolik mám v daný okamžik jednorožců), Counter přičítá a vrací celkovou hodnotu (počet neúspěšných přihlášení do SeaCat Auth). Průšvih nastává přesně jednou za minutu, kdy dojde k resetu všech metrik v ASABu, a ty začínají počítat nanovo. V metrikách typu Gauge nevzniká velký problém. Nicméně pokud Prometheus získá data z Counteru, který ještě nedosáhl svého maxima, dostane úplně nesmyslná čísla.

Naštěstí nejsem první, kdo se s tímto úkolem potýká. Time-series databází je celá řada a ASAB již umně komunikuje s Influxem. Najdete články, které porovnávají Influx s Prometheem z mnoha úhlů, ale pro mě je zcela zásadní jejich rozdílný způsob sběru dat. Influx se svým „push modelem“ zkrátka čeká, až mu nová data někdo pošle, není tedy těžké synchronizovat v ASABu odesílání metrik do Influxu s jejich resetem. Jenže Prometheus, který využívá „pull model“ se na stav metrik může zeptat kdykoliv. Musela jsem tedy zařídit, aby si ASAB zapamatoval poslední hodnoty Counterů před „spláchnutím“ a poslal je Prometheovi, jakmile si o ně řekne.

Naivně jsem si myslela, že pointou tohoto příběhu bude vyřešený případ. Metriky odhaleny a já – geniální programátorka! Pravdou je, že každá iterace otevírá nové pohledy a výzvy. Jaké parametry použít, aby výsledná data byla přínosná? Co takhle vypnout reset metrik? Je lepší Gauge nebo Counter? Nebo nějaký jiný typ? Jak spočítám, kolik je aktivních uživatelů? A jak metriky nejlépe popisovat a třídit, aby byly dobře čitelné? Nevím, nakolik uspokojivý je to závěr tohoto blogu, ve mně ale tyto otázky vyvolávají nadšení. Vím totiž, že hledáním odpovědí odkrývám fascinující kus digitálního světa a také tvořím malý dílek do smysluplného produktu.

Navštivte a sledujte TekskaLabs Github: github.com/TeskaLabs

About the Author

Eliška Novotná

Junior backend developer at TeskaLabs. Python and unicorns lover.




You Might Be Interested in Reading These Articles

SeaCat Mobile Secure Gateway Architecture

SeaCat Mobile Secure Gateway is built using the SeaCat Application Security Platform. It provides strong protection against multiple types of cyberattacks by securing all application components, including the mobile application, network paths, which present an entry point to the enterprise network and application’s backend servers. It reduces an administrator's workload with easy PKI administration of distributed large-scale mobile applications. SeaCat Security Platform has been carefully designed to be flexible, fast, and highly secure.

Continue reading ...

tech

Published on May 18, 2014

Binary distributions of OpenSSL static libraries

The official source of OpenSSL software is the OpenSSL website. One can download OpenSSL source codes archives and compile them for a given platform. The compilation work can sometimes be quite tedious, especially for exotic platforms. We, at TeskaLabs, set up this page because we frequently compile OpenSSL for various platforms for our internal purposes and this may save some time to other developers.

Continue reading ...

development android windows ios security

Published on July 20, 2017

Is There A Network Protocol for Your Mobile Apps That Offers A Higher Security Level While Consuming Less Bandwidth Than HTTPS? Yes, There Is

For mobile apps or websites that don’t have logins, forms or features to extract data, you don’t need secure access. For banking websites, mobile apps and mobile banking services, without a doubt, secure communication is a must. But nothing is ever black and white.

Continue reading ...

tech security

Published on September 13, 2016