Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

2021-11-16 SeaJUG - Observability

2021-11-16 SeaJUG - Observability

Jonatan Ivanov

May 02, 2022
Tweet

More Decks by Jonatan Ivanov

Other Decks in Programming

Transcript

  1. Agenda - What is Observability? - Why do we need

    Observability? - “The Three Pillars” (with examples) - Logging - Metrics - Distributed Tracing - “Non-conventional” Observability - Demo
  2. “In control theory, observability is a measure of how well

    internal states of a system can be inferred from knowledge of its external outputs.” … “A system is said to be observable if [...] the current state can be estimated using only the information from outputs.” What is Observability? (Wikipedia) Rudolf Kálmán
  3. How well we can understand the internals of a system

    based on its outputs What is Observability?
  4. What is Observability (Software)? Being able to ask arbitrary questions

    without knowing ahead what do you want to ask Turning data points and context into insights Being able to quickly troubleshoot problems with no prior knowledge (known or unknown unknowns) Increasing operational visibility, developer productivity
  5. Why do we need Observability? Because today's systems are insanely

    complex (Death Star Architecture, Big Ball of Mud)
  6. Why do we need Observability? We cannot predict what is

    going to happen We need to face unknown unknowns We are in the Cloud (size + complexity) - LAMP stack vs. Cloud Environments - We might not know where our app is or how many instances we have - We can’t modify/debug/etc. it Something is always broken (Fallacies of Distributed Computing) It is like sending rovers to Mars: You can’t touch/modify them after launch
  7. "The Three Pillars” Logging, Metrics, and Distributed Tracing Observability !=

    Logging + Metrics + Distributed Tracing Do they give you meaningful information about what is going on inside? Do they make your systems more Observable? There are other answers: Eventing, Signaling/Simulation Also: Visualization/Dashboards/Alerting Other “non-conventional” components (later)
  8. Logging - Metrics - Distributed Tracing Logging: “What happened?” Emitting

    events; easy to manually read (grep) Metrics: “What is the context?” (“Is it bad?”) Measuring and combining the data; aggregatable, can identify trends Distributed Tracing: “Why happened?” Recording events with causal ordering; can identify cause across services
  9. Example: Latency Logging: “What happened?” - We found an event

    triggered by an HTTP request in the logs - It says that processing this request took 140ms (access logs)
  10. Example: Latency Metrics: “What is the context?” (“Is it bad?”)

    - What are the trends? - Is 140ms slow? - How fast were the others around this time? What is the max? - Distribution (Between 9:00 and 9:30): - < 90ms -> 12.5% (great) - 90-110ms -> 68.2% (good) - 110-130ms -> 13.6% (fine) - 130-150ms -> 5.5% (slow) - > 150ms -> 0.2% (bad)
  11. Example: Latency Distributed Tracing: “Why happened?” Overall: 140ms Sending request

    to Service A: 5ms Service A processing the request: 130ms (100 + 30) Sending request to Service B: 10ms Service B processing the request: 100ms Receiving response from Service B: 20ms Receiving response from Service A: 5ms
  12. Example: Errors Logging: “What happened?” - You found an event

    triggered by an HTTP request in your logs - It says that processing this request failed: 500 Internal Server Error
  13. Example: Errors Metrics: “What is the context?” (“Is it bad?”)

    - What are the trends? - How many errors do we have around this time? - Error rate (errors/sec) (Between 9:00 and 9:30): - 9:00 - 9:05 -> 0 errors/sec - 9:05 - 9:10 -> 0 errors/sec - 9:10 - 9:15 -> 0 errors/sec - 9:15 - 9:20 -> 2 errors/sec - 9:20 - 9:25 -> 0 errors/sec - 9:25 - 9:30 -> 0 errors/sec
  14. Example: Errors Distributed Tracing: “Why happened?” Overall: FAILED Sending request

    to Service A: OK Service A processing the request: FAILED Sending request to Service B: FAILED (Request Timed Out) Service B processing the request Receiving response from Service B Receiving response from Service A: OK
  15. Logging 101 - Terminology Logger: Named objects you can use

    to emit log events - Name: hierarchical (com.foo.Bar -> com.foo -> com -> root) - Level: inherited if not specified (TRACE DEBUG INFO WARN ERROR) - Appenders - Additivity: should all the appenders of all the ancestors also receive it? Appender: Writes log events to a destination (console, file, socket, DB, etc.) Layout (Pattern): Responsible for formatting the log event (belongs to an appender)
  16. Logging 101 - Types of logs Application logs: classic DEBUG/INFO/WARN/ERROR

    events (+stack traces) Payload logs: Raw request and response pairs GC logs: GC events (JEP 271: Unified GC Logging) Access logs: Logs from the underlying HTTP server - Who and when called our service - What request (HTTP method, headers, path, query) - Response status, processing time, payload sizes etc. (metrics, trace log)
  17. Logging 101 - Application Logs (SLF4J) // Lombok: @Slf4j Logger

    LOGGER = LoggerFactory.getLogger(Car.class); LOGGER.warn("Low battery level."); LOGGER.debug("Starting search for charging stations..."); LOGGER.trace("Sending search request..."); LOGGER.trace("Receiving search response..."); LOGGER.info("Located nearest charging station."); LOGGER.debug("Exiting gas station search."); LOGGER.error("Oh no...", exception);
  18. Logging 101 - Access Logs (Tomcat) 2021-11-07 22:34:36.663 method="GET" url="/tea/sencha"

    query="?size=xxxl" protocol="HTTP/1.1" statusCode="500" duration="46" remoteIp="0:0:0:0:0:0:0:1" localIp="192.168.0.100" localPort="8090" userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36"
  19. Logging 101 - Payload Logs "origin" : "local", "type" :

    "request", "correlation" : "93f7e21e34e0564c", "protocol" : "HTTP/1.1", "remote" : "localhost", "method" : "GET", "uri" : "http://localhost:8091/waters/search/findBySize?size=xxxl", "host" : "localhost", "path" : "/waters/search/findBySize", "scheme" : "http", "port" : "8091", "headers" : { "accept" : [ "*/*" ], "accept-encoding" : [ "gzip" ], "connection" : [ "Keep-Alive" ], "host" : [ "localhost:8091" ], "user-agent" : [ "okhttp/4.9.1" ] }
  20. Logging 101 - Payload Logs "origin" : "remote", "type" :

    "response", "correlation" : "93f7e21e34e0564c", "duration" : 17, "protocol" : "HTTP/1.1", "status" : 404, "headers" : { "connection" : [ "keep-alive" ], "content-type" : [ "application/json" ], "date" : [ "Sun, 07 Nov 2021 22:34:36 GMT" ], "keep-alive" : [ "timeout=60" ], "transfer-encoding" : [ "chunked" ] }, "body" : { "status":404, "error":"Not Found", "path":"/waters/search/findBySize" }
  21. Logging 101 - GC Logs [14:34:04.688][0.384s][start ] Pause Young (Normal)

    (G1 Evacuation Pause) [14:34:04.688][0.384s][task ] Using 6 workers of 13 for evacuation [14:34:04.692][0.388s][phases] Pre Evacuate Collection Set: 0.1ms [14:34:04.692][0.388s][phases] Merge Heap Roots: 0.0ms [14:34:04.692][0.388s][phases] Evacuate Collection Set: 3.1ms [14:34:04.692][0.388s][phases] Post Evacuate Collection Set: 0.4ms [14:34:04.692][0.388s][phases] Other: 0.6ms [14:34:04.692][0.388s][heap ] Eden regions: 23->0(26) [14:34:04.692][0.388s][heap ] Survivor regions: 0->3(3) [14:34:04.692][0.388s][heap ] Old regions: 0->5 [14:34:04.692][0.388s][heap ] Archive regions: 2->2 [14:34:04.692][0.388s][heap ] Humongous regions: 2->1 [14:34:04.692][0.388s][metasp] Metaspace: 2692K(2816K)->2692K(2816K) NonClass: 2369K(2432K)->2369K(2432K) Class: 322K(384K)->322K(384K) [14:34:04.692][0.388s][gc ] Pause Young (Normal) (G1 Evacuation Pause) 25M->9M(256M) 4.701ms [14:34:04.692][0.388s][cpu ] User=0.01s Sys=0.01s Real=0.01s
  22. SLF4J with Logback comes pre-configured but you can change the

    logging lib. SLF4J - Simple Logging Facade for Java (SLF4J) - Simple API (facade/abstraction) for various logging frameworks - Allows to plug in the desired logging framework Logback - Modern logging framework - Natively implements the SLF4J API Logging with Spring Boot
  23. Logging with Spring Boot If you want Log4j2 instead of

    Logback: exclude: spring-boot-starter-logging include: spring-boot-starter-log4j2 Payload logs: logbook-spring-boot-starter (auto-configured) Access logs: logback-access (need to configure a LogbackValve) GC logs: JVM args
  24. Metrics 101 Time series data (changes over time) Trends, context,

    anomaly detection, visualization, alerting Backends Publishing: Client Pushes vs. Server Polls Dimensionality: Dimensional vs. Hierarchical
  25. Metrics 101 - Counter Counter: How frequent is this event?

    - Report a single metric: a count - Increments, must be positive - Monotonically increasing - E.g.: queue; how many items were inserted/removed?
  26. Metrics 101 - Gauge Gauge: Current value of something (increment/decrement)

    - Asynchronous (sampled, not set) - Monitor existing things (with an upper bound) - “Heisen-Gauge” (changes when observed) - E.g.: queue size, current temperature, CPU load Never Gauge something that you can Count!
  27. Timer: Records the (“short”) duration of events - Reports: count,

    sum, max - Percentiles, Histogram, SLOs - E.g.: request/call latency - Long Task Timers (record active tasks) Never Count something that you can Time/Summarize! Metrics 101 - Timer
  28. Micrometer Popular Metrics library on the JVM Like SLF4J, but

    for metrics Simple API (facade/abstraction) Supports the most popular metric backends Comes with spring-boot-actuator Spring projects are instrumented using Micrometer A lot of third-party libraries use Micrometer to instrument their code
  29. Micrometer Ganglia Graphite Humio InfluxDB JMX KairosDB New Relic Like

    SLF4J, but for metrics: AppOptics Atlas Azure Monitor CloudWatch (AWS) Datadog Dynatrace Elastic OpenTSDB Prometheus SignalFx Stackdriver (GCP) StatsD Wavefront* (VMware) (/actuator/metrics) *VMware Tanzu Observability by Wavefront
  30. 2021-11-11 18:42:05.123 [123] INFO Receiving request 2021-11-11 18:42:05.123 [123] DEBUG

    Validating 2021-11-11 18:42:15.123 [123] DEBUG Request is valid 2021-11-11 18:42:15.123 [123] INFO Sending a request 2021-11-11 18:42:25.123 [123] INFO Response received 2021-11-11 18:42:25.123 [123] INFO Returning response - Sending what request? Where? Receiving what response? - Did that response belong to this request? - Can we calculate latency this way (system clock)? Distributed Tracing 101 - Correlation
  31. Distributed Tracing 101 - Span and Trace Span (basic unit

    of work) - SpanId, ParentSpanId, TraceId - Timestamps (start/stop) - Events (annotations) with timestamps - Tags (key-value pairs) - ProcessId - Local IP, Remote IP + Log correlation (and context propagation) + Visualization
  32. Distributed Tracing 101 If we could have something that… -

    Automatically instruments frameworks and libraries - Records spans (sending/receiving requests/responses) - Lets you instrument your codebase - Propagates tracing information over the wire - Adds tracing details to logs (log correlation) We could identify issues across services...
  33. Spring Cloud Sleuth - Distributed Tracing Support for Spring -

    Provides an abstraction layer on top of tracing libraries (3.x) - Brave (OpenZipkin) - OpenTelemetry (CNCF) - Log Correlation + Context Propagation - Instrumentation for Spring Projects (and your application) - Instrumentation for third-party libraries (through Brave and OTel) - Supports various backends(through Brave and OTel)
  34. OpenZipkin Mature, Production Tested Brave is the tracing library Zipkin

    is the backend (data store + UI) Multi language support: C#, Go, Java, JavaScript, Ruby, Scala, PHP + others (community driven) Many backends: Zipkin, SkyWalking, Jaeger, Elastic, X-Ray, Stackdriver, Haystack + Pitchfork, Wavefront* (VMware) *VMware Tanzu Observability by Wavefront
  35. OpenTelemetry (OTel) New, CNCF Project OpenTracing + OpenCensus (deprecated) Wants

    to tackle Logging + Metrics + Tracing Multi language support: C++, C#, Erlang/Elixir, Go, Java, Javascript, PHP, Python, Ruby, Rust, Swift Multiple formats: Zipkin, Jaeger, OTLP (many backends)
  36. OpenTelemetry (OTel) Tracing Specs: stable Tracing Java Instrumentation: Alpha Metrics:

    API Specs: stable; SDK Specs: feature-freeze Logging: No stable specs yet Spring Cloud Sleuth OTel (incubating, only Milestone releases) Right now it is not recommended for prod use The Spring Team is collaborating with OTel
  37. “Non-conventional” Observability Is there anything else beyond Logging + Metrics

    + Tracing? We are looking for: - outputs (that provide) - meaningful information - about what’s inside of our system Can you mention a few?
  38. spring-boot-actuator auditevents, beans, caches, conditions, configprops, env, flyway, health, heapdump,

    httptrace, info, integrationgraph, jolokia, loggers, liquibase, metrics, mappings, scheduledtasks, sessions, startup, threaddump Service Registry/Discoverability How many service instances do we have (by environment)? What versions are deployed (by environment)? Where are they (host/ip, port, instanceId, region, cloud provider, etc.)? Service starts/stops (deployments, restarts) “Non-conventional” Observability
  39. “Non-conventional” Observability API Discoverability - Spring REST Docs - Spring

    Cloud Contract / Pact Broker - Spring HATEOAS - HAL Explorer - Swagger - Eureka, Spring Boot Admin CI/CD - Build performance, success rate - Delivery Pipeline performance, success rate - Deployment frequency, Mean-Time-To-Prod