Skip to content

Commit

Permalink
Add test for grpc telemetry drain
Browse files Browse the repository at this point in the history
  • Loading branch information
eablack committed Jan 16, 2025
1 parent 98dd02e commit 94b4018
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
16 changes: 15 additions & 1 deletion packages/cli/test/fixtures/telemetry/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,25 @@ export const appTelemetryDrain2: TelemetryDrain = {
owner: {id: '87654321-5717-4562-b3fc-2c963f66afa6', type: 'app', name: 'myapp'},
signals: ['logs'],
exporter: {
type: 'otlphttp',
type: 'otlp',
endpoint: 'https://api.papertrail.com/',
headers: {
'x-papertrail-team': 'your-api-key',
'x-papertrail-dataset': 'your-dataset',
},
},
}

export const grpcAppTelemetryDrain: TelemetryDrain = {
id: '3fa85f64-5717-4562-b3fc-2c963f66afa6',
owner: {id: '745c1486-ad78-4de7-8da7-20d4f8b15b71', type: 'app', name: 'myapp'},
signals: ['traces', 'metrics', 'logs'],
exporter: {
type: 'otlp',
endpoint: 'https://api.honeycomb.io/',
headers: {
'x-honeycomb-team': 'your-api-key',
'x-honeycomb-dataset': 'your-dataset',
},
},
}
33 changes: 32 additions & 1 deletion packages/cli/test/unit/commands/telemetry/add.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import runCommand from '../../../helpers/runCommand'
import {expect} from 'chai'
import * as nock from 'nock'
import expectOutput from '../../../helpers/utils/expectOutput'
import {spaceTelemetryDrain1, appTelemetryDrain1} from '../../../fixtures/telemetry/fixtures'
import {spaceTelemetryDrain1, appTelemetryDrain1, grpcAppTelemetryDrain} from '../../../fixtures/telemetry/fixtures'
import {firApp} from '../../../fixtures/apps/fixtures'
import * as spaceFixtures from '../../../fixtures/spaces/fixtures'
import {SpaceWithOutboundIps} from '../../../../src/lib/types/spaces'

const appId = appTelemetryDrain1.owner.id
const grpcDrainAppId = grpcAppTelemetryDrain.owner.id
const spaceId = spaceTelemetryDrain1.owner.id
const testEndpoint = appTelemetryDrain1.exporter.endpoint

Expand Down Expand Up @@ -133,4 +134,34 @@ describe('telemetry:add', function () {
expect(message).to.contain('Invalid signal option: logs,all. Run heroku telemetry:add --help to see signal options.')
}
})

it('successfully creates a telemetry drain for an app with grpc', async function () {
nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.get(`/apps/${grpcDrainAppId}`)
.reply(200, firApp)
nock('https://api.heroku.com', {reqheaders: {Accept: 'application/vnd.heroku+json; version=3.sdk'}})
.post('/telemetry-drains', {
owner: {
type: 'app',
id: grpcDrainAppId,
},
signals: ['traces', 'metrics', 'logs'],
exporter: {
endpoint: testEndpoint,
type: 'otlp',
headers: {},
},
})
.reply(200, spaceTelemetryDrain1)

await runCommand(Cmd, [
testEndpoint,
'--app',
grpcDrainAppId,
'--transport',
'grpc',
])

expectOutput(stdout.output, `successfully added drain ${testEndpoint}`)
})
})

0 comments on commit 94b4018

Please sign in to comment.