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

feat(cli): Add a CLI to build deep-links to Central ELK #36

Merged
merged 11 commits into from
Dec 19, 2023
Merged

Conversation

akash1810
Copy link
Member

@akash1810 akash1810 commented Dec 12, 2023

What does this change?

Adds a (Deno) CLI tool to build a deep-link to Central ELK, and open it in user's browser.

How to test

  • Checkout the branch
  • From the cli directory, run deno task demo to view the logs for Riff-Raff PROD
  • OR from the cli directory, run deno run main.ts --help and follow the instructions
  • To run the binary, from the cli directory, run deno task compile then run ./dist/devx-logs --help and follow the instructions

Notes

We don't yet have a defined vulnerability scanning story for the Deno ecosystem, so I've deliberately opted to use the standard library, and no third-party dependencies (cc @guardian/devx-security).

@akash1810 akash1810 force-pushed the aa/cli branch 5 times, most recently from 7742d51 to 6f5f177 Compare December 12, 2023 23:36
Adds a (Deno) CLI tool to build a deep-link to Central ELK,
and open it in user's browser.
@akash1810 akash1810 force-pushed the aa/cli branch 7 times, most recently from 516affe to e87a6cb Compare December 13, 2023 08:40
akash1810 added a commit to guardian/homebrew-devtools that referenced this pull request Dec 13, 2023
@akash1810 akash1810 force-pushed the aa/cli branch 2 times, most recently from de07cae to 2fbfc97 Compare December 13, 2023 09:06
akash1810 added a commit to guardian/homebrew-devtools that referenced this pull request Dec 13, 2023
@akash1810 akash1810 marked this pull request as ready for review December 13, 2023 11:01
@akash1810 akash1810 requested a review from a team as a code owner December 13, 2023 11:01
cli/deno.json Outdated
@@ -0,0 +1,6 @@
{
"tasks": {
"compile": "deno compile --allow-run=open --target aarch64-apple-darwin --output dist/devx-logs index.ts",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only compile for M series macs, because as a department, that's what we use for local development.

Copy link
Member Author

@akash1810 akash1810 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resulting binary is pretty big for what it does (>100MB). We could use bash instead of Deno, however we'd lose type-safety etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the Deno runtime has to be shipped within the binary. Can't be helped unfortunately (:

Copy link
Member

@AshCorr AshCorr Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're compiling to a specific arch anyway, is it worth using a compiled language like Rust or Go instead? Would likely cut down on the runtime size significantly.

Or compile to JS and run with the users existing node binaries?

Copy link
Member Author

@akash1810 akash1810 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're compiling to a specific arch anyway, is it worth using a compiled language like Rust or Go instead? Would likely cut down on the runtime size significantly.

Chose TS on the assumption that it's the most familiar across the department (other than possibly Scala). If we move to JS, we could probably distribute this via NPM, rather than homebrew?

WDYT?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't worked with it much, but deno install could be a nice middle-ground, which wouldn't require much change to the code? https://docs.deno.com/runtime/manual/tools/script_installer

Copy link

@marsavar marsavar Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryophyta my understanding is that install would create a script that invokes the CLI using deno. That means that people would have to have deno installed in order to run the CLI, since the runtime is not included.
I don't think we should require people to install additional software when running CLIs (which is why I'm personally averse to CLIs that need, for example, the JVM to run). I would rather have a 100MB standalone executable that's easy to distribute - I don't see it as different from a huge Electron app (which we've pretty much accepted as the norm).
As Ash says, there are languages there are better suited to writing CLIs, but Deno is a good compromise imho, since TypeScript is pretty much understood by everyone at the G.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We distribute our dev tooling via homebew. I'd be keen for this to also be distributed the same way, to reduce cognitive load. Homebrew formulae supports the idea of dependencies, so we could craft this such that the raw TS files form the Homebrew artifact, and we have a dependency on Deno. Theoretically this would provide the same benefit as distributing a binary - the reduction of "works on my machine" symptoms.

I'd suggest we ship as is, and revise our approach once we understand what to optimise for (disk usage, performance, maintainability, etc.). Our work laptops have quite a lot of storage (1TB), and I'd be surprised if ~100MB is noticeable.

WDYT?

cli/deno.lock Outdated Show resolved Hide resolved
cli/index.ts Outdated Show resolved Hide resolved
cli/index.ts Outdated Show resolved Hide resolved
cli/index.ts Outdated Show resolved Hide resolved
cli/index.ts Outdated Show resolved Hide resolved
@akash1810 akash1810 force-pushed the aa/cli branch 3 times, most recently from 4193945 to ef05394 Compare December 13, 2023 18:31
@mchv
Copy link
Member

mchv commented Dec 14, 2023

@akash1810 I think you may be missing changing SKIP_NODE to true in snyk.yml to have the client code scanned.

@akash1810
Copy link
Member Author

akash1810 commented Dec 14, 2023

@akash1810 I think you may be missing changing SKIP_NODE to true in snyk.yml to have the client code scanned.

This CLI is written with Deno, rather than Node. AFAICT Deno isn't yet supported by Snyk.

This'll allow `main.ts` to be unit tested.
@akash1810 akash1810 enabled auto-merge December 15, 2023 10:18
export function removeUndefined(
obj: Record<string, string | undefined>,
): Record<string, string> {
return Object.entries(obj).filter(([, value]) => !!value).reduce(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would stop you for filtering for any values that are 0?

!!0 == false
!!1 == true

Copy link
Member Author

@akash1810 akash1810 Dec 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're correct, however removeUndefined takes a string, and !!"0" is true... because JavaScript...

image

I've added a unit test for this now too - 824038d.

@akash1810 akash1810 disabled auto-merge December 19, 2023 11:13
@akash1810 akash1810 merged commit 8a3cc09 into main Dec 19, 2023
3 checks passed
@akash1810 akash1810 deleted the aa/cli branch December 19, 2023 11:25
akash1810 added a commit to guardian/homebrew-devtools that referenced this pull request Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants