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

Refactor all Get hydrates #167

Closed
wants to merge 4 commits into from

Conversation

japborst
Copy link
Contributor

There's a lot of duplication when hydrating the data. Likely from copy-pasting over time.

The aim of this PR is to decrease that for "get" hydrates.

Refactoring the list hydrates are a bit trickier, so I started out with just the gets. Lists can be done in a separate PR.

  • Refactor get hydrates into a single function
  • Always log upon hydrating

return nil, nil
}

func streamList(ctx context.Context, d *plugin.QueryData, item []interface{}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It would be nice to have this built into the SDK, similar to d.StreamListItem.

@cbruno10 cbruno10 self-requested a review June 20, 2022 16:00
@misraved
Copy link
Contributor

misraved commented Jun 20, 2022

Great work @japborst !!!

I had an initial pass at the changes and they look good. I will have a detailed look at it and provide feedback 👍 .

The idea of creating streamList function sounds interesting. Could you also create an issue in the SDK repo so that we could discuss more on it?

@japborst
Copy link
Contributor Author

japborst commented Jun 20, 2022

Thanks, @misraved. Looking forward to your comments.

Created the issue here turbot/steampipe-plugin-sdk#341.

@japborst japborst force-pushed the japborst/refactor-get branch from 8ee95e3 to 3683a9c Compare July 8, 2022 20:23
@japborst
Copy link
Contributor Author

japborst commented Jul 8, 2022

@misraved I noticed I missed a few use-cases. Should be complete now 👍

@japborst japborst force-pushed the japborst/refactor-get branch from 20481ba to ca4a396 Compare August 7, 2022 15:10
@github-actions
Copy link

github-actions bot commented Sep 9, 2022

'This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.'

@github-actions github-actions bot added the stale No recent activity has been detected on this issue/PR and it will be closed label Sep 9, 2022
@japborst
Copy link
Contributor Author

Not stale. Needs a review.

@github-actions github-actions bot removed the stale No recent activity has been detected on this issue/PR and it will be closed label Sep 15, 2022
@japborst
Copy link
Contributor Author

@cbruno10 what would you like to do with this PR?

@cbruno10
Copy link
Contributor

Hey @japborst , sorry for the long delay. It's still on our radar to review, but we have some other items we're focusing on right now, and due to its scope, I don't want to rush a review. I'd like to leave the PR open and review some time in the next few weeks.

@github-actions
Copy link

'This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.'

@github-actions github-actions bot added the stale No recent activity has been detected on this issue/PR and it will be closed label Nov 27, 2022
@misraved
Copy link
Contributor

Not stale. It will be reviewed shortly.

@misraved misraved removed the stale No recent activity has been detected on this issue/PR and it will be closed label Nov 28, 2022
@github-actions
Copy link

'This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.'

@github-actions github-actions bot added the stale No recent activity has been detected on this issue/PR and it will be closed label Jan 27, 2023
@misraved misraved removed the stale No recent activity has been detected on this issue/PR and it will be closed label Jan 30, 2023
@github-actions
Copy link

'This PR is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.'

@github-actions github-actions bot added the stale No recent activity has been detected on this issue/PR and it will be closed label Mar 31, 2023
@japborst
Copy link
Contributor Author

japborst commented Apr 6, 2023

Not stale

@e-gineer e-gineer removed the stale No recent activity has been detected on this issue/PR and it will be closed label Apr 6, 2023
@cbruno10
Copy link
Contributor

cbruno10 commented May 2, 2023

Hi @japborst , sorry it's taken so long to reply to this PR!

We've been deciding on what the GitHub plugin should look like, mainly around which API version should it use for its tables, and ultimately decided that we should update all tables to use the GitHub v4 GraphQL API. With this change, we will use a different Go SDK and the code structure itself will change, e.g.,

func tableGitHubOrganizationMemberList(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
client := connectV4(ctx, d)
quals := d.EqualsQuals
org := quals["organization"].GetStringValue()
pageSize := 100
limit := d.QueryContext.Limit
if limit != nil {
if *limit < int64(pageSize) {
pageSize = int(*limit)
}
}
variables := map[string]interface{}{
"login": githubv4.String(org),
"membersWithRolePageSize": githubv4.Int(pageSize),
"membersWithRoleCursor": (*githubv4.String)(nil), // Null after argument to get first page.
}
for {
err := client.Query(ctx, &query, variables)
if err != nil {
plugin.Logger(ctx).Error("github_organization_member", "api_error", err)
if strings.Contains(err.Error(), "Could not resolve to an Organization with the login of") {
return nil, nil
}
return nil, err
}
for _, member := range query.Organization.MembersWithRole.Edges {
d.StreamListItem(ctx, member)
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
if !query.Organization.MembersWithRole.PageInfo.HasNextPage {
break
}
variables["membersWithRoleCursor"] = githubv4.NewString(query.Organization.MembersWithRole.PageInfo.EndCursor)
}
return nil, nil
}
.

The new code should in theory be lighter than it is now, as we'll be requesting the exact fields for each resource, so the number of hydrate calls should decrease overall.

At this time, we most likely will not accept this PR, as I believe the GraphQL API changes will change the codebase in a significant way, but if these changes are applicable to the updated code in some way, we're happy to re-open and discuss more in this PR (or in a new one if easier).

@cbruno10 cbruno10 closed this May 2, 2023
@japborst
Copy link
Contributor Author

japborst commented May 2, 2023

Hey, thanks for the reply!

Using the GraphQL API makes a lot of sense. I really think you can get a big performance boost out of it, by reducing the number of calls to hydrate the data.

@cbruno10
Copy link
Contributor

cbruno10 commented May 2, 2023

@japborst Definitely, early tests are promising, so hoping we can get better performance so large queries and our mods will work smoother (rate limits are killer).

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.

4 participants