Skip to content

Commit

Permalink
Move endpoint to ARG, headers to flag
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack committed Dec 2, 2024
1 parent 5c3fd07 commit 8a47c34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
13 changes: 7 additions & 6 deletions packages/cli/src/commands/telemetry/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ export default class Add extends Command {

static flags = {
app: Flags.string({char: 'a', exactlyOne: ['app', 'space'], description: 'app to add a drain to'}),
headers: Flags.string({description: 'custom headers to configure the drain in json format'}),
space: Flags.string({char: 's', description: 'space to add a drain to'}),
signals: Flags.string({default: 'all', description: 'comma-delimited list of signals to collect (traces, metrics, logs). Use "all" to collect all signals.'}),
endpoint: Flags.string({required: true, description: 'drain url'}),
transport: Flags.string({required: true, options: ['http', 'grpc'], description: 'transport protocol for the drain'}),
transport: Flags.string({default: 'http', options: ['http', 'grpc'], description: 'transport protocol for the drain'}),
}

static args = {
headers: Args.string({required: true, description: 'custom headers to configure the drain in json format'}),
endpoint: Args.string({required: true, description: 'drain url'}),
}

static example = heredoc(`
Expand All @@ -27,8 +27,8 @@ export default class Add extends Command {

public async run(): Promise<void> {
const {flags, args} = await this.parse(Add)
const {app, space, signals, endpoint, transport} = flags
const {headers} = args
const {app, headers, space, signals, transport} = flags
const {endpoint} = args
let id
if (app) {
const {body: herokuApp} = await this.heroku.get<App>(
Expand All @@ -41,6 +41,7 @@ export default class Add extends Command {
id = herokuSpace.id
}

const exporterHeaders = headers || '{}'
const drainConfig = {
owner: {
type: app ? 'app' : 'space',
Expand All @@ -50,7 +51,7 @@ export default class Add extends Command {
exporter: {
endpoint,
type: `otlp${transport}`,
headers: JSON.parse(headers),
headers: JSON.parse(exporterHeaders),
},
}

Expand Down
28 changes: 11 additions & 17 deletions packages/cli/test/unit/commands/telemetry/add.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ describe('telemetry:add', function () {
it('returns an error if an app, remote, or space is not set', async function () {
try {
await runCommand(Cmd, [
testEndpoint,
'--headers',
'{"x-honeycomb-team": "your-api-key", "x-honeycomb-dataset": "your-dataset"}',
])
} catch (error) {
Expand All @@ -38,7 +40,7 @@ describe('telemetry:add', function () {
it('returns an error if values are provided for both the app and the space flags', async function () {
try {
await runCommand(Cmd, [
'{"x-honeycomb-team": "your-api-key", "x-honeycomb-dataset": "your-dataset"}',
testEndpoint,
'--app',
firApp.name || '',
'--space',
Expand All @@ -59,15 +61,13 @@ describe('telemetry:add', function () {
.reply(200, spaceTelemetryDrain1)

await runCommand(Cmd, [
testEndpoint,
'--headers',
'{"x-honeycomb-team": "your-api-key", "x-honeycomb-dataset": "your-dataset"}',
'--app',
appId,
'--signals',
'logs',
'--endpoint',
testEndpoint,
'--transport',
'http',
])

expectOutput(stdout.output, `successfully added drain ${testEndpoint}`)
Expand All @@ -82,15 +82,13 @@ describe('telemetry:add', function () {
.reply(200, spaceTelemetryDrain1)

await runCommand(Cmd, [
testEndpoint,
'--headers',
'{"x-honeycomb-team": "your-api-key", "x-honeycomb-dataset": "your-dataset"}',
'--space',
spaceId,
'--signals',
'logs',
'--endpoint',
testEndpoint,
'--transport',
'http',
])

expectOutput(stdout.output, `successfully added drain ${testEndpoint}`)
Expand All @@ -102,15 +100,13 @@ describe('telemetry:add', function () {
.reply(200, space)
try {
await runCommand(Cmd, [
testEndpoint,
'--headers',
'{"x-honeycomb-team": "your-api-key", "x-honeycomb-dataset": "your-dataset"}',
'--space',
spaceId,
'--signals',
'logs,foo',
'--endpoint',
testEndpoint,
'--transport',
'http',
])
} catch (error) {
const {message} = error as { message: string }
Expand All @@ -124,15 +120,13 @@ describe('telemetry:add', function () {
.reply(200, space)
try {
await runCommand(Cmd, [
testEndpoint,
'--headers',
'{"x-honeycomb-team": "your-api-key", "x-honeycomb-dataset": "your-dataset"}',
'--space',
spaceId,
'--signals',
'logs,all',
'--endpoint',
testEndpoint,
'--transport',
'http',
])
} catch (error) {
const {message} = error as { message: string }
Expand Down

0 comments on commit 8a47c34

Please sign in to comment.