-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add telemetry:update, change capabilities to signals * Add test for telemetry:update, fix grpc spelling, display drain after update * Clarify description of what gets changed * Add examples, switch signal to signals
- Loading branch information
Showing
11 changed files
with
218 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,6 @@ Gdvb | |
getreqs | ||
Ghpcy | ||
githuborg | ||
gprc | ||
hamurai | ||
herokai | ||
herokuapp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import {flags as Flags, Command} from '@heroku-cli/command' | ||
import {Args, ux} from '@oclif/core' | ||
import {TelemetryDrain, TelemetryDrainWithOptionalKeys, TelemetryExporterWithOptionalKeys} from '../../lib/types/telemetry' | ||
import heredoc from 'tsheredoc' | ||
import {displayTelemetryDrain, validateAndFormatSignals} from '../../lib/telemetry/util' | ||
|
||
export default class Update extends Command { | ||
static topic = 'telemetry' | ||
static description = 'updates a telemetry drain with provided attributes (attributes not provided remain unchanged)' | ||
static args = { | ||
telemetry_drain_id: Args.string({required: true, description: 'ID of the drain to update'}), | ||
headers: Args.string({description: 'custom headers to configure the drain in json format'}), | ||
} | ||
|
||
static flags = { | ||
signals: Flags.string({description: 'comma-delimited list of signals to collect (traces, metrics, logs). Use "all" to collect all signals.'}), | ||
endpoint: Flags.string({description: 'drain url'}), | ||
transport: Flags.string({options: ['http', 'grpc'], description: 'transport protocol for the drain'}), | ||
} | ||
|
||
static example = heredoc(` | ||
$ heroku telemetry:update acde070d-8c4c-4f0d-9d8a-162843c10333 --signals logs,metrics --endpoint https://my-new-endpoint.com | ||
`) | ||
|
||
public async run(): Promise<void> { | ||
const {args, flags} = await this.parse(Update) | ||
const {telemetry_drain_id, headers} = args | ||
const {signals, endpoint, transport} = flags | ||
if (!(headers || signals || endpoint || transport)) { | ||
ux.error(heredoc(` | ||
Requires either --signals, --endpoint, --transport or HEADERS to be provided. | ||
See more help with --help | ||
`)) | ||
} | ||
|
||
const drainConfig: TelemetryDrainWithOptionalKeys = {} | ||
if (signals) { | ||
drainConfig.signals = validateAndFormatSignals(signals) | ||
} | ||
|
||
if (headers || endpoint || transport) { | ||
const exporter: TelemetryExporterWithOptionalKeys = {} | ||
if (headers) { | ||
exporter.headers = JSON.parse(headers) | ||
} | ||
|
||
if (endpoint) { | ||
exporter.endpoint = endpoint | ||
} | ||
|
||
if (transport) { | ||
exporter.type = `otlp${transport}` | ||
} | ||
|
||
drainConfig.exporter = exporter | ||
} | ||
|
||
ux.action.start(`Updating telemetry drain ${telemetry_drain_id}`) | ||
const {body: telemetryDrain} = await this.heroku.patch<TelemetryDrain>(`/telemetry-drains/${telemetry_drain_id}`, { | ||
headers: { | ||
Accept: 'application/vnd.heroku+json; version=3.sdk', | ||
}, | ||
body: drainConfig, | ||
}) | ||
ux.action.stop() | ||
|
||
displayTelemetryDrain(telemetryDrain) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {ux} from '@oclif/core' | ||
import {TelemetryDrain} from '../types/telemetry' | ||
|
||
export function validateAndFormatSignals(signalInput: string | undefined): string[] { | ||
const signalOptions = ['traces', 'metrics', 'logs'] | ||
if (!signalInput || signalInput === 'all') return signalOptions | ||
const signalArray = signalInput.split(',') | ||
signalArray.forEach(signal => { | ||
if (!signalOptions.includes(signal)) { | ||
ux.error(`Invalid signal option: ${signalArray}. Run heroku telemetry:add --help to see signal options.`, {exit: 1}) | ||
} | ||
}) | ||
return signalArray | ||
} | ||
|
||
export function displayTelemetryDrain(telemetryDrain: TelemetryDrain) { | ||
ux.styledHeader(telemetryDrain.id) | ||
const drainType = telemetryDrain.owner.type.charAt(0).toUpperCase() + telemetryDrain.owner.type.slice(1) | ||
ux.styledObject({ | ||
[drainType]: telemetryDrain.owner.name, | ||
Signals: telemetryDrain.signals.join(', '), | ||
Endpoint: telemetryDrain.exporter.endpoint, | ||
Kind: telemetryDrain.exporter.type, | ||
Headers: telemetryDrain.exporter.headers, | ||
}, ['App', 'Space', 'Signals', 'Endpoint', 'Kind', 'Headers']) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.