the ultimate logging architecture - you know you want it!

44
The Ultimate Logging Architecture You know you WANT it! Michele Leroux Bustamante [email protected] @michelebusta http://solliance.net http://michelebusta.com

Upload: michele-bustamante

Post on 13-Jul-2015

929 views

Category:

Technology


5 download

TRANSCRIPT

Page 1: The Ultimate Logging Architecture - You KNOW you want it!

The Ultimate Logging ArchitectureYou know you WANT it!

Michele Leroux [email protected]

@michelebusta

http://solliance.nethttp://michelebusta.com

Page 2: The Ultimate Logging Architecture - You KNOW you want it!

The Hello WorldOf Logging

1992

Page 3: The Ultimate Logging Architecture - You KNOW you want it!

HelloWorld!

Page 4: The Ultimate Logging Architecture - You KNOW you want it!

HelloWorld!

Page 5: The Ultimate Logging Architecture - You KNOW you want it!

Logging Today2014

Page 6: The Ultimate Logging Architecture - You KNOW you want it!

WebBrowsers

MobileApps

ClientApps

Page 7: The Ultimate Logging Architecture - You KNOW you want it!

Why do we log?

• Troubleshooting visibility

• Security audits, review, early detection

• Post incident forensics

• Track change history

• Insights into user activity

• Reporting and analysis

Page 8: The Ultimate Logging Architecture - You KNOW you want it!

What to log?

EXAMPLE:

Application EventsWindows Logs

IIS LogsTrace Output

EXAMPLE:

Login AttemptsUnauthorized/

Authorized AccessPassword Resets

EXAMPLE:

Session TracePurchase Flow

Report GenerationFeature Access

EXAMPLE:

Change history for any critical system

records

Event Logs Audit Logs Activity Logs History Logs

Live Streaming / Analytics

Page 9: The Ultimate Logging Architecture - You KNOW you want it!

Make LoggingEASY

Page 10: The Ultimate Logging Architecture - You KNOW you want it!

Implement a Log Helper

ILogger

Logger

TraceDebug()

TraceInformation()

TraceWarning()

TraceError()

Throw()

Logger.Current.TraceInformation();Logger.Current.Throw(ex);

Page 11: The Ultimate Logging Architecture - You KNOW you want it!

Failure is NOT an option.

Page 12: The Ultimate Logging Architecture - You KNOW you want it!

Event Logging

Page 13: The Ultimate Logging Architecture - You KNOW you want it!

Just Do It

• Whatever is built in

• Whatever you know best

• Just do it

Page 14: The Ultimate Logging Architecture - You KNOW you want it!

Encapsulate the Mechanism

ILogger

Logger

ELMAH / SLAB Azure Diagnostics log4j / log4net ElasticSearch

Page 15: The Ultimate Logging Architecture - You KNOW you want it!

Audit Logging

Page 16: The Ultimate Logging Architecture - You KNOW you want it!

Logs and Compliance

• Contain no user credentials

• No PII, PHI or identifiable user data

• Retention period (1 year is good baseline)

• A structured archival process

• Alert if log reaches capacity

• Authorized access

• Protections from modifications (write-only)

Page 17: The Ultimate Logging Architecture - You KNOW you want it!

Implement an Audit Helper

ILogger

Logger

Tracexxx()

Throw()

AuditLogger.Current.Write();AuditLogger.Current.Throw(ex);

IAuditLogger

AuditLogger

Write() Throw()

Event Logs Audit Logs

Logger.Current.TraceInformation();Logger.Current.Throw(ex);

AzureBlobs

DocumentDB

Page 18: The Ultimate Logging Architecture - You KNOW you want it!

Benefits of noSQL

• Log details tend to evolve

– Schema-less storage is best

– Re-indexing may be necessary

• Co-location with mainline databases

– Adds complexity and overhead (potentially)

– Does not allow a separate “evolution” team around telemetry and analysis

Page 19: The Ultimate Logging Architecture - You KNOW you want it!

Audit Log Use Cases

• Every login attempt (success or failure)

• Excessive login attempts and lockouts

• Blocking/blacklisting users, IP addresses, access ports

• Every logout

• Every modification to user table, including permissions

• All configuration changes

• Attempts to access restricted resources, APIs from unexpected paths

• All access to PII / PHI in an individually identifiable way

Page 20: The Ultimate Logging Architecture - You KNOW you want it!

Audit Log Fields

• Date/time of event• Machine name/instance• Process ID• User ID (possibly encrypted) / Session ID• Type of event• Success or failure of the event (if applicable)• Seriousness of the event violation (if applicable)• Message (free form)• Stack Trace (if applicable)

Page 21: The Ultimate Logging Architecture - You KNOW you want it!

History and ActivityLogging

Page 22: The Ultimate Logging Architecture - You KNOW you want it!

History Logs

• Changes made to key tables

• Describes

– Who changed the record?

– From which application?

– Which fields changed?

• Need the ability to surface this to applications

– Sometimes to users

– Always to operations to solve problems

Page 23: The Ultimate Logging Architecture - You KNOW you want it!

Implement a History Log Helper

IHistoryLogger

HistoryLogger

HistoryLogger.Current.Write();

History Logs

DocumentDB

Users

Orders

ClaimsClaims

Claims

Page 24: The Ultimate Logging Architecture - You KNOW you want it!

Wrap History in the DAL

History Logs

OrdersDal

UsersDal

ContentDal

Relational DB

Users

Orders

Claims

Content

Page 25: The Ultimate Logging Architecture - You KNOW you want it!

Wrap History in the DAL

History Logs

OrdersDal

UsersDal

ContentDal

Relational DB

Users

Orders

Claims

Content

Page 26: The Ultimate Logging Architecture - You KNOW you want it!

What happened with my order?

History Logs

OrdersDal

UsersDal

ContentDal

Relational DB

Users

Orders

Claims

Content

Page 27: The Ultimate Logging Architecture - You KNOW you want it!

Activity Logs

• Not specific to code execution and troubleshooting, diagnostics

• Specific to the application, user activity

• COULD be informative to users as well– History of recent activity in the site

– Reports they requested, downloads, other…

• Provides insights to the business regarding user activity, trends and patterns– Non-critical analysis

Page 28: The Ultimate Logging Architecture - You KNOW you want it!

Implement an Activity Log Helper

IActivityLogger

ActivityLogger

ActivityLogger.Current.UserDownload();ActivityLogger.Current.ReportRequest();ActivityLogger.Current.PurchaseOrder();

Activity Logs

DocumentDB

Page 29: The Ultimate Logging Architecture - You KNOW you want it!

What happened with my order?

History Logs

OrdersDal

Relational DB

Orders

Activity Logs

Page 30: The Ultimate Logging Architecture - You KNOW you want it!

Automate Logging Where Possible

• View controllers

• API controllers

• Authorization hooks

• Outbound calls

• Data Access layers

Page 31: The Ultimate Logging Architecture - You KNOW you want it!

To QueueOr NOT To Queue

Page 32: The Ultimate Logging Architecture - You KNOW you want it!

Event Logs Audit Logs Activity Logs History Logs

Loggers

Client and Server Logging

WebBrowsers

MobileApps

ClientApps

Mobile API Client API Log API Client API Log API

Page 33: The Ultimate Logging Architecture - You KNOW you want it!

What can I queue?

Event Logs Audit Logs Activity Logs History Logs

Loggers

ETWDocDB

Page 34: The Ultimate Logging Architecture - You KNOW you want it!

ETW Goal

Event Logs Audit Logs Activity Logs History Logs

Loggers

ETW

HistoryPublisher

ActivityPublisher

Audit Publisher

Events Publisher

Stream Analytics

ALERTS

Page 35: The Ultimate Logging Architecture - You KNOW you want it!

Queued Logging

• Considerations– Timestamps matter

– Correlation across nodes matters (to a point)

– Guaranteed exactly one in order doesn’t exist

– Async is good (mostly)

• That said– Priority matters (hot, warm, default)

– Simplicity matters

– Throughput matters

Page 36: The Ultimate Logging Architecture - You KNOW you want it!

TroubleshootingIs Important!

Page 37: The Ultimate Logging Architecture - You KNOW you want it!

Problem Statement

• We need immediate access to what the HECK is going on when there is a problem

• Sometimes I use (in order):

– Google Analytics

– Event Logs (Azure Website)

– Table Storage queries (STRIKE THAT, USELESS)

– Blob storage CSVs (good enough, not realtime)

Page 38: The Ultimate Logging Architecture - You KNOW you want it!

Elasticsearch Architecture

Elasticsearch

Logger AuditLogger HistoryLogger ActivityLogger

Page 39: The Ultimate Logging Architecture - You KNOW you want it!

Kibana Visualization

Page 40: The Ultimate Logging Architecture - You KNOW you want it!

LogStash

LogStash

Elasticsearch

Identity Server Web Server / IIS /

Event LogsCPU / Memory

Perf Counters

Blob CSVs …

Page 41: The Ultimate Logging Architecture - You KNOW you want it!

Archives, Aggregation and Analytics

Page 42: The Ultimate Logging Architecture - You KNOW you want it!

ARCHIVE

Elastic Search

Audit Logs

Activity Logs

History Logs

HDInsight

PoweShellSpin up, analyze, spin down

Ingest

Blob

Storage

Event Logs

OR, just…

Page 43: The Ultimate Logging Architecture - You KNOW you want it!

What you’re looking for is…

• Manageable implementation

• Ability to “evolve” log content

• Reduce IO / socket overhead (monitor this)

• Prioritization

• Real-time analytics, troubleshooting

• Accessibility for UI lookups (history, activity)

• Archival and mass analysis

Page 44: The Ultimate Logging Architecture - You KNOW you want it!

References

• Conference resources:

– http://michelebusta.com

• Contact me:

[email protected]

– @michelebusta

• Founder, CIO of Solliance

– http://solliance.net