-
Notifications
You must be signed in to change notification settings - Fork 65
✨ improve logging: catalog http server, op-con resolver #1564
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ type foundBundle struct { | |
|
||
// Resolve returns a Bundle from a catalog that needs to get installed on the cluster. | ||
func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtension, installedBundle *ocv1.BundleMetadata) (*declcfg.Bundle, *bsemver.Version, *declcfg.Deprecation, error) { | ||
l := log.FromContext(ctx) | ||
packageName := ext.Spec.Source.Catalog.PackageName | ||
versionRange := ext.Spec.Source.Catalog.Version | ||
channels := ext.Spec.Source.Catalog.Channels | ||
|
@@ -65,6 +66,15 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio | |
} | ||
} | ||
|
||
type catStat struct { | ||
joelanford marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CatalogName string `json:"catalogName"` | ||
PackageFound bool `json:"packageFound"` | ||
TotalBundles int `json:"totalBundles"` | ||
MatchedBundles int `json:"matchedBundles"` | ||
} | ||
|
||
var catStats []*catStat | ||
|
||
resolvedBundles := []foundBundle{} | ||
var priorDeprecation *declcfg.Deprecation | ||
|
||
|
@@ -76,6 +86,16 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio | |
return fmt.Errorf("error getting package %q from catalog %q: %w", packageName, cat.Name, err) | ||
} | ||
|
||
cs := catStat{CatalogName: cat.Name} | ||
catStats = append(catStats, &cs) | ||
|
||
if isFBCEmpty(packageFBC) { | ||
return nil | ||
} | ||
Comment on lines
+92
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This early exit did not exist before. Are we worried about a change in behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before, if So I don't think there's a behavior change here other than skipping some unnecessary predicate setup. |
||
|
||
cs.PackageFound = true | ||
cs.TotalBundles = len(packageFBC.Bundles) | ||
|
||
var predicates []filter.Predicate[declcfg.Bundle] | ||
if len(channels) > 0 { | ||
channelSet := sets.New(channels...) | ||
|
@@ -99,6 +119,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio | |
|
||
// Apply the predicates to get the candidate bundles | ||
packageFBC.Bundles = filter.Filter(packageFBC.Bundles, filter.And(predicates...)) | ||
cs.MatchedBundles = len(packageFBC.Bundles) | ||
if len(packageFBC.Bundles) == 0 { | ||
return nil | ||
} | ||
|
@@ -158,6 +179,7 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio | |
|
||
// Check for ambiguity | ||
if len(resolvedBundles) != 1 { | ||
l.Info("resolution failed", "stats", catStats) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want this before all error returns from this point forward? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could. I felt like those other returns include context in the error message that would make it possible to figure out what happened, so that's why I only included it here. |
||
return nil, nil, nil, resolutionError{ | ||
PackageName: packageName, | ||
Version: versionRange, | ||
|
@@ -174,12 +196,15 @@ func (r *CatalogResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtensio | |
|
||
// Run validations against the resolved bundle to ensure only valid resolved bundles are being returned | ||
// Open Question: Should we grab the first valid bundle earlier? | ||
// Answer: No, that would be a hidden resolution input, which we should avoid at all costs; the query can be | ||
// constrained in order to eliminate the invalid bundle from the resolution. | ||
for _, validation := range r.Validations { | ||
if err := validation(resolvedBundle); err != nil { | ||
return nil, nil, nil, fmt.Errorf("validating bundle %q: %w", resolvedBundle.Name, err) | ||
} | ||
} | ||
|
||
l.V(4).Info("resolution succeeded", "stats", catStats) | ||
return resolvedBundle, resolvedBundleVersion, priorDeprecation, nil | ||
} | ||
|
||
|
@@ -257,6 +282,9 @@ func CatalogWalker( | |
return false | ||
}) | ||
|
||
availableCatalogNames := mapSlice(catalogs, func(c catalogd.ClusterCatalog) string { return c.Name }) | ||
l.Info("using ClusterCatalogs for resolution", "catalogs", availableCatalogNames) | ||
|
||
for i := range catalogs { | ||
cat := &catalogs[i] | ||
|
||
|
@@ -271,3 +299,18 @@ func CatalogWalker( | |
return nil | ||
} | ||
} | ||
|
||
func isFBCEmpty(fbc *declcfg.DeclarativeConfig) bool { | ||
if fbc == nil { | ||
return true | ||
} | ||
return len(fbc.Packages) == 0 && len(fbc.Channels) == 0 && len(fbc.Bundles) == 0 && len(fbc.Deprecations) == 0 && len(fbc.Others) == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @joelanford IHMO IsEmpty should be implemented in DeclarativeConfig itself. However, that is not a blocker for us to move forward here. |
||
} | ||
|
||
func mapSlice[I any, O any](in []I, f func(I) O) []O { | ||
out := make([]O, len(in)) | ||
for i := range in { | ||
out[i] = f(in[i]) | ||
} | ||
return out | ||
} |
Uh oh!
There was an error while loading. Please reload this page.