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

Add metrics CLI app 🚀 #6

Merged
merged 24 commits into from
Nov 23, 2023
Merged

Add metrics CLI app 🚀 #6

merged 24 commits into from
Nov 23, 2023

Conversation

hackebrot
Copy link
Member

The metrics CLI application enables us retrieve information for software delivery artifacts, such as:

  • GitHub Pull Requests (including ID, Number, Title, CreatedAt, MergedAt etc.)
  • GitHub Releases (including Name, TagName, IsPrerelease, PublishedAt etc.)
  • GitHub Deployments (including Description, LatestEnvironment, Commit, CreatedAt etc.)

I've added integration test coverage for all CLI commands.

This revision is what I demoed to you, @mtbottle @dlactin earlier this week.

I will create follow-up PRs for:

  • Parsing Pull Request Numbers for GitHub Releases from auto-generated release descriptions (so we can join PR info with the Release which included the PR and the Deployment which included it).
  • Querying the Grafana API for retrieving deployment information from Annotations.
  • Documentation for CLI app usage, testing and architecture.

@hackebrot hackebrot requested a review from a team November 16, 2023 11:48
@hackebrot hackebrot added feature New feature or request code quality CI, testing, linting etc. labels Nov 16, 2023
Copy link

@mtbottle mtbottle left a comment

Choose a reason for hiding this comment

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

Just a few non-blocking suggestions! I played around with the tool locally and it's really cool! :) I don't really know much Golang, but the code is understandable (even to me!) and seems well structured and well tested!

}

// QueryDeployments fetches information about Deployments from the GitHub GraphQL API
func QueryDeployments(gqlClient GraphQLClient, repo *Repo, limit int, envs *[]string) ([]Deployment, error) {

Choose a reason for hiding this comment

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

(non-blocking) Just a thought on maybe making the CLI tool more user friendly : instead of passing limit, maybe we can query by timeframe? That's a bit more understandable for human users than a "limit" (i.e. we usually want to get deployments starting at X time to Y time, rather than the last 100 deployments). Since we're paginating results anyways, it would be useful to do the filtering on something slightly more human understandable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, being able to filter on createdAt or mergedAt date times directly from the CLI would be nice! The GraphQL API doesn't support a date time range as an argument for pullRequests, releases, or deployments on the repository object: https://docs.github.com/en/graphql/reference/objects#repository

That operation is only supported by the search query: https://docs.github.com/en/graphql/reference/queries#search

The latter method does not seem to work on some of the repos we're interested in with Public Repositories (read-only) permissions. I created #7 and added a few ideas for how we can achieve this.

Comment on lines +52 to +62
deployments, err := github.QueryDeployments(gqlClient, repo, opts.Limit, opts.Environments)
if err != nil {
return err
}

exporter, err := f.NewExporter()
if err != nil {
return err
}

return exporter.Export(deployments)

Choose a reason for hiding this comment

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

If we are expecting potentially to query and aggregate a lot of data, then we might want to consider writing to file or emitting to console as we paginate over the API so that we don't blow up the memory usage on our machines. Some other advantage for streaming (as opposed to batch exporting) is that if we get some data corruption, we can also more easily start from the last good entry (rather than redownloading everything again).

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good idea! 👍🏻

@hackebrot hackebrot requested a review from dlactin November 21, 2023 11:45
return export.NewWriterExporter(os.Stdout, encoder)
}

f.NewGitHubHTTPClient = func() (*http.Client, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds reasonable! 👍🏻

f.NewGitHubHTTPClient = func() (*http.Client, error) {
token := config.FromEnv("GITHUB", "TOKEN")
if token == "" {
return nil, fmt.Errorf("Requires GitHub token to be set in env")
Copy link
Member

Choose a reason for hiding this comment

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

This will be covered by the upcoming docs and feels nitpicky, but it would be nice to print the full envvar we're looking for here too: RRM_METRICS__GITHUB__TOKEN

Copy link
Member Author

Choose a reason for hiding this comment

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

That's good feedback, @dlactin! I just pushed a commit to improve error reporting for this. Thanks!

@hackebrot hackebrot added this pull request to the merge queue Nov 23, 2023
Merged via the queue into main with commit 5d7df0e Nov 23, 2023
@hackebrot hackebrot deleted the add-metrics-cli-app branch November 23, 2023 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code quality CI, testing, linting etc. feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants