-
Notifications
You must be signed in to change notification settings - Fork 1
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
Conversation
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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! 👍🏻
return export.NewWriterExporter(os.Stdout, encoder) | ||
} | ||
|
||
f.NewGitHubHTTPClient = func() (*http.Client, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need to add GitHub app auth if we want to run this regularly against our repos.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds reasonable! 👍🏻
metrics/internal/factory/factory.go
Outdated
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
The metrics CLI application enables us retrieve information for software delivery artifacts, such as:
ID
,Number
,Title
,CreatedAt
,MergedAt
etc.)Name
,TagName
,IsPrerelease
,PublishedAt
etc.)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: