SlideShare a Scribd company logo
LOGS IN CODE
MODEN APPLICATION
Jannarong Wadthong


1/Sept/2020
▸ Part I — Software Development and S.O.L.I.D ~ 10 mins


▸ Part II — Logs in Code ~ 30 mins


▸ Part III — Logs in Architecture ~ 15 mins


▸ Part IV — Log Framework ~ xx mins
SOFTWARE DEVELOPMENT
AND S.O.L.D
PART I
S.O.L.I.D
S.O.L.I.D
S.O.L.I.D
TEXT
MAINTAINABILITY CAN BE QUANTIFIED:
▸ Extensibility — how hard is it to add features


▸ Stability — how hard is it to make changes?


▸ Understandability — how hard is it for someone else to pick
up your code?
S.O.L.I.D
12 PRINCIPLES BEHIND THE AGILE MANIFESTO
HOW TO AVOID TECHNICAL DEBT?
▸ Avoid code smells as you go, and practice regular
refactoring. Don’t Repeat Yourself (DRY), use clear &
consistent variable & method names, practice Test Driven
Development (TDD), follow the Single Responsibility
Principle (SRP), avoid long/complex methods, and
maintain thin interfaces / don’t hard-code


▸ Conduct code reviews.


▸ Use automated testing.
LOGS IN CODE
PART II
PUBLIC VS INTERNAL BANKING API
▸ Transfer Money API


▸ Deposit Money API


▸ Withdrawal Money API
TEXT
PUBLIC TRANSFER MONEY FLOW
CONTROLLER ACCEPTS
REQUEST
CONTROLLER ACK BACK TO USER
CHECK BALANCE WITHDRAW DEPOSIT
CHECK
AUTHORISATION
TEXT
INTERNAL TRANSFER MONEY FLOW
CONTROLLER ACCEPTS
REQUEST
CONTROLLER ACK BACK TO USER
CHECK BALANCE WITHDRAW DEPOSIT
INTERNAL TRANSFER
void transfer(Account fromAcc, Account toAcc, int amount) throws Exception {


if (fromAcc.getBalance() < amount)


throw new InsufficientFundsException();




fromAcc.withdraw(amount);


toAcc.deposit(amount);


}
PUBLIC TRANSFER
void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception {




if (!isUserAuthorised(user, fromAcc)) {


logger.info("User has no permission.");


throw new UnauthorisedUserException();


}




if (fromAcc.getBalance() < amount) {


logger.info("Insufficient funds.");


throw new InsufficientFundsException();


}


fromAcc.withdraw(amount);


toAcc.deposit(amount);


}
PUBLIC TRANSFER WITH PERFORMANCE LOGGING
void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception {


long startTime = currentTime();


if (!isUserAuthorised(user, fromAcc)) {


logger.info("User has no permission.");


throw new UnauthorisedUserException();


}




if (fromAcc.getBalance() < amount) {


logger.info("Insufficient funds.");


throw new InsufficientFundsException();


}


fromAcc.withdraw(amount);


toAcc.deposit(amount);


long endTime = currentTime();


logger.info("Execution time:" + (endTime - startTime);


}
S.O.L.I.D
S.O.L.I.D — HOW?
TEXT
WITHDRAW MONEY
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
CONTROLLER
CHECK BALANCE
DO WITHDRAW
START TIME
END TIME
START TIME
END TIME
TEXT
DEPOSIT MONEY
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
CONTROLLER
DO DEPOSIT
START TIME
END TIME
START TIME
END TIME
TEXT
TRANSFER MONEY
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
DEPOSIT
START TIME
END TIME
TEXT
WITHDRAW MONEY
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
CONTROLLER
CHECK BALANCE
DO WITHDRAW
START TIME
END TIME
START TIME
END TIME
DO WITHDRAW
TEXT
DEPOSIT MONEY
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
CONTROLLER
DO DEPOSIT
START TIME
END TIME
START TIME
END TIME
DO DEPOSIT
ALL PUBLIC API
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
ALL PUBLIC API
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
PERFORMANCE LOGGING CONCERN
ALL PUBLIC API
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
PERFORMANCE LOGGING CONCERN SECURITY CONCERN
PROBLEM HAVING LOGS IN CODE
PROBLEM HAVING LOGS IN CODE
PROBLEM HAVING LOGS IN CODE
PROBLEM HAVING LOGS IN CODE
CODE TANGLING AND CODE SCATTERING
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
DO DEPOSIT
CHECK AUTHORISATION
START TIME
END TIME
CONTROLLER
CHECK BALANCE
WITHDRAW
CHECK AUTHORISATION
DEPOSIT
START TIME
END TIME
DEPOSIT TRANSFER
PERFORMANCE LOGGING CONCERN SECURITY CONCERN
CODE TANGLING AND CODE SCATTERING
WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CONTROLLER
CHECK BALANCE
DO WITHDRAW
CONTROLLER
DO DEPOSIT
CONTROLLER
CHECK BALANCE
WITHDRAW
DEPOSIT
DEPOSIT TRANSFER
PERFORMANCE LOGGING ASPECT SECURITY ASPECT
WE WANT THIS
@LogExecutionTime


@Authorize


void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception {


checkBalance(fromAcc);


fromAcc.withdraw(amount);


toAcc.deposit(amount);


}
TEXT
AOP IMPLEMENTATION: DYNAMIC PROXY
@Aspect


Performance Logging Proxy


1.start time


2.end time
ATMController Target Service
+ transfer()


+ withdraw()


+ deposit()
As you can see from that diagram, the proxy has one job.
• Opening and closing times.
• And then delegating to the real target service, the one we wrote.
• And ATMController will never know that they are talking to a proxy, and not the real thing.
2 MARKERS: @BEFORE AND @AFTER
OR 1 MARKER: @AROUND
TEXT
AOP IMPLEMENTATION
@Aspect


Authorisation Proxy


1.check if user is valid


ATMController Real ATMService
+ transfer()


+ withdraw()


+ deposit()
1 MARKER: @BEFORE
TEXT
ASPECT
@Aspect
public class PerformanceAspect {
@Around("@annotation(LogExecutionTime)")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
long start = System.currentTimeMillis();
Object proceed = joinPoint.proceed();
long executionTime = System.currentTimeMillis() - start;
log.info(joinPoint.getSignature() + " executed in " + executionTime + "ms");
return proceed;
}
}
LOGS IN ARCHITECTURE
PART III
This slide is intentionally left blank :)
TEXT
LOGS IN ACTION
▸ Troubleshooting


▸ Law


▸ User behaviours
TEXT
PUBLIC TRANSFER MONEY FLOW
TEXT
LOG FRAMEWORK: IMPLEMENTATION
LOG
HARDDISK
STOUT REST API
DATABASE
TEXT FILE
PROMETHEUS GRAFANA
TEXT
TEXT
TEXT
SUMMARY
Begin/End Transaction


Transaction Error Hand
TEXT
THANK YOU

More Related Content

What's hot

JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promise
eslam_me
 
Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathon
Sittiphol Phanvilai
 
Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010
Cleverson Sacramento
 
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196
Mahmoud Samir Fayed
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script PromiseAlok Guha
 
Clojure workshop
Clojure workshopClojure workshop
Clojure workshop
Alf Kristian Støyle
 
Xtext @ Profict Summer Camp
Xtext @ Profict Summer CampXtext @ Profict Summer Camp
Xtext @ Profict Summer CampSven Efftinge
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
Konrad Malawski
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwift
Scott Gardner
 
Functional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwiftFunctional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwift
Rodrigo Leite
 
Introduction to typescript
Introduction to typescriptIntroduction to typescript
Introduction to typescript
Mario Alexandro Santini
 
Oop assignment 02
Oop assignment 02Oop assignment 02
Oop assignment 02
MamoonKhan39
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline codeRajeev Sharan
 
ES2015 promise
ES2015 promiseES2015 promise
ES2015 promise
LearningTech
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorEthanTu
 
Async js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaAsync js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgaria
HackBulgaria
 
The account problem in Java and Clojure
The account problem in Java and ClojureThe account problem in Java and Clojure
The account problem in Java and Clojure
Alf Kristian Støyle
 

What's hot (19)

JavaScript promise
JavaScript promiseJavaScript promise
JavaScript promise
 
Smart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathonSmart Contract programming 101 with Solidity #PizzaHackathon
Smart Contract programming 101 with Solidity #PizzaHackathon
 
Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010Demoiselle 2.0 no JavaOne Brasil 2010
Demoiselle 2.0 no JavaOne Brasil 2010
 
The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196The Ring programming language version 1.7 book - Part 85 of 196
The Ring programming language version 1.7 book - Part 85 of 196
 
Java Script Promise
Java Script PromiseJava Script Promise
Java Script Promise
 
Clojure workshop
Clojure workshopClojure workshop
Clojure workshop
 
Xtext @ Profict Summer Camp
Xtext @ Profict Summer CampXtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
Reactive programming with RxSwift
Reactive programming with RxSwiftReactive programming with RxSwift
Reactive programming with RxSwift
 
Functional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwiftFunctional Reactive Programming - RxSwift
Functional Reactive Programming - RxSwift
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Introduction to typescript
Introduction to typescriptIntroduction to typescript
Introduction to typescript
 
Oop assignment 02
Oop assignment 02Oop assignment 02
Oop assignment 02
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline code
 
ES2015 promise
ES2015 promiseES2015 promise
ES2015 promise
 
Trisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptorTrisha gee concurrentprogrammingusingthedisruptor
Trisha gee concurrentprogrammingusingthedisruptor
 
Async js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgariaAsync js - Nemetschek Presentaion @ HackBulgaria
Async js - Nemetschek Presentaion @ HackBulgaria
 
The account problem in Java and Clojure
The account problem in Java and ClojureThe account problem in Java and Clojure
The account problem in Java and Clojure
 

Similar to Logging in code

Introduction to aop
Introduction to aopIntroduction to aop
Introduction to aop
Dror Helper
 
A Journey with React
A Journey with ReactA Journey with React
A Journey with React
FITC
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
Thibaud Desodt
 
Formal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsFormal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsGera Shegalov
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
Chad Hietala
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy codeShriKant Vashishtha
 
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy
 
Taming event-driven software via formal verification
Taming event-driven software via formal verificationTaming event-driven software via formal verification
Taming event-driven software via formal verification
AdaCore
 
README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia
Richard Radics
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractGera Shegalov
 
Ruslan Platonov - Transactions
Ruslan Platonov - TransactionsRuslan Platonov - Transactions
Ruslan Platonov - TransactionsDmitry Buzdin
 
Test First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTest First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in Grails
Tim Berglund
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
Massimo Oliviero
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in Grails
Tim Berglund
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
goodfriday
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
Vadym Khondar
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
BOSC Tech Labs
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented ProgrammingAndrey Bratukhin
 
ELEVATE Paris
ELEVATE ParisELEVATE Paris
ELEVATE Paris
Peter Chittum
 

Similar to Logging in code (20)

Introduction to aop
Introduction to aopIntroduction to aop
Introduction to aop
 
A Journey with React
A Journey with ReactA Journey with React
A Journey with React
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
Formal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction ContractsFormal Verification of Web Service Interaction Contracts
Formal Verification of Web Service Interaction Contracts
 
Inversion Of Control
Inversion Of ControlInversion Of Control
Inversion Of Control
 
Working effectively with legacy code
Working effectively with legacy codeWorking effectively with legacy code
Working effectively with legacy code
 
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
Stanfy MadCode Meetup #11: Why do you need to switch from Obj-C to Swift, or ...
 
Taming event-driven software via formal verification
Taming event-driven software via formal verificationTaming event-driven software via formal verification
Taming event-driven software via formal verification
 
README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia README.MD for building the first purely digital mobile bank in Indonesia
README.MD for building the first purely digital mobile bank in Indonesia
 
Formal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction ContractFormal Verification of Transactional Interaction Contract
Formal Verification of Transactional Interaction Contract
 
Ruslan Platonov - Transactions
Ruslan Platonov - TransactionsRuslan Platonov - Transactions
Ruslan Platonov - Transactions
 
Test First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in GrailsTest First Refresh Second: Test-Driven Development in Grails
Test First Refresh Second: Test-Driven Development in Grails
 
Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)Advanced iOS Debbuging (Reloaded)
Advanced iOS Debbuging (Reloaded)
 
Test First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in GrailsTest First, Refresh Second: Web App TDD in Grails
Test First, Refresh Second: Web App TDD in Grails
 
Developing ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller PatternDeveloping ASP.NET Applications Using the Model View Controller Pattern
Developing ASP.NET Applications Using the Model View Controller Pattern
 
Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
How to perform debounce in react
How to perform debounce in reactHow to perform debounce in react
How to perform debounce in react
 
Aspect-Oriented Programming
Aspect-Oriented ProgrammingAspect-Oriented Programming
Aspect-Oriented Programming
 
ELEVATE Paris
ELEVATE ParisELEVATE Paris
ELEVATE Paris
 

Recently uploaded

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 

Recently uploaded (20)

Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 

Logging in code

  • 1. LOGS IN CODE MODEN APPLICATION Jannarong Wadthong 1/Sept/2020
  • 2. ▸ Part I — Software Development and S.O.L.I.D ~ 10 mins ▸ Part II — Logs in Code ~ 30 mins ▸ Part III — Logs in Architecture ~ 15 mins ▸ Part IV — Log Framework ~ xx mins
  • 7. TEXT MAINTAINABILITY CAN BE QUANTIFIED: ▸ Extensibility — how hard is it to add features ▸ Stability — how hard is it to make changes? ▸ Understandability — how hard is it for someone else to pick up your code?
  • 9. 12 PRINCIPLES BEHIND THE AGILE MANIFESTO
  • 10. HOW TO AVOID TECHNICAL DEBT? ▸ Avoid code smells as you go, and practice regular refactoring. Don’t Repeat Yourself (DRY), use clear & consistent variable & method names, practice Test Driven Development (TDD), follow the Single Responsibility Principle (SRP), avoid long/complex methods, and maintain thin interfaces / don’t hard-code ▸ Conduct code reviews. ▸ Use automated testing.
  • 12. PUBLIC VS INTERNAL BANKING API ▸ Transfer Money API ▸ Deposit Money API ▸ Withdrawal Money API
  • 13. TEXT PUBLIC TRANSFER MONEY FLOW CONTROLLER ACCEPTS REQUEST CONTROLLER ACK BACK TO USER CHECK BALANCE WITHDRAW DEPOSIT CHECK AUTHORISATION
  • 14. TEXT INTERNAL TRANSFER MONEY FLOW CONTROLLER ACCEPTS REQUEST CONTROLLER ACK BACK TO USER CHECK BALANCE WITHDRAW DEPOSIT
  • 15. INTERNAL TRANSFER void transfer(Account fromAcc, Account toAcc, int amount) throws Exception { if (fromAcc.getBalance() < amount) throw new InsufficientFundsException(); fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 16. PUBLIC TRANSFER void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception { if (!isUserAuthorised(user, fromAcc)) { logger.info("User has no permission."); throw new UnauthorisedUserException(); } if (fromAcc.getBalance() < amount) { logger.info("Insufficient funds."); throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 17. PUBLIC TRANSFER WITH PERFORMANCE LOGGING void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception { long startTime = currentTime(); if (!isUserAuthorised(user, fromAcc)) { logger.info("User has no permission."); throw new UnauthorisedUserException(); } if (fromAcc.getBalance() < amount) { logger.info("Insufficient funds."); throw new InsufficientFundsException(); } fromAcc.withdraw(amount); toAcc.deposit(amount); long endTime = currentTime(); logger.info("Execution time:" + (endTime - startTime); }
  • 20. TEXT WITHDRAW MONEY CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION CONTROLLER CHECK BALANCE DO WITHDRAW START TIME END TIME START TIME END TIME
  • 21. TEXT DEPOSIT MONEY CONTROLLER DO DEPOSIT CHECK AUTHORISATION CONTROLLER DO DEPOSIT START TIME END TIME START TIME END TIME
  • 22. TEXT TRANSFER MONEY CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW DEPOSIT START TIME END TIME
  • 23. TEXT WITHDRAW MONEY CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION CONTROLLER CHECK BALANCE DO WITHDRAW START TIME END TIME START TIME END TIME DO WITHDRAW
  • 24. TEXT DEPOSIT MONEY CONTROLLER DO DEPOSIT CHECK AUTHORISATION CONTROLLER DO DEPOSIT START TIME END TIME START TIME END TIME DO DEPOSIT
  • 25. ALL PUBLIC API WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER
  • 26. ALL PUBLIC API WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER PERFORMANCE LOGGING CONCERN
  • 27. ALL PUBLIC API WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER PERFORMANCE LOGGING CONCERN SECURITY CONCERN
  • 32. CODE TANGLING AND CODE SCATTERING WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE DO WITHDRAW CHECK AUTHORISATION START TIME END TIME CONTROLLER DO DEPOSIT CHECK AUTHORISATION START TIME END TIME CONTROLLER CHECK BALANCE WITHDRAW CHECK AUTHORISATION DEPOSIT START TIME END TIME DEPOSIT TRANSFER PERFORMANCE LOGGING CONCERN SECURITY CONCERN
  • 33. CODE TANGLING AND CODE SCATTERING WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CONTROLLER CHECK BALANCE DO WITHDRAW CONTROLLER DO DEPOSIT CONTROLLER CHECK BALANCE WITHDRAW DEPOSIT DEPOSIT TRANSFER PERFORMANCE LOGGING ASPECT SECURITY ASPECT
  • 34. WE WANT THIS @LogExecutionTime @Authorize void transfer(Account fromAcc, Account toAcc, int amount, User user) throws Exception { checkBalance(fromAcc); fromAcc.withdraw(amount); toAcc.deposit(amount); }
  • 35. TEXT AOP IMPLEMENTATION: DYNAMIC PROXY @Aspect 
 Performance Logging Proxy 1.start time 2.end time ATMController Target Service + transfer() + withdraw() + deposit() As you can see from that diagram, the proxy has one job. • Opening and closing times. • And then delegating to the real target service, the one we wrote. • And ATMController will never know that they are talking to a proxy, and not the real thing. 2 MARKERS: @BEFORE AND @AFTER OR 1 MARKER: @AROUND
  • 36. TEXT AOP IMPLEMENTATION @Aspect 
 Authorisation Proxy 1.check if user is valid ATMController Real ATMService + transfer() + withdraw() + deposit() 1 MARKER: @BEFORE
  • 37. TEXT ASPECT @Aspect public class PerformanceAspect { @Around("@annotation(LogExecutionTime)") public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable { long start = System.currentTimeMillis(); Object proceed = joinPoint.proceed(); long executionTime = System.currentTimeMillis() - start; log.info(joinPoint.getSignature() + " executed in " + executionTime + "ms"); return proceed; } }
  • 39. This slide is intentionally left blank :)
  • 40. TEXT LOGS IN ACTION ▸ Troubleshooting ▸ Law ▸ User behaviours
  • 42. TEXT LOG FRAMEWORK: IMPLEMENTATION LOG HARDDISK STOUT REST API DATABASE TEXT FILE PROMETHEUS GRAFANA
  • 43. TEXT
  • 44. TEXT
  • 45. TEXT