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

Validate that telemetry definitions are ordered alphabetically; Reorder the current file #705

Merged
merged 8 commits into from
Mar 6, 2024

Conversation

awschristou
Copy link
Contributor

Problem

Metrics are defined in haphazard order in the telemetry definitions file. This makes it challenging to locate entries, particularly those sharing a common prefix. Maintaining sorted lists also makes it easier to reason about entries being added or modified, without having to think about their location.

Solution

Scripting has been created to:

  • test that the definition file is arranged in alphabetical order
  • automatically rearrange the file's entries in alphabetical order

A CI job has been set up to run the validation check during PRs

This change was not wired up as a commit hook, because the repo does not have a top level node project. The CI job, and the readme are the mechanisms used to maintain the file going forward.

I chose not to use eslint. I started out in that direction, but it was becoming more of a distraction from the problem being solved. From https://github.com/azeemba/eslint-plugin-json?tab=readme-ov-file#is-eslint-really-the-best-tool-to-lint-my-json:

Is eslint really the best tool to lint my JSON?
Not really. eslint plugin interface wasn't designed to lint a completely different language but its interface is flexible enough to allow it. So this plugin is certainly unusual.

I ran the fix script against the current definitions file. This PR also contains that change as a separate commit.

To verify this change, I ran the new fix script on the current telemetry file. I then hand sorted the same file, and verified that the resulting file matched what the script produced.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@awschristou awschristou requested a review from a team as a code owner February 29, 2024 23:59
@@ -0,0 +1,26 @@
name: Lint Telemetry Definitions
Copy link
Contributor

@justinmk3 justinmk3 Mar 1, 2024

Choose a reason for hiding this comment

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

could be just "Lint", all linting can be in one CI place

Suggested change
name: Lint Telemetry Definitions
name: Lint

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to parallelize all of the linting, having each job focus on its own domain. We only have the one thing being linted in CI, and it's easy to change course though. Let's leave it as-is for now.

await saveTelemetryDefinitions(definitions, jsonPath)
}

export function fix(definitions: TelemetryDefinitions): void {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we're re-inventing eslint. We should probably implement this as an eslint plugin, otherwise it's a novel system that others must learn, for not much reason.

vscode toolkit has custom eslint plugins here: https://github.com/aws/aws-toolkit-vscode/tree/master/plugins/eslint-plugin-aws-toolkits

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apparently its a little different to make eslint rules on json. I started out that way, and opted to just write pure scripts.


if (inputMetric.name != sortedName) {
validations.push(`Telemetry Metrics are not sorted. Expected: ${sortedName}, Found: ${inputMetric.name}`)
break
Copy link
Contributor

Choose a reason for hiding this comment

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

should we post msg that they can fix by command?
perhaps adding run npm run fix

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh my bad.. I see it's already added in final msg

Copy link
Contributor

@justinmk3 justinmk3 left a comment

Choose a reason for hiding this comment

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

This still seems a bit over-engineered. A validation script shouldn't need a package.json, it could be plain javascript. This will add a dependency-maintenance cost too, besides the more general risk that it's another project that will accumulate quirks and hidden corners.

eslint plugins do require a sub-project. But with this solution we're gaining a project but not gaining eslint :/ (Assuming that eslint is even needed; if we are only "linting" json we don't need eslint, or a test framework...)

@awschristou awschristou merged commit ec38b82 into main Mar 6, 2024
8 checks passed
@awschristou awschristou deleted the awschristou/telemetry-def-lint branch March 6, 2024 00:42
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.

3 participants