Site Reliability Engineering — Best of this Week — 30 April 2023

Vikas Yadav
4 min readApr 30, 2023

--

“Productivity is the deliberate, strategic investment of your time, talent, intelligence, energy, resources, and opportunities in a manner calculated to move you measurably closer to meaningful goals.” — Dan S. Kennedy

I compile Site Reliability Engineering/DevOps-related articles every week and help you keep up your learning game.

This week we covered:

  1. An underrated trick to trace the lifecycle of each request on #Kubernetes!
  2. CORS errors simplified!
  3. How to overcome token size limitation of GPT-3?
  4. Want to do some robust object oriented programming in python?

I also write about the tools and tips related to Software Development and SRE regularly on my Linkedin profile. You can check out my profile here: https://www.linkedin.com/in/vikasyadav94/

An underrated trick to trace the lifecycle of each request on #Kubernetes!

One of the biggest challenges with running microservices is to trace the lifecycle of each request. Let’s make it trivial!

When you are running microservices — a single request spans across multiple microservices. While external monitoring systems like #prometheus will let you capture overall response time, number of invocations, etc they don’t provide any insights into individual operations.

So how do you track the whole lifecycle of every request that comes into your systems? Use Distributed Tracing

-> Assign each external request a unique request id
-> Pass the request id to all services that are involved in handling the request
-> Include the request id in all log messages emitted by every service
-> Record information about requests (e.g. start time, end time, status code) in a centralized service.

Try Jaeger if you haven’t tried it already. It oversimplifies the process of implementing a Distributed tracing system: https://lnkd.in/eMZyTRfp

Find below an architectural diagram of how Jaeger works.

For more such content every day: Follow Vikas Yadav. If you’re preparing for SRE/Devops interviews — you might consider going through my other posts as well.

#sre #devops #kubernetes #tracing #github

CORS errors simplified!

No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Hate this error? Read further. 💡

This is an error that a lot of developers see and almost always fix incorrectly. Let’s understand it further.

First of all, what is CORS?

👉 Cross-Origin Resource Sharing (CORS) is a mechanism that was introduced to prevent javascript code from making calls to a domain other than the one which you have open on your browser.

But wait, why?

👉 Imagine you have logged in to linkedin.com — which sets cookies on your browser. You open a malicious website — xyz.com — a script on this malicious website tries to make a call to linkedin.com — this call will use the cookies stored in your browser’s cookie jar — and linkedin.com might think that you are a legitimate user trying to reach out to Linkedin — isn’t that dangerous? So a bad script can potentially mess up your account if LinkedIn doesn’t implement CORS settings properly.

A beautiful demonstration of how this attack works: https://lnkd.in/eqrey6_Y

How CORS policies work?

👉 An oversimplified explanation: Browser sends a preflight request to your server before sending the actual request. Your server responds to the preflight request with CORS headers. Based on the CORS headers the browser enforces security policies/restrictions.

So next time you see this error — don’t panic. Also, don’t try to fix the error ASAP. Take a deep breath — understand what you’re doing and make sure it’s secure.🙂 Hope this was helpful. Happy coding.

#programming #cors #security #javascript

How to overcome token size limitation of GPT-3

Are you tired of GPT’s limitations when it comes to answering questions about unfamiliar topics? Do you want to learn how you can give a large dataset as a context to GPT3?

There are a bunch of ways to overcome these limitations. One method is to use embedding-based search, which is simple to implement and works especially well with questions. Plus, it doesn’t rely on fine-tuning, which can be unreliable for factual recall.

The full procedure includes preparing search data, collecting and chunking relevant documents, embedding the sections, and then searching, ranking, and asking GPT for the answer. It’s like taking an exam with open notes!

For more details checkout this notebook: https://lnkd.in/eDQXxpHy

Don’t let GPT’s limitations hold you back anymore!

#ai #gpt #openai

Want to do some robust object oriented programming in python?

Want to do some robust object oriented programming in python?

Leverage the charm of Python to write some really beautiful (and efficient) code that your teammates will also love you for.

Here’s a blog I wrote about Pydantic which covers everything that you’ll need to know as a beginner — https://lnkd.in/eHQ4vRxU

Pydantic provides you
👉 Data validation and settings management using python type annotations.
👉 Enforces type hints at runtime, and provides user friendly errors when data is invalid.
👉 Neat intellisense integration with your IDE.

So go ahead and give it a try on your own. If you’re already using it, let me know about your experience with it in the comments section!

For more such interesting content every day — Follow Vikas Yadav

#python #programming #pydantic #opensource

--

--

Vikas Yadav
Vikas Yadav

No responses yet