Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function init(): Promise {
const SERVER_CONFIG = await config().get('calculator-service')
const ADD_SERVER_CONFIG = await config().get('add-service')
// Create thrift client
const thriftClient: AddService.Client = createHttpClient(
AddService.Client,
{
hostName: ADD_SERVER_CONFIG.host,
port: ADD_SERVER_CONFIG.port,
register: [
ThriftClientZipkinFilter({
localServiceName: 'calculator-service',
remoteServiceName: 'add-service',
tracerConfig: {
endpoint: 'http://localhost:9411/api/v1/spans',
httpInterval: 1000,
httpTimeout: 5000,
sampleRate: 1.0,
},
}),
],
},
)
const impl = new Calculator.Processor({
ping(): void {
return
},
}),
])
}
// Create thrift client
const thriftClient: Calculator.Client = createHttpClient(
Calculator.Client,
{
hostName: HAPI_CALC_SERVER_CONFIG.hostName,
port: HAPI_CALC_SERVER_CONFIG.port,
protocol: protocolType,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-client',
remoteServiceName: 'calculator-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
: 'v1',
sampleRate,
httpInterval: 0,
},
}),
ThriftClientTimingFilter({
remoteServiceName: 'calculator-service',
}),
]
export function createServer(sampleRate: number = 0): express.Application {
// Create thrift client
const addServiceClient: AddService.Client = createHttpClient(
AddService.Client,
{
hostName: ADD_SERVER_CONFIG.hostName,
port: ADD_SERVER_CONFIG.port,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-service',
remoteServiceName: 'add-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
: 'v1',
httpInterval: 0,
},
}),
ThriftClientTimingFilter({
remoteServiceName: 'add-service',
}),
]
: [
endpoint: 'http://localhost:9411/api/v1/spans',
httpInterval: 1000,
httpTimeout: 5000,
sampleRate: 1.0,
},
}),
)
// Create thrift client
const thriftClient: Calculator.Client = createHttpClient(
Calculator.Client,
{
hostName: SERVER_CONFIG.host,
port: SERVER_CONFIG.port,
register: [
ThriftClientZipkinFilter({
localServiceName: 'calculator-client',
remoteServiceName: 'calculator-service',
tracerConfig: {
endpoint: 'http://localhost:9411/api/v1/spans',
httpInterval: 1000,
httpTimeout: 5000,
sampleRate: 1.0,
},
}),
],
},
)
function symbolToOperation(sym: string): Operation {
switch (sym) {
case 'add':
export async function createServer(
sampleRate: number = 0,
protocolType: ProtocolType = 'binary',
): Promise {
// Create thrift client
const addServiceClient: AddService.Client = createHttpClient(
AddService.Client,
{
hostName: ADD_SERVER_CONFIG.hostName,
port: ADD_SERVER_CONFIG.port,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-service',
remoteServiceName: 'add-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
: 'v1',
sampleRate,
httpInterval: 0,
},
}),
ThriftClientTimingFilter({
remoteServiceName: 'add-service',
}),
]
export async function createServer(
sampleRate: number = 0,
protocolType: ProtocolType = 'binary',
): Promise {
// Create thrift client
const addServiceClient: AddService.Client = createHttpClient(
AddService.Client,
{
hostName: ADD_SERVER_CONFIG.hostName,
port: ADD_SERVER_CONFIG.port,
register:
sampleRate > 0
? [
ThriftClientZipkinFilter({
localServiceName: 'calculator-service',
remoteServiceName: 'add-service',
tracerConfig: {
endpoint: process.env.ZIPKIN_ENDPOINT,
zipkinVersion:
process.env.ZIPKIN_VERSION === 'v2'
? 'v2'
: 'v1',
sampleRate,
httpInterval: 0,
},
}),
ThriftClientTimingFilter({
remoteServiceName: 'add-service',
}),
]