diff --git a/CHANGELOG.md b/CHANGELOG.md index a8eec845ba..16097a26b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Changelog ## [Unreleased] +- Add sdkVersion in client registration ## 3.0.0-alpha.1 - upgrade unleash-frontend to 3.0.0-alpha.1 diff --git a/docs/api/client/metrics-api.md b/docs/api/client/metrics-api.md index 86af96598d..fd82b94da8 100644 --- a/docs/api/client/metrics-api.md +++ b/docs/api/client/metrics-api.md @@ -1,30 +1,5 @@ # This document describes the client metrics endpoints -### Client registration - -`POST: http://unleash.host.com/api/client/register` - -Register a client instance with the unleash server. The client should send all fields specified. - -```json -{ - "appName": "appName", - "instanceId": "instanceId", - "strategies": ["default", "some-strategy-1"], - "started": "2016-11-03T07:16:43.572Z", - "interval": 10000, -} -``` - - -**Fields:** - -* **appName** - Name of the application seen by unleash-server -* **instanceId** - Instance id for this application (typically hostname, podId or similar) -* **strategies** - List of strategies implemented by this application -* **started** - When this client started. Should be reported as UTC time. -* **interval** - At wich interval will this client be expected to send metrics? - ### Send metrics `POST http://unleash.host.com/api/client/metrics` diff --git a/docs/api/client/register-api.md b/docs/api/client/register-api.md new file mode 100644 index 0000000000..6c8ad8073f --- /dev/null +++ b/docs/api/client/register-api.md @@ -0,0 +1,28 @@ +# This document describes the client registration endpoints + +### Client registration + +`POST: http://unleash.host.com/api/client/register` + +Register a client instance with the unleash server. The client should send all fields specified. + +```json +{ + "appName": "appName", + "instanceId": "instanceId", + "sdkVersion": "unleash-client-java:2.2.0", + "strategies": ["default", "some-strategy-1"], + "started": "2016-11-03T07:16:43.572Z", + "interval": 10000 +} +``` + + +**Fields:** + +* **appName** - Name of the application seen by unleash-server +* **instanceId** - Instance id for this application (typically hostname, podId or similar) +* **sdkVersion** - Optional field that describes the sdk version (name:version) +* **strategies** - List of strategies implemented by this application +* **started** - When this client started. Should be reported as UTC time. +* **interval** - At wich interval will this client be expected to send metrics? diff --git a/lib/db/client-instance-store.js b/lib/db/client-instance-store.js index 6d17af88cf..61d417c5ea 100644 --- a/lib/db/client-instance-store.js +++ b/lib/db/client-instance-store.js @@ -5,6 +5,7 @@ const logger = require('../logger'); const COLUMNS = [ 'app_name', 'instance_id', + 'sdk_version', 'client_ip', 'last_seen', 'created_at', @@ -14,6 +15,7 @@ const TABLE = 'client_instances'; const mapRow = row => ({ appName: row.app_name, instanceId: row.instance_id, + sdkVersion: row.sdk_version, clientIp: row.client_ip, lastSeen: row.last_seen, createdAt: row.created_at, @@ -48,6 +50,7 @@ class ClientInstanceStore { .update({ last_seen: 'now()', client_ip: details.clientIp, + sdk_version: details.sdkVersion, }); } @@ -55,6 +58,7 @@ class ClientInstanceStore { return this.db(TABLE).insert({ app_name: details.appName, instance_id: details.instanceId, + sdk_version: details.sdkVersion, client_ip: details.clientIp, }); } diff --git a/lib/routes/client-api/metrics-schema.js b/lib/routes/client-api/metrics-schema.js index 548b70bc7b..12dedc6262 100644 --- a/lib/routes/client-api/metrics-schema.js +++ b/lib/routes/client-api/metrics-schema.js @@ -12,12 +12,4 @@ const clientMetricsSchema = joi.object().keys({ }), }); -const clientRegisterSchema = joi.object().keys({ - appName: joi.string().required(), - instanceId: joi.string().required(), - strategies: joi.array().required().items(joi.string(), joi.any().strip()), - started: joi.date().required(), - interval: joi.number().required(), -}); - -module.exports = { clientMetricsSchema, clientRegisterSchema }; +module.exports = { clientMetricsSchema }; diff --git a/lib/routes/client-api/register-schema.js b/lib/routes/client-api/register-schema.js new file mode 100644 index 0000000000..e133e03598 --- /dev/null +++ b/lib/routes/client-api/register-schema.js @@ -0,0 +1,14 @@ +'use strict'; + +const joi = require('joi'); + +const clientRegisterSchema = joi.object().keys({ + appName: joi.string().required(), + instanceId: joi.string().required(), + sdkVersion: joi.string().optional(), + strategies: joi.array().required().items(joi.string(), joi.any().strip()), + started: joi.date().required(), + interval: joi.number().required(), +}); + +module.exports = { clientRegisterSchema }; diff --git a/lib/routes/client-api/register.js b/lib/routes/client-api/register.js index 0b4536acdb..034a95c5aa 100644 --- a/lib/routes/client-api/register.js +++ b/lib/routes/client-api/register.js @@ -4,7 +4,7 @@ const { Router } = require('express'); const joi = require('joi'); const logger = require('../../logger'); -const { clientRegisterSchema } = require('./metrics-schema'); +const { clientRegisterSchema } = require('./register-schema'); exports.router = config => { const { clientInstanceStore, clientApplicationsStore } = config.stores; diff --git a/lib/routes/client-api/register.test.js b/lib/routes/client-api/register.test.js index 5ba4f91e80..913e73879c 100644 --- a/lib/routes/client-api/register.test.js +++ b/lib/routes/client-api/register.test.js @@ -28,6 +28,22 @@ function getSetup() { } test('should register client', t => { + t.plan(0); + const { request } = getSetup(); + return request + .post('/api/client/register') + .send({ + appName: 'demo', + instanceId: 'test', + strategies: ['default'], + sdkVersion: 'unleash-client-test:1.2', + started: Date.now(), + interval: 10, + }) + .expect(202); +}); + +test('should register client without sdkVersin', t => { t.plan(0); const { request } = getSetup(); return request diff --git a/migrations/20170628205541-add-sdk-version-to-client-instances.js b/migrations/20170628205541-add-sdk-version-to-client-instances.js new file mode 100644 index 0000000000..527a9e2cca --- /dev/null +++ b/migrations/20170628205541-add-sdk-version-to-client-instances.js @@ -0,0 +1,15 @@ +'use strict'; + +exports.up = function(db, callback) { + db.runSql( + 'ALTER TABLE client_instances ADD "sdk_version" varchar(255);', + callback + ); +}; + +exports.down = function(db, callback) { + db.runSql( + 'ALTER TABLE client_instances DROP COLUMN "sdk_version";', + callback + ); +};