Skip to content

🐛 improve poor performance of helm chart conversion - #1050

Merged
tmshort merged 1 commit into
operator-framework:mainfrom
joelanford:faster-helm-chart-generation
Jul 15, 2024
Merged

🐛 improve poor performance of helm chart conversion#1050
tmshort merged 1 commit into
operator-framework:mainfrom
joelanford:faster-helm-chart-generation

Conversation

@joelanford

@joelanfordjoelanford commented Jul 15, 2024

Copy link
Copy Markdown
Member

Description

A few ways that performance is improved:

  1. Remove the unnecessary storage abstraction. We can convert directly from the unpacked bundle FS.
  2. Use standard tooling from cli-runtime to parse manifests from the registry+v1 bundle (e.g. don't read file into buffer and then parse the buffer)
  3. Don't write to a plain FS and then turn around and immediately re-parse the plain FS. Skip the plain FS and generate the chart directly.
  4. Use JSON encoding rather than YAML encoding. The YAML encoding traverses JSON anyway, so this just removes an unnecessary step. Also, the Helm client has a performance benefit later by not having to convert YAML to JSON when reading the chart we generate.

Other ancillary changes:

  1. Put unpacked catalogs in a separate <cacheDir>/catalogs directory (rather than directly in <cacheDir>).
  2. Add debug logging and nanosecond-level granularity in log lines.
  3. Remove a bunch of unused code from rukpak (handlers, provisioners, storage implementations)

Motivation

Performance improvements of the reconcile function, and thus a more reactive system.

Locally, I noticed e2e drops from 323s to 231s.

Reviewer Checklist

  • API Go Documentation
  • Tests: Unit Tests (and E2E Tests, if appropriate)
  • Comprehensive Commit Messages
  • Links to related GitHub Issue(s)

@joelanford
joelanford requested a review from a team as a code ownerJuly 15, 2024 15:07
@openshift-merge-robotopenshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2024
@netlify

netlifyBot commented Jul 15, 2024

Copy link
Copy Markdown

👷 Deploy Preview for olmv1 processing.

NameLink
🔨 Latest commiteb5f63f
🔍 Latest deploy loghttps://app.netlify.com/sites/olmv1/deploys/66953b4dab6d1a00072d74f5

@netlify

netlifyBot commented Jul 15, 2024

Copy link
Copy Markdown

Deploy Preview for olmv1 ready!

NameLink
🔨 Latest commit67352d1
🔍 Latest deploy loghttps://app.netlify.com/sites/olmv1/deploys/66953f904f9d310008a7a462
😎 Deploy Previewhttps://deploy-preview-1050--olmv1.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@joelanford
joelanfordforce-pushed the faster-helm-chart-generation branch from eb5f63f to 5bd1eddCompareJuly 15, 2024 15:09
@openshift-merge-robotopenshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 15, 2024
@tmshort

Copy link
Copy Markdown
Contributor

And it already needs a rebase...

…lm chart conversion
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
@joelanford
joelanfordforce-pushed the faster-helm-chart-generation branch from 5bd1edd to 67352d1CompareJuly 15, 2024 15:26
@codecov

codecovBot commented Jul 15, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 68.85246% with 19 lines in your changes missing coverage. Please review.

Project coverage is 72.98%. Comparing base (ee7c35a) to head (67352d1).
Report is 3 commits behind head on main.

FilesPatch %Lines
internal/rukpak/convert/registryv1.go60.97%11 Missing and 5 partials ⚠️
cmd/manager/main.go50.00%2 Missing and 1 partial ⚠️
Additional details and impacted files
@@ Coverage Diff @@## main #1050 +/- ##
==========================================
- Coverage 73.46% 72.98% -0.48% 
==========================================
Files 32 28 -4 Lines 1986 1877 -109 ==========================================
- Hits 1459 1370 -89 - Misses 368 375 +7 + Partials 159 132 -27 
FlagCoverage Δ
e2e54.33% <68.85%> (-1.52%)⬇️
unit45.92% <9.83%> (+0.90%)⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tmshorttmshort left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few questions.

Comment threadcmd/manager/main.go
cl := mgr.GetClient()
catalogClient := catalogclient.New(cl, cache.NewFilesystemCache(cachePath, httpClient))
catalogsCachePath := filepath.Join(cachePath, "catalogs")
if err := os.MkdirAll(catalogsCachePath, 0700); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nothing that the previous mode (for bundles) was 0755, does this make a difference?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

It shouldn't. We don't expect any other users or groups to read these files.

*/
//nolint:unparam
func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alpha1.ClusterExtension) (ctrl.Result, error) {
l := log.FromContext(ctx)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you want to put the name of the ClusterExtension here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Possibly, also attach the V(1) to this. e.g.

Suggested change
l:=log.FromContext(ctx)
l:=log.FromContext(ctx).V(1).AddValues("ClusterExtension", ext.GetName())

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The name is already part of the context provided in the context that arrives from the caller of Reconcile.

I thought about using V(1), but that would mean that no logging (with that logger at least) could ever happen at the INFO level.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

I was going to suggest that I could do something like this:

l := log.FromContext(ctx)
debugLog := l.V(1)

But that would be misleading because levels build (i.e. .V(1).V(1) is equivalent to .V(2)), so if the caller set a .V(1) logger in the context, the this would suddenly not be a debug logger.

},
hash := sha256.Sum256(jsonData)
chrt.Templates = append(chrt.Templates, &chart.File{
Name: fmt.Sprintf("object-%x.json", hash[0:8]),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this enough of the hash? Should it be longer?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

We can make it longer, but I didn't change that aspect of this code. The name is the same as before except for .json instead of .yaml.

return nil, fmt.Errorf("read %q: %v", e.Name(), err)
defer func() {
if err := manifestFile.Close(); err != nil {
l.Error(err, "error closing file", "path", path)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This appears to be the only place l is used. Should l := log.FromContext(ctx) be moved down here for locality?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(or even into the WalkDir function?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

If we did that, we'd have to repeatedly ask the context for the same logger over and over. It feels better (to me at least) to get the "logger to be used in the scope of this function" once, right at the very beginning of the function.

return nil, err
}
for _, e := range entries {
if err := fs.WalkDir(rv1, manifestsDir, func(path string, e fs.DirEntry, err error) error {

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

There's another potential optimization here, where we spin up runtime.NumCPU goroutines and parse the files concurrently. But that can happen as a follow-up.

@tmshorttmshort left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/lgtm

@openshift-ciopenshift-ciBot added the lgtm Indicates that a PR is ready to be merged. label Jul 15, 2024
@tmshort
tmshort added this pull request to the merge queue Jul 15, 2024
Merged via the queue into operator-framework:main with commit bfc65eeJul 15, 2024
@joelanford
joelanford deleted the faster-helm-chart-generation branch July 15, 2024 17:27
perdasilva pushed a commit to LalatenduMohanty/operator-controller that referenced this pull request Aug 13, 2024
…lm chart conversion (operator-framework#1050)
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
perdasilva pushed a commit to kevinrizza/operator-controller that referenced this pull request Aug 13, 2024
…lm chart conversion (operator-framework#1050)
Signed-off-by: Joe Lanford <joe.lanford@gmail.com>
@skattojuskattoju mentioned this pull request Sep 25, 2024
4 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtmIndicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@joelanford@tmshort@openshift-merge-robot