Skip to content

Commit

Permalink
add feature flag for health
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Phillips committed Aug 20, 2015
1 parent dba3d11 commit 347a4f5
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 23 deletions.
30 changes: 7 additions & 23 deletions agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,14 @@ local Confd = require('./confd')
local ConnectionStream = require('virgo/client/connection_stream').ConnectionStream
local MachineIdentity = require('virgo/machineidentity').MachineIdentity
local constants = require('./constants')
local deepCopyTable = require('virgo/util/misc').deepCopyTable
local endpoint = require('./endpoint')
local hostname = require('./hostname')
local logging = require('logging')
local misc = require('virgo/util/misc')
local ffi = require('ffi')
local certs = require('./certs')
local isStaging = require('./staging').isStaging

local FEATURE_UPGRADES = { name = 'upgrades', version = '1.0.0' }
local FEATURE_CONFD = { name = 'confd', version = '1.0.0' }

local FEATURES = {
FEATURE_UPGRADES,
FEATURE_CONFD
}
local features = require('./features')

local function loadFlock()
-- do not load on windows
Expand All @@ -66,7 +58,7 @@ function Agent:initialize(options, types)
self._upgradesEnabled = true
self._types = types or {}
self._confd = Confd:new(options.confdDir)
self._features = deepCopyTable(FEATURES)
self._features = features.get()
end

function Agent:start(options)
Expand Down Expand Up @@ -126,19 +118,6 @@ end

function Agent:connect(callback)
local endpoints = self._config['endpoints']
local upgradeStr = self._config['upgrade']
if upgradeStr then
upgradeStr = upgradeStr:lower()
if upgradeStr == 'false' or upgradeStr == 'disabled' then
self._upgradesEnabled = false
for i, v in ipairs(self._features) do
if v.name == FEATURE_UPGRADES.name then
table.remove(self._features, i)
break
end
end
end
end

if #endpoints <= 0 then
logging.error('no endpoints')
Expand Down Expand Up @@ -250,6 +229,11 @@ function Agent:_preConfig(callback)
self._config['token'] = misc.trim(self._config['token'])
self._config['id'] = misc.trim(self._config['id'])

-- Disable Features
features.disableWithOption(self._config['upgrade'], 'upgrades', true)
features.disableWithOption(self._config['health'], 'health')
self._features = features.get()

async.series({
-- retrieve xen id
function(callback)
Expand Down
57 changes: 57 additions & 0 deletions features.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
--[[
Copyright 2015 Rackspace
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS-IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
--]]
local FEATURE_UPGRADES = { name = 'upgrades', version = '1.0.0' }
local FEATURE_CONFD = { name = 'confd', version = '1.0.0' }
local FEATURE_HEALTH = { name = 'health', version = '1.0.0' }

local FEATURES = {
FEATURE_UPGRADES,
FEATURE_CONFD,
FEATURE_HEALTH
}

local function disable(name, remove)
for i, v in pairs(FEATURES) do
if v.name == name then
if remove then
table.remove(FEATURES, i)
else
v.disabled = true
end
break
end
end
end

local function get(name)
if not name then return FEATURES end
for _, v in pairs(FEATURES) do
if v.name == name then return v end
end
return
end

local function disableWithOption(option, name, remove)
if not option then return end
option = option:lower()
if option == 'disabled' or option == 'false' then
disable(name, remove)
end
end

exports.get = get
exports.disable = disable
exports.disableWithOption = disableWithOption
1 change: 1 addition & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ local function start(...)
virgo.config['proxy'] = virgo.config['monitoring_proxy_url']
virgo.config['insecure'] = virgo.config['monitoring_insecure']
virgo.config['debug'] = virgo.config['monitoring_debug']
virgo.config['health'] = virgo.config['monitoring_health']

-- Set debug logging based on the config file
if virgo.config['debug'] == 'true' then
Expand Down
19 changes: 19 additions & 0 deletions tests/test-agent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,23 @@ require('tap')(function(test)
end
})
end)

test('test features (get)', function()
local features = require('../features')
assert(#features.get() > 0)
end)

test('test features (disable)', function()
local features = require('../features')
features.disable('health')
assert(features.get('health').disabled)
end)

test('test features (disable+remove)', function()
local features = require('../features')
p('before', features.get())
features.disable('upgrades', true)
assert(not features.get('upgrades'))
p(features.get())
end)
end)

0 comments on commit 347a4f5

Please sign in to comment.