Observability with Elastic APM and Flask

In out last article here , we explained how to send Docker and application logs to ELK. Now is the time to add some observability to our app using Elastic APM. Configure Elastic APM First, we add Elastic APM to our Docker Compose file from last time, using the same version as Elastic Search. apm-server: image: docker.elastic.co/apm/apm-server:7.17.24 container_name: apm-server user: apm-server ports: - "8200:8200" volumes: - ./apm-server.docker.yml:/usr/share/apm-server/apm-server.yml:ro command: > --strict.perms=false -e -E output....

December 23, 2024 · 1 min · Alex Popescu

AWS Lambda and CORS preflight response

Are you struggling with a frontend application that wants to use a backend AWS Lambda API ? Do you have the next CORS problem: Request header field content-type is not allowed by Access-Control-Allow-Headers in preflight response The solution is simple: implement HTTP OPTIONS method respond with the next access control headers : Access-Control-Allow-Origin, Access-Control-Allow-Headers, Access-Control-Allow-Methods For example in python you can do something like this: def return_200(): return { 'statusCode': 200, 'headers': { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,HEAD,OPTIONS,POST,PUT', 'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization', 'Content-Type': 'application/json' }, 'body': json....

December 9, 2024 · 1 min · Alex Popescu

Developing a Sample TODO API with Couchbase in Docker

Have you ever wanted to run Couchbase on Docker to freely build and test your app? Here’s a simple guide to help you set up Couchbase in Docker and build a sample TODO app using Python and FastAPI. Developer Cluster Setup First, let’s create a minimal docker-compose.yml file to spin up Couchbase: services: couchbase: image: couchbase:latest container_name: couchbase ports: - "8091:8091" # Couchbase Web Console - "8092:8092" # Query Service - "8093:8093" # Full Text Search - "11210:11210" # Data Service environment: COUCHBASE_ADMINISTRATOR_USERNAME: admin COUCHBASE_ADMINISTRATOR_PASSWORD: password volumes: - couchbase_data:/opt/couchbase/var - ....

October 27, 2024 · 5 min · Alex Popescu

Almost Wrong Way To Send Docker Containers logs To ELK

In this article, we’ll walk through setting up a Docker-based ELK (Elasticsearch, Logstash, and Kibana) stack to collect, view, and send Docker logs. services: elasticsearch: image: elasticsearch:7.17.24 environment: - discovery.type=single-node volumes: - ./elasticsearch_data/:/usr/share/elasticsearch/data mem_limit: "1g" redis-cache: image: redis:7.4.0 logstash-agent: image: logstash:7.17.24 volumes: - ./logstash-agent:/etc/logstash command: logstash -f /etc/logstash/logstash.conf depends_on: - elasticsearch ports: - 12201:12201/udp logstash-central: image: logstash:7.17.24 volumes: - ./logstash-central:/etc/logstash command: logstash -f /etc/logstash/logstash.conf depends_on: - elasticsearch kibana: image: kibana:7.17.24 ports: - 5601:5601 environment: - ELASTICSEARCH_HOSTS=http://elasticsearch:9200 depends_on: - elasticsearch ElasticSearch Just create a folder named elasticsearch_data for storing data....

October 16, 2024 · 3 min · Alex Popescu

Linux Login Update Notifier Script With Python

Introduction Do you ever want to get a notification with the number of updates required when logging into XFCE in debian/ubuntu like systems ? There is a simple python script that can do just that. It uses notify-send command and paired with the magic command that returns the update count, we get the next python script: #!/usr/bin/env python3 import os import subprocess # Run the apt-get command and grep the output command = 'apt-get --simulate upgrade | grep "upgraded....

August 29, 2024 · 2 min · Alex Popescu