Part 6 · Exercises

Part 6 Exercises

See what you can't see — and lock what must not be open. These exercises drill observability and security skills that separate senior engineers from beginners.

Metrics & Logs

Exercise 6.1

Explain the difference between a Prometheus Counter, a Gauge, and a Histogram. Give one real-world example of what you would measure with each type.

Exercise 6.2

Write a PromQL query that returns the per-second HTTP request rate over the last 5 minutes, broken down by status_code label. Then write a second query that returns the 95th percentile latency from a histogram metric called http_request_duration_seconds.

Exercise 6.3

Write a Prometheus alerting rule YAML that fires an alert named HighErrorRate when more than 5% of HTTP requests return status codes ≥ 500, sustained for 2 minutes. Include a severity: critical label and a human-readable summary annotation.

Exercise 6.4

What is the difference between Loki and the ELK stack (Elasticsearch + Logstash + Kibana)? Describe a scenario where you would prefer one over the other, and explain why.

Exercise 6.5

Write a LogQL query that finds all log lines from a job called api-server that contain the word ERROR and occurred in the last hour. Then extend the query to count the number of such errors per minute as a time-series.

Distributed Tracing

Exercise 6.6

Define the following OpenTelemetry terms in your own words: Trace, Span, TraceId, SpanId, and Parent Span. How do they combine to represent a request's journey across multiple services?

Exercise 6.7

You have a Node.js Express API. Write the minimal code required to auto-instrument it with the OpenTelemetry SDK, exporting traces to an OTel Collector running at http://collector:4317. Your answer should include the packages to install and where the instrumentation code must be placed relative to the rest of your application startup.

Exercise 6.8

What is the W3C traceparent header? Write an example value and decode each part: version, trace ID, parent span ID, and trace flags. Why is propagating this header between services critical for distributed tracing to work?

Exercise 6.9

Write an OpenTelemetry Collector configuration (otel-collector-config.yaml) that: receives traces over gRPC (port 4317), exports traces to Jaeger at http://jaeger:14268/api/traces, and logs all received traces to stdout. Include the receivers, exporters, processors, and service.pipelines sections.

Security & Secrets

Exercise 6.10

List five things that should never appear in a Git repository, even in a private one. For each, explain what the real-world consequence of accidentally committing it would be (e.g. leaked AWS keys, exposed database passwords, etc.).

Exercise 6.11

Write the HashiCorp Vault CLI commands to: (1) enable the KV v2 secrets engine at path secret/, (2) store an API key at secret/data/myapp/api, and (3) read it back and display only the value of the api_key field using jq.

Exercise 6.12

You need to scan a Docker image called myapp:v1.2.0 for vulnerabilities before it can be deployed. Write the trivy command that scans the image, outputs results as a table, and exits with a non-zero status code if any HIGH or CRITICAL severity vulnerabilities are found. Then write a GitHub Actions step that runs this scan and blocks a merge if the check fails.

Exercise 6.13 — Capstone

Design a complete observability and security pipeline for a three-service application (API Gateway → Order Service → Payment Service). Your design must specify: what metrics each service exposes and how Prometheus scrapes them, how logs are shipped to Loki, how distributed traces flow through all three services using OpenTelemetry, where secrets are stored and how each service retrieves them at runtime, and what security scans run in CI before any image is deployed. Write this as a design document with diagrams described in plain text.