How to use Logger for Custom FlexBalancers?

Test your Custom FlexBalancers with PerfOps Logger usage

We have provided simple and powerful feature that makes your "flex-balancing" more comfortable. You can log any events and data using `logger.write`:

/**
* Logger interface
*/
declare interface ILogger {
/**
* Write a message to the log.
*
* Logged messages will be visible in the Raw Logs for
* current Flex Balancer in the Panel
*/
write(message: string): void;
}

declare const logger: ILogger;


Let's see how it works. We should create a simplest Custom type balancer and add logging to its code:

function onRequest(req: IRequest, res: IResponse) {
res.setCNAMERecord('my.sampleanswer.net');
logger.write('it should return: my.sampleanswer.net');
}


In fact it does nothing useful - returns the same answer, but the goal was to test our logging feature.


So let's Publish it and make couple dozens of `dig` tests, using any of approaches described in How to test my FlexBalancer tutorial.

logger_1

We get some responses and now we need to check our logs. Log in to PerfOps Panel Analytics page, select FlexBalancer and that balancer we have created:

logger_2

Apply any filters and take a look at raw logs section below:

logger_3

`View meta` brings up a window with detailed information, where we can see our log message!

logger_4


So, now you can log different events depending on your FlexBalancer logic and needs!

Let's make an error and log it. Mixing of A and CNAME records is not allowed for our responses, so the code below will definitely produce an error:

function onRequest(req: IRequest, res: IResponse) {
try {
res.setARecord('192.168.1.1');
res.setCNAMERecord('do.something.for.test.net');
} catch(error) {
logger.write(error.message); // Here we log our error
}
return; // return answer
}


Let's publish and test this balancer. Dig returns:

logger_5

And if we look at our raw logs - we will see our 'caught' error message:

logger_6

Easy and helpful, isnt' it?