Introduction to Sage
A node.js micro service container
Agenda
What is node.js?
Pros and Cons
What is Sage?
Use cases
Workshop

What is node.js?
Javascript runtime
Built for running network apps
Uses V8 (chrome engine)
Async \ non-blocking model
Why node?
Web APIs ("HTTP is a first class citizen")
Natively async
Lightweight
Javascript (?!)

Why not node?
CPU intensive jobs

What is Sage?
Ob1k for node
Wraps express
Common routes and services

Sage API
import {server as SageServer, lumberjack} from '@sage/toolkit';
import router from './route/routes';
const logger = lumberjack.LoggerFactory.getLogger('server.main');
const myService = new SageServer({
routes: router.getRoutes()
});
myService.start().then(() => {
logger.info(`*************** MyService Started ********************`);
});
server
Sage API
import { discovery, httpClient } from '@sage/toolkit';
...
constructor() {
this.httpClientInstance = httpClient.create();
}
async crawl(req: Request, res: Response) {
const { url } = req.query;
const target = await discovery.discoveryClient.fetchTarget('DocumentActions');
return this.httpClientInstance.get(`${target}/api/crawlByUrl/url=${url}`);
}
discovery
Sage API
config
[all]:
recaptcha.enabled: false
trackjs.key: dummay
[test]:
[simulator]:
[stg]:
trackjs.key: 123BjhWp6dHhlLAXk4AiGaKnoq4543
[prod]:
recaptcha.enabled: true
trackjs.key: ENC(lsQBjhWp6dHhlLAXk4AiGaKnoqfydn)import { config } from '@sage/toolkit';
...
isRecaptchaEnabled() {
return config.get('recaptcha.enabled');
}
Sage API
import { metrics } from '@sage/toolkit';
...
constructor() {
this.tokenIssueCounter = metrics.createCounter('token_issue',
'Counter for creation of tokens',
['token_type', 'status']);
}
issueToken(params: any) {
tokenIssueCounter.inc({token_type: 'AMELIA', status: 'new'});
...
}
metrics
Where do we use it?
const target = await discoveryClient.fetchTarget(serviceName);
proxy.web(req, res, { target: target });
example: ob-gateway
Never trust benchmarks



Workshop
Introduction to Sage
By Tsachi Shushan
Introduction to Sage
- 526