adobe / semantic-release-coralogix

Automatically tag semantic releases in Coralogix
Apache License 2.0
0 stars 8 forks source link

Tagging and release fails if Coralogix account has no Parsing Rules #87

Open alexkli opened 1 year ago

alexkli commented 1 year ago

Description Tagging and subsequently an entire release fails if the Coralogix account used has no Parsing Rules.

This is because the verifytoken check makes a test request to the Coralogix Rules API at /api/v1/external/rules which returns the Parsing Rules to see if the configured api key is valid, before actually making the tagging request. However, in case of no parsing rules in the account, this API will return a 404 and the current plugin code will treat any !response.ok case as invalid api key and abort the tagging and thus the release.

To Reproduce Steps to reproduce the behavior:

  1. Have a coralogix account with no parsing rules
  2. Configure a semantic release with the @adobe/semantic-release-coralogix plugin and an api key from that coralogix account
  3. Trigger a release
  4. Release fails with Error: Invalid API key, see full output below
[10:40:57 PM] [semantic-release] [@semantic-release/github] › ℹ  Verify GitHub authentication
[10:40:57 PM] [semantic-release] › ✔  Completed step "verifyConditions" of plugin "@semantic-release/github"
[10:40:57 PM] [semantic-release] › ✖  An error occurred while running semantic-release: Error: Invalid API key
    at verifytoken (/home/circleci/repo/node_modules/@adobe/semantic-release-coralogix/src/coralogix-tagger.js:68:11)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async verify (/home/circleci/repo/node_modules/@adobe/semantic-release-coralogix/src/verify.js:19:5)
    at async validator (/home/circleci/repo/node_modules/semantic-release/lib/plugins/normalize.js:34:24)
    at async /home/circleci/repo/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
    at async Promise.all (index 0)
    at async next (/home/circleci/repo/node_modules/p-reduce/index.js:16:18) {
  pluginName: '@adobe/semantic-release-coralogix'
}
AggregateError: 
    Error: Invalid API key
        at verifytoken (/home/circleci/repo/node_modules/@adobe/semantic-release-coralogix/src/coralogix-tagger.js:68:11)
        at processTicksAndRejections (node:internal/process/task_queues:96:5)
        at async verify (/home/circleci/repo/node_modules/@adobe/semantic-release-coralogix/src/verify.js:19:5)
        at async validator (/home/circleci/repo/node_modules/semantic-release/lib/plugins/normalize.js:34:24)
        at async /home/circleci/repo/node_modules/semantic-release/lib/plugins/pipeline.js:37:34
        at async Promise.all (index 0)
        at async next (/home/circleci/repo/node_modules/p-reduce/index.js:16:18)
    at /home/circleci/repo/node_modules/semantic-release/lib/plugins/pipeline.js:54:11
    at async Object.pluginsConf.<computed> [as verifyConditions] (/home/circleci/repo/node_modules/semantic-release/lib/plugins/index.js:80:11)
    at async run (/home/circleci/repo/node_modules/semantic-release/index.js:103:3)
    at async module.exports (/home/circleci/repo/node_modules/semantic-release/index.js:269:22)
    at async module.exports (/home/circleci/repo/node_modules/semantic-release/cli.js:55:5)

Exited with code exit status 1
CircleCI received exit code 1

Expected behavior Tagging and release works even if the coralogix account happens to have no parsing rules. Which might be at least true during initial setup when first trying to setup and use this plugin.

Version: @adobe/semantic-release-coralogix version 1.1.23

Additional context I manually tested the Rules API to verify this.

With no parsing rules in the account, I get a 404. If I add one (inactive) rule, I get 200 with the right api key.

Workaround

Create a mock parsing rule in the account (through the UI) and set it as "inactive". This way it has no impact on the log ingestion but makes the rules api return 200.

alexkli commented 1 year ago

Ideas

  1. You could check for only 401 and 403 in the response in verifytoken
    if ([401, 403].includes(response.status)) {
  2. You could just handle 404 differently
    if (!response.ok && response.status != 404) {
  3. Use a different API for the validation that doesn't have a 404 issue for "empty" content aka new accounts