Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: ZENKO-616 Use local cache for metrics #350

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions bin/queuePopulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const kafkaConfig = config.kafka;
const extConfigs = config.extensions;
const qpConfig = config.queuePopulator;
const mConfig = config.metrics;
const rConfig = config.redis;
const rLocalCacheConfig = config.localCache;
const QueuePopulator = require('../lib/queuePopulator/QueuePopulator');
const zookeeper = require('node-zookeeper-client');

Expand Down Expand Up @@ -48,8 +48,7 @@ function queueBatch(queuePopulator, taskState) {
/* eslint-enable no-param-reassign */

const queuePopulator = new QueuePopulator(zkConfig, kafkaConfig,
qpConfig, mConfig,
rConfig, extConfigs);
qpConfig, mConfig, rLocalCacheConfig, extConfigs);

const healthServer = new HealthProbeServer({
bindAddress: config.healthcheckServer.bindAddress,
Expand Down
8 changes: 8 additions & 0 deletions conf/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class Config extends EventEmitter {
{ host: '127.0.0.1', port: 6379 });
}

if (parsedConfig.localCache) {
this.localCache = {
host: config.localCache.host,
port: config.localCache.port,
password: config.localCache.password,
};
}

// config is validated, safe to assign directly to the config object
Object.assign(this, parsedConfig);

Expand Down
5 changes: 5 additions & 0 deletions conf/config.joi.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ const joiSchema = {
})
),
},
localCache: {
host: joi.string().default('localhost'),
port: joi.number().default(6379),
password: joi.string(),
},
healthcheckServer: joi.object({
bindAddress: joi.string().default('127.0.0.1'),
port: joi.number().default(4042),
Expand Down
4 changes: 4 additions & 0 deletions conf/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,5 +174,9 @@
"healthcheckServer": {
"bindAddress": "0.0.0.0",
"port": 4042
},
"localCache": {
"host": "127.0.0.1",
"port": 6379
}
}
9 changes: 9 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ if [[ "$REDIS_PORT" ]]; then
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .redis.port=\"$REDIS_PORT\""
fi

if [[ "$REDIS_LOCALCACHE_HOST" ]]; then
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .localCache.host=\"$REDIS_LOCALCACHE_HOST\""
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .localCache.port=6379"
fi

if [[ "$REDIS_LOCALCACHE_PORT" ]]; then
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .localCache.port=$REDIS_LOCALCACHE_PORT"
fi

if [[ "$QUEUE_POPULATOR_DMD_HOST" ]]; then
JQ_FILTERS_CONFIG="$JQ_FILTERS_CONFIG | .queuePopulator.dmd.host=\"$QUEUE_POPULATOR_DMD_HOST\""
fi
Expand Down
11 changes: 5 additions & 6 deletions lib/MetricsConsumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,21 @@ const CONCURRENCY = 10;
class MetricsConsumer {
/**
* @constructor
* @param {object} rConfig - redis configurations
* @param {string} rConfig.host - redis host
* @param {number} rConfig.port - redis port
* @param {object} rLocalCacheConfig - redis local cache configuration
* @param {string} rLocalCacheConfig.host - redis local cache host
* @param {number} rLocalCacheConfig.port - redis local cache port
* @param {object} mConfig - metrics configurations
* @param {string} mConfig.topic - metrics topic name
* @param {object} kafkaConfig - kafka configurations
* @param {string} kafkaConfig.hosts - kafka hosts
* as "host:port[/chroot]"
*/
constructor(rConfig, mConfig, kafkaConfig) {
constructor(rLocalCacheConfig, mConfig, kafkaConfig) {
this.mConfig = mConfig;
this.kafkaConfig = kafkaConfig;

this.logger = new Logger('Backbeat:MetricsConsumer');

const redisClient = new RedisClient(rConfig, this.logger);
const redisClient = new RedisClient(rLocalCacheConfig, this.logger);
this._statsClient = new StatsModel(redisClient, INTERVAL,
(EXPIRY + INTERVAL));
}
Expand Down
11 changes: 6 additions & 5 deletions lib/queuePopulator/QueuePopulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,18 @@ class QueuePopulator {
* configuration (mandatory if logSource is "mongo")
* @param {Object} mConfig - metrics configuration object
* @param {string} mConfig.topic - metrics topic
* @param {Object} rConfig - redis configuration object
* @param {Object} rLocalCacheConfig - redis local cache configuration
* @param {Object} extConfigs - configuration of extensions: keys
* are extension names and values are extension's config object.
* object
*/
constructor(zkConfig, kafkaConfig, qpConfig, mConfig, rConfig,
constructor(zkConfig, kafkaConfig, qpConfig, mConfig, rLocalCacheConfig,
extConfigs) {
this.zkConfig = zkConfig;
this.kafkaConfig = kafkaConfig;
this.qpConfig = qpConfig;
this.mConfig = mConfig;
this.rConfig = rConfig;
this.rLocalCacheConfig = rLocalCacheConfig;
this.extConfigs = extConfigs;

this.log = new Logger('Backbeat:QueuePopulator');
Expand Down Expand Up @@ -111,8 +112,8 @@ class QueuePopulator {

_setupMetricsClients(cb) {
// Metrics Consumer
this._mConsumer = new MetricsConsumer(this.rConfig, this.mConfig,
this.kafkaConfig);
this._mConsumer = new MetricsConsumer(this.rLocalCacheConfig,
this.mConfig, this.kafkaConfig);
this._mConsumer.start();

// Metrics Producer
Expand Down