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

CEXT-2009 Add New Relic support to aio CLI #311

Merged
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
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ $ aio runtime --help
* [`aio runtime namespace log-forwarding set adobe-io-runtime`](#aio-runtime-namespace-log-forwarding-set-adobe-io-runtime)
* [`aio runtime namespace log-forwarding set azure-log-analytics`](#aio-runtime-namespace-log-forwarding-set-azure-log-analytics)
* [`aio runtime namespace log-forwarding set splunk-hec`](#aio-runtime-namespace-log-forwarding-set-splunk-hec)
* [`aio runtime namespace log-forwarding set new-relic`](#aio-runtime-namespace-log-forwarding-set-new-relic)
* [`aio runtime package`](#aio-runtime-package)
* [`aio runtime package bind PACKAGENAME BINDPACKAGENAME`](#aio-runtime-package-bind-packagename-bindpackagename)
* [`aio runtime package create PACKAGENAME`](#aio-runtime-package-create-packagename)
Expand Down Expand Up @@ -1282,6 +1283,42 @@ ALIASES
$ aio rt ns lf set splunk-hec
```

## `aio runtime namespace log-forwarding set new-relic`

Set log forwarding destination to New Relic

```
USAGE
$ aio runtime namespace log-forwarding set new-relic --base-uri <value> --license-key <value> [--cert] [--key]
[--apiversion] [--apihost] [-u] [-i] [--debug <value>] [-v] [--version] [--help]

FLAGS
-i, --insecure bypass certificate check
-u, --auth whisk auth
-v, --verbose Verbose output
--apihost whisk API host
--apiversion whisk API version
--base-uri=<value> (optional) Base URI
--cert client cert
--debug=<value> Debug level output
--help Show help
--key client key
--license-key=<value> (required) License key
--version Show version

DESCRIPTION
Set log forwarding destination to New Relic

ALIASES
$ aio runtime ns log-forwarding set new-relic
$ aio runtime ns lf set new-relic
$ aio runtime namespace lf set new-relic
$ aio rt namespace log-forwarding set new-relic
$ aio rt namespace lf set new-relic
$ aio rt ns log-forwarding set new-relic
$ aio rt ns lf set new-relic
```

## `aio runtime package`

Manage your packages
Expand Down
56 changes: 56 additions & 0 deletions src/commands/runtime/namespace/log-forwarding/set/new-relic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2019 Adobe Inc. All rights reserved.
This file is licensed to you 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 REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const { Flags } = require('@oclif/core')
const RuntimeBaseCommand = require('../../../../../RuntimeBaseCommand')

class NewRelicCommand extends RuntimeBaseCommand {
async run () {
const { flags } = await this.parse(NewRelicCommand)
const ow = await this.wsk()
try {
await ow.logForwarding.setDestination('new_relic', {
base_uri: flags['base-uri'],
license_key: flags['license-key']
})
this.log('Log forwarding was set to new_relic for this namespace')
} catch (e) {
await this.handleError('failed to update log forwarding configuration', e)
}
}
}

NewRelicCommand.description = 'Set log forwarding destination to New Relic'

NewRelicCommand.flags = {
...RuntimeBaseCommand.flags,
'base-uri': Flags.string({
description: 'Base URI',
required: true
}),
'license-key': Flags.string({
description: 'License Key',
required: true
})
}

NewRelicCommand.aliases = [
'runtime:ns:log-forwarding:set:new-relic',
'runtime:ns:lf:set:new-relic',
'runtime:namespace:lf:set:new-relic',
'rt:namespace:log-forwarding:set:new-relic',
'rt:namespace:lf:set:new-relic',
'rt:ns:log-forwarding:set:new-relic',
'rt:ns:lf:set:new-relic'
]

module.exports = NewRelicCommand
4 changes: 4 additions & 0 deletions test/commands/runtime/namespace/log-forwarding/set.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const dataFixtures = [
port: 'port1',
index: 'index1',
hec_token: 'token1'
}],
['new_relic', {
base_uri: 'uri1',
license_key: 'key1'
}]
]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2019 Adobe Inc. All rights reserved.
This file is licensed to you 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 REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const RuntimeLib = require('@adobe/aio-lib-runtime')
const TheCommand = require('../../../../../../src/commands/runtime/namespace/log-forwarding/set/new-relic')
const { stdout } = require('stdout-stderr')

let command, rtLib
beforeEach(async () => {
command = new TheCommand([])
rtLib = await RuntimeLib.init({ apihost: 'fakehost', api_key: 'fakekey' })
})

test('set log forwarding settings to new_relic', () => {
return new Promise(resolve => {
const setCall = jest.fn()
rtLib.logForwarding.setDestination = setCall
command.argv = ['--base-uri', 'uri1', '--license-key', 'key1']
return command.run()
.then(() => {
expect(stdout.output).toMatch(/Log forwarding was set to new_relic for this namespace/)
expect(setCall).toBeCalledTimes(1)
expect(setCall).toHaveBeenCalledWith('new_relic', { base_uri: 'uri1', license_key: 'key1' })
resolve()
})
})
})

test('failed to set log forwarding settings to new_relic', async () => {
rtLib.logForwarding.setDestination = jest.fn().mockRejectedValue(new Error('mocked error'))
command.argv = ['--base-uri', 'uri1', '--license-key', 'key1']
await expect(command.run()).rejects.toThrow('failed to update log forwarding configuration: mocked error')
})