Skip to content

Commit

Permalink
Add common logging to poller
Browse files Browse the repository at this point in the history
  • Loading branch information
nielm committed Dec 12, 2023
1 parent 5f1c459 commit de90fb8
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 160 deletions.
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const pollerCore = require('./poller/poller-core');
const scalerCore = require('./scaler/scaler-core');
const poller = require('./poller');
const scaler = require('./scaler');
const {logger} = require('./autoscaler-common/logger');
const yaml = require('js-yaml');
const fs = require('fs/promises');

Expand All @@ -27,8 +28,7 @@ async function main() {
const DEFAULT_CONFIG_LOCATION =
'/etc/autoscaler-config/autoscaler-config.yaml';

scalerCore.log(
`Autoscaler unified poller+scaler job started`, {severity: 'INFO'});
logger.info(`Autoscaler unified poller+scaler job started`);

let configLocation = DEFAULT_CONFIG_LOCATION;

Expand All @@ -41,9 +41,9 @@ async function main() {

if (process.env.AUTOSCALER_CONFIG) {
configLocation = process.env.AUTOSCALER_CONFIG;
scalerCore.log(`Using custom config location ${configLocation}`);
logger.debug(`Using custom config location ${configLocation}`);
} else {
pollerCore.log(`Using default config location ${configLocation}`);
logger.debug(`Using default config location ${configLocation}`);
}

try {
Expand All @@ -54,9 +54,9 @@ async function main() {
await scalerCore.scaleSpannerInstanceLocal(spanner);
}
} catch (err) {
scalerCore.log(
'Error in unified poller/scaler wrapper:',
{severity: 'ERROR', payload: err});
logger.error({
message: 'Error in unified poller/scaler wrapper:',
err: err});
}
}

Expand Down
1 change: 1 addition & 0 deletions src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions src/poller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
const pollerCore = require('poller-core');
const yaml = require('js-yaml');
const fs = require('fs/promises');
const {logger} = require('../autoscaler-common/logger');

/**
* Startup function
Expand All @@ -24,7 +25,7 @@ async function main() {
const DEFAULT_CONFIG_LOCATION =
'/etc/autoscaler-config/autoscaler-config.yaml';

pollerCore.log(`Autoscaler Poller job started`, {severity: 'INFO'});
logger.info(`Autoscaler Poller job started`);

let configLocation = DEFAULT_CONFIG_LOCATION;

Expand All @@ -37,18 +38,19 @@ async function main() {

if (process.env.AUTOSCALER_CONFIG) {
configLocation = process.env.AUTOSCALER_CONFIG;
pollerCore.log(`Using custom config location ${configLocation}`);
logger.debug(`Using custom config location ${configLocation}`);
} else {
pollerCore.log(`Using default config location ${configLocation}`);
logger.debug(`Using default config location ${configLocation}`);
}

try {
const config = await fs.readFile(configLocation, {encoding: 'utf8'});
await pollerCore.checkSpannerScaleMetricsJSON(
JSON.stringify(yaml.load(config)));
} catch (err) {
pollerCore.log(
'Error in Poller wrapper:', {severity: 'ERROR', payload: err});
logger.error({
message: 'Error in Poller wrapper:',
err: err});
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/poller/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/poller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
"dependencies": {
"js-yaml": "^4.1.0",
"poller-core": "file:poller-core",
"run": "^1.4.0"
"run": "^1.4.0",
"autoscaler-common": "file:../autoscaler-common"
},
"scripts": {
"start": "node -e \"require('./index').autoscalerMain()\""
"start": "node -e \"require('./index').main()\""
}
}
Loading

0 comments on commit de90fb8

Please sign in to comment.