Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

76
Why and how to test logging DevOps Showcase North / Testing Showcase North Manchester, UK - Unicom Thursday 11 th February 2015 Matthew Skelton Skelton Thatcher Consulting

Transcript of Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Page 1: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Why and how to test loggingDevOps Showcase North / Testing Showcase North

Manchester, UK - UnicomThursday 11th February 2015

Matthew SkeltonSkelton Thatcher Consulting

Page 2: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

confession:

I am a big fan of logging

Page 3: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 4: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

use logging as a channel/vector to make distributed

systems more testable

Page 5: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

transforming technology and teams

high impact expertise

Cloud, Agile, DevOps

Page 6: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 7: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 8: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Why we should test logging

How to test logging effectively

Page 9: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 10: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 11: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

exceptional situationsedge cases

metricsanalytics‘audits’

…@evanphx

Page 12: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

logging as an execution trace

Page 13: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

reduce time-to-detectincrease team engagement

increase configurabilityenhance DevOps collaboration

#operability

Page 14: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 15: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

(event sourcing)

(structured logging)

(CQRS)

Page 16: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 17: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

using logging mainly for errors

inconsistent use of logging

“logging slows things down”

Page 18: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

“logging pollutes my domain model”

“logging is just for Ops people”

log aggregation only in Production

Page 19: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

logging assumed to be free ($0) to implement

logs not available to Tester or Developers

Page 20: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 21: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 22: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 23: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 24: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 25: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

distinct event IDs

transaction tracing

instrumentation

log aggregation & search

Page 26: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

cross-component visibility

increased test coverage

programmatic assertions

deep insights

Page 27: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

stories for testing logging

Page 28: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

BasketItemAdded

Search: BasketItem

Page 29: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Continuous event IDs

Page 30: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

How many distinct event types (state transitions) in

your application?

Page 31: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 32: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

represent distinct states

Page 33: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

enum

Human-readable sets: unique values, sparse, immutable

C#, Java, Python, node(Ruby, PHP, …)

Page 34: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

public enum EventID

{

// Badly-initialised logging data

NotSet = 0,

// An unrecognised event has occurred

UnexpectedError = 10000,

ApplicationStarted = 20000,

ApplicationShutdownNoticeReceived = 20001,

PageGenerationStarted = 30000,

PageGenerationCompleted = 30001,

MessageQueued = 40000,

MessagePeeked = 40001,

BasketItemAdded = 60001,

BasketItemRemoved = 60002,

CreditCardDetailsSubmitted = 70001,

// ...

}

Page 35: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Technical

Domain

public enum EventID

{

// Badly-initialised logging data

NotSet = 0,

// An unrecognised event has occurred

UnexpectedError = 10000,

ApplicationStarted = 20000,

ApplicationShutdownNoticeReceived = 20001,

PageGenerationStarted = 30000,

PageGenerationCompleted = 30001,

MessageQueued = 40000,

MessagePeeked = 40001,

BasketItemAdded = 60001,

BasketItemRemoved = 60002,

CreditCardDetailsSubmitted = 70001,

// ...

}

Page 36: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

BasketItemAdded = 60001

Page 37: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

BasketItemAdded = 60001

BasketItemRemoved = 60002

Page 38: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

BasketItemAdded = 60001

BasketItemRemoved = 60002

Page 39: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

represent distinct states

Page 40: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 41: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

OrderSvc_BasketItemAdded

Page 42: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 43: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Monolith to microservices:debugger does not have the full view

Page 44: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Even with remote debugger, it’s boring to attach and detach

Page 45: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 46: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Storage I/O

Worker Job

Queue

Upload

Page 47: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 48: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 49: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 50: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Transaction tracing

Page 51: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

‘Unique-ish’ identifier for each request

Passed through downstream layers

Page 52: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Unique-ish ID

Page 53: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Testing logging

Page 54: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

use logging as a channel/vector to make distributed

systems more testable

Page 55: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

track a parcel online

Page 56: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 57: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

search by event ID

Page 58: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

transaction trace

Page 59: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Web App

Doc store

Audit service

Msg queue

Page 60: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Transactional sub-system

Log aggregation sub-system

Page 61: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

An action here… …results in log entry here

Page 62: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

trace events in a distributed,

asynchronous system

Page 63: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

stories for testing logging

Page 64: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

AuditRecordCreated

Search: AuditRecordCreated

Page 65: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

AuditRecordCreated

Search: AuditRecordCreated

Page 66: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Feature: User trades stocksScenario: User requests a sell before close of trading

Given I have 100 shares of MSFT stockAnd I have 150 shares of APPL stockAnd the time is before close of trading

When I ask to sell 20 shares of MSFT stock

Then I should have 80 shares of MSFT stockAnd I should have 150 shares of APPL stockAnd a sell order for 20 shares of MSFT stock should have been executed

http://martinfowler.com/bliki/GivenWhenThen.html - Pete Hodgson

Page 67: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Given I run a scenario as a LawyerAnd I create a document[And I wait 5 seconds]

When I search the logs APIThen I should find a recent entry for “AuditRecordCreated”

Page 68: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton
Page 69: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Recap

Page 70: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

use logging as a channel/vector to make distributed

systems more testable

Page 71: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

unique-ish event type IDs

transaction tracing

log aggregation & search

Stories: expected search results

Page 72: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

cross-component visibility

increased test coverage

programmatic assertions

deep insights

Page 73: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

trace events in a distributed,

asynchronous system

Page 74: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

‘Structured Logging’TW: “Adopt” (May 2015)

https://www.thoughtworks.com/radar/techniques/structured-logging

http://gregoryszorc.com/

.NET: http://serilog.net/Java: https://github.com/fluent/fluent-logger-java

Page 75: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

More

Ditch the Debugger and Use Log Analysis Instead

Matthew Skelton

https://blog.logentries.com/2015/07/ditch-the-debugger-and-use-log-analysis-instead/

Page 76: Why and how to test logging - DevOps Showcase North - Feb 2016 - Matthew Skelton

Thank you

http://skeltonthatcher.com/[email protected]

@SkeltonThatcher

+44 (0)20 8242 4103

@matthewpskelton