diff --git a/pkg/cache/memory/cache_test.go b/pkg/cache/memory/cache_test.go index c2523d8d..4f641509 100644 --- a/pkg/cache/memory/cache_test.go +++ b/pkg/cache/memory/cache_test.go @@ -101,7 +101,7 @@ func TestPublishedLatest(t *testing.T) { bucket := revisions[0] // Expect draft package - if got, want := bucket.Lifecycle(), api.PackageRevisionLifecycleDraft; got != want { + if got, want := bucket.Lifecycle(ctx), api.PackageRevisionLifecycleDraft; got != want { t.Fatalf("Bucket package lifecycle: got %s, want %s", got, want) } @@ -147,7 +147,7 @@ func TestDeletePublishedMain(t *testing.T) { bucket := revisions[0] // Expect draft package - if got, want := bucket.Lifecycle(), api.PackageRevisionLifecycleDraft; got != want { + if got, want := bucket.Lifecycle(ctx), api.PackageRevisionLifecycleDraft; got != want { t.Fatalf("Bucket package lifecycle: got %s, want %s", got, want) } @@ -184,7 +184,7 @@ func TestDeletePublishedMain(t *testing.T) { approvedBucket := publishedRevisions[0] - if got, want := approvedBucket.Lifecycle(), api.PackageRevisionLifecyclePublished; got != want { + if got, want := approvedBucket.Lifecycle(ctx), api.PackageRevisionLifecyclePublished; got != want { t.Fatalf("Approved Bucket package lifecycle: got %s, want %s", got, want) } diff --git a/pkg/cache/memory/packagerevision.go b/pkg/cache/memory/packagerevision.go index f12f8d62..7ca2f5fa 100644 --- a/pkg/cache/memory/packagerevision.go +++ b/pkg/cache/memory/packagerevision.go @@ -19,6 +19,7 @@ import ( api "github.com/nephio-project/porch/api/porch/v1alpha1" "github.com/nephio-project/porch/pkg/repository" + "go.opentelemetry.io/otel/trace" ) // We take advantage of the cache having a global view of all the packages @@ -35,6 +36,9 @@ type cachedPackageRevision struct { } func (c *cachedPackageRevision) GetPackageRevision(ctx context.Context) (*api.PackageRevision, error) { + ctx, span := tracer.Start(ctx, "cachedPackageRevision::GetPackageRevision", trace.WithAttributes()) + defer span.End() + apiPR, err := c.PackageRevision.GetPackageRevision(ctx) if err != nil { return nil, err diff --git a/pkg/cache/memory/repository.go b/pkg/cache/memory/repository.go index add34983..9363a61e 100644 --- a/pkg/cache/memory/repository.go +++ b/pkg/cache/memory/repository.go @@ -92,6 +92,9 @@ func (r *cachedRepository) Refresh(ctx context.Context) error { } func (r *cachedRepository) Version(ctx context.Context) (string, error) { + ctx, span := tracer.Start(ctx, "cachedRepository::Version", trace.WithAttributes()) + defer span.End() + return r.repo.Version(ctx) } @@ -122,7 +125,7 @@ func (r *cachedRepository) getPackageRevisions(ctx context.Context, filter repos } r.mutex.Lock() defer r.mutex.Unlock() - return toPackageRevisionSlice(packageRevisions, filter), nil + return toPackageRevisionSlice(ctx, packageRevisions, filter), nil } func (r *cachedRepository) getPackages(ctx context.Context, filter repository.ListPackageFilter, forceRefresh bool) ([]repository.Package, error) { @@ -196,12 +199,12 @@ func (r *cachedRepository) ClosePackageRevisionDraft(ctx context.Context, prd re var publishedRevisions []string for _, rev := range revisions { - if v1alpha1.LifecycleIsPublished(rev.Lifecycle()) { + if v1alpha1.LifecycleIsPublished(rev.Lifecycle(ctx)) { publishedRevisions = append(publishedRevisions, rev.Key().Revision) } } - nextVersion, err := repository.NextRevisionNumber(publishedRevisions) + nextVersion, err := repository.NextRevisionNumber(ctx, publishedRevisions) if err != nil { return nil, err } @@ -234,7 +237,7 @@ func (r *cachedRepository) update(ctx context.Context, updated repository.Packag k := updated.Key() // previous := r.cachedPackageRevisions[k] - if v1alpha1.LifecycleIsPublished(updated.Lifecycle()) { + if v1alpha1.LifecycleIsPublished(updated.Lifecycle(ctx)) { oldKey := repository.PackageRevisionKey{ Repository: k.Repository, Package: k.Package, @@ -247,10 +250,10 @@ func (r *cachedRepository) update(ctx context.Context, updated repository.Packag r.cachedPackageRevisions[k] = cached // Recompute latest package revisions. - identifyLatestRevisions(r.cachedPackageRevisions) + identifyLatestRevisions(ctx, r.cachedPackageRevisions) // Create the main package revision - if v1alpha1.LifecycleIsPublished(updated.Lifecycle()) { + if v1alpha1.LifecycleIsPublished(updated.Lifecycle(ctx)) { updatedMain := updated.ToMainPackageRevision() err := r.createMainPackageRevision(ctx, updatedMain) if err != nil { @@ -325,7 +328,7 @@ func (r *cachedRepository) DeletePackageRevision(ctx context.Context, old reposi // Recompute latest package revisions. // TODO: Only for affected object / key? - identifyLatestRevisions(r.cachedPackageRevisions) + identifyLatestRevisions(ctx, r.cachedPackageRevisions) } r.mutex.Unlock() @@ -408,7 +411,7 @@ func (r *cachedRepository) pollOnce(ctx context.Context) { start := time.Now() klog.Infof("repo %s: poll started", r.id) defer func() { klog.Infof("repo %s: poll finished in %f secs", r.id, time.Since(start).Seconds()) }() - ctx, span := tracer.Start(ctx, "Repository::pollOnce", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::Repository::pollOnce", trace.WithAttributes()) defer span.End() if _, err := r.getPackageRevisions(ctx, repository.ListPackageRevisionFilter{}, true); err != nil { @@ -432,6 +435,9 @@ func (r *cachedRepository) flush() { // it also triggers notifications for all package changes. // mutex must be held. func (r *cachedRepository) refreshAllCachedPackages(ctx context.Context) (map[repository.PackageKey]*cachedPackage, map[repository.PackageRevisionKey]*cachedPackageRevision, error) { + ctx, span := tracer.Start(ctx, "cachedRepository::refreshAllCachedPackages", trace.WithAttributes()) + defer span.End() + // TODO: Avoid simultaneous fetches? // TODO: Push-down partial refresh? r.mutex.Lock() @@ -567,7 +573,7 @@ func (r *cachedRepository) refreshAllCachedPackages(ctx context.Context) (map[re newPackageRevisionMap[k] = pkgRev } - identifyLatestRevisions(newPackageRevisionMap) + identifyLatestRevisions(ctx, newPackageRevisionMap) newPackageMap := make(map[repository.PackageKey]*cachedPackage) diff --git a/pkg/cache/memory/util.go b/pkg/cache/memory/util.go index c69d402b..95203b69 100644 --- a/pkg/cache/memory/util.go +++ b/pkg/cache/memory/util.go @@ -15,6 +15,7 @@ package memory import ( + "context" "sort" "strings" @@ -24,7 +25,7 @@ import ( "k8s.io/klog/v2" ) -func identifyLatestRevisions(result map[repository.PackageRevisionKey]*cachedPackageRevision) { +func identifyLatestRevisions(ctx context.Context, result map[repository.PackageRevisionKey]*cachedPackageRevision) { // Compute the latest among the different revisions of the same package. // The map is keyed by the package name; Values are the latest revision found so far. @@ -35,7 +36,7 @@ func identifyLatestRevisions(result map[repository.PackageRevisionKey]*cachedPac // Check if the current package revision is more recent than the one seen so far. // Only consider Published packages - if !v1alpha1.LifecycleIsPublished(current.Lifecycle()) { + if !v1alpha1.LifecycleIsPublished(current.Lifecycle(ctx)) { continue } @@ -64,10 +65,11 @@ func identifyLatestRevisions(result map[repository.PackageRevisionKey]*cachedPac } } -func toPackageRevisionSlice(cached map[repository.PackageRevisionKey]*cachedPackageRevision, filter repository.ListPackageRevisionFilter) []repository.PackageRevision { +func toPackageRevisionSlice( + ctx context.Context, cached map[repository.PackageRevisionKey]*cachedPackageRevision, filter repository.ListPackageRevisionFilter) []repository.PackageRevision { result := make([]repository.PackageRevision, 0, len(cached)) for _, p := range cached { - if filter.Matches(p) { + if filter.Matches(ctx, p) { result = append(result, p) } } @@ -89,7 +91,7 @@ func toPackageRevisionSlice(cached map[repository.PackageRevisionKey]*cachedPack default: // Equal. Compare next element } - switch res := strings.Compare(string(result[i].Lifecycle()), string(result[j].Lifecycle())); { + switch res := strings.Compare(string(result[i].Lifecycle(ctx)), string(result[j].Lifecycle(ctx))); { case res < 0: return true case res > 0: diff --git a/pkg/git/git.go b/pkg/git/git.go index 8929ac52..10fc9ab6 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -75,7 +75,7 @@ type GitRepositoryOptions struct { } func OpenRepository(ctx context.Context, name, namespace string, spec *configapi.GitRepository, deployment bool, root string, opts GitRepositoryOptions) (GitRepository, error) { - ctx, span := tracer.Start(ctx, "OpenRepository", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "git.go::OpenRepository", trace.WithAttributes()) defer span.End() replace := strings.NewReplacer("/", "-", ":", "-") @@ -263,6 +263,7 @@ func (r *gitRepository) DeletePackage(ctx context.Context, obj repository.Packag func (r *gitRepository) ListPackageRevisions(ctx context.Context, filter repository.ListPackageRevisionFilter) ([]repository.PackageRevision, error) { ctx, span := tracer.Start(ctx, "gitRepository::ListPackageRevisions", trace.WithAttributes()) defer span.End() + r.mutex.Lock() defer r.mutex.Unlock() @@ -324,7 +325,7 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit continue } for _, p := range tagged { - if filter.Matches(p) { + if filter.Matches(ctx, p) { result = append(result, p) } } @@ -338,14 +339,14 @@ func (r *gitRepository) listPackageRevisions(ctx context.Context, filter reposit return nil, err } for _, p := range mainpkgs { - if filter.Matches(p) { + if filter.Matches(ctx, p) { result = append(result, p) } } } for _, p := range drafts { - if filter.Matches(p) { + if filter.Matches(ctx, p) { result = append(result, p) } } @@ -425,7 +426,7 @@ func (r *gitRepository) UpdatePackageRevision(ctx context.Context, old repositor // Fetch lifecycle directly from the repository rather than from the gitPackageRevision. This makes // sure we don't end up requesting the same lock twice. - lifecycle := r.getLifecycle(ctx, oldGitPackage) + lifecycle := r.getLifecycle(oldGitPackage) return &gitPackageRevisionDraft{ parent: r, @@ -628,7 +629,7 @@ func (r *gitRepository) loadPackageRevision(ctx context.Context, version, path s } else { revision = version[last+1:] } - workspace, err = getPkgWorkspace(ctx, commit, krmPackage, ref) + workspace, err = getPkgWorkspace(commit, krmPackage, ref) if err != nil { return nil, kptfilev1.GitLock{}, err } @@ -667,7 +668,7 @@ func (r *gitRepository) discoverFinalizedPackages(ctx context.Context, ref *plum var result []*gitPackageRevision for _, krmPackage := range krmPackages.packages { - workspace, err := getPkgWorkspace(ctx, commit, krmPackage, ref) + workspace, err := getPkgWorkspace(commit, krmPackage, ref) if err != nil { return nil, err } @@ -814,7 +815,7 @@ func (r *gitRepository) loadTaggedPackages(ctx context.Context, tag *plumbing.Re return nil, nil } - workspaceName, err := getPkgWorkspace(ctx, commit, krmPackage, tag) + workspaceName, err := getPkgWorkspace(commit, krmPackage, tag) if err != nil { return nil, err } @@ -1083,6 +1084,9 @@ func (r *gitRepository) createPackageDeleteCommit(ctx context.Context, branch pl } func (r *gitRepository) PushAndCleanup(ctx context.Context, ph *pushRefSpecBuilder) error { + ctx, span := tracer.Start(ctx, "gitRepository::PushAndCleanup", trace.WithAttributes()) + defer span.End() + r.mutex.Lock() defer r.mutex.Unlock() @@ -1090,6 +1094,9 @@ func (r *gitRepository) PushAndCleanup(ctx context.Context, ph *pushRefSpecBuild } func (r *gitRepository) pushAndCleanup(ctx context.Context, ph *pushRefSpecBuilder) error { + ctx, span := tracer.Start(ctx, "gitRepository::pushAndCleanup", trace.WithAttributes()) + defer span.End() + specs, require, err := ph.BuildRefSpecs() if err != nil { return err @@ -1229,7 +1236,7 @@ func (r *gitRepository) GetResources(hash plumbing.Hash) (map[string]string, err // findLatestPackageCommit returns the latest commit from the history that pertains // to the package given by the packagePath. If no commit is found, it will return nil. -func (r *gitRepository) findLatestPackageCommit(ctx context.Context, startCommit *object.Commit, packagePath string) (*object.Commit, error) { +func (r *gitRepository) findLatestPackageCommit(startCommit *object.Commit, packagePath string) (*object.Commit, error) { var commit *object.Commit err := r.packageHistoryIterator(startCommit, packagePath, func(c *object.Commit) error { commit = c @@ -1330,15 +1337,15 @@ func (r *gitRepository) storeTree(tree *object.Tree) (plumbing.Hash, error) { } func (r *gitRepository) GetLifecycle(ctx context.Context, pkgRev *gitPackageRevision) v1alpha1.PackageRevisionLifecycle { - ctx, span := tracer.Start(ctx, "GitRepository::GetLifecycle", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "gitRepository::GetLifecycle", trace.WithAttributes()) defer span.End() r.mutex.Lock() defer r.mutex.Unlock() - return r.getLifecycle(ctx, pkgRev) + return r.getLifecycle(pkgRev) } -func (r *gitRepository) getLifecycle(ctx context.Context, pkgRev *gitPackageRevision) v1alpha1.PackageRevisionLifecycle { +func (r *gitRepository) getLifecycle(pkgRev *gitPackageRevision) v1alpha1.PackageRevisionLifecycle { switch ref := pkgRev.ref; { case ref == nil: return r.checkPublishedLifecycle(pkgRev) @@ -1368,12 +1375,13 @@ func (r *gitRepository) checkPublishedLifecycle(pkgRev *gitPackageRevision) v1al } func (r *gitRepository) UpdateLifecycle(ctx context.Context, pkgRev *gitPackageRevision, newLifecycle v1alpha1.PackageRevisionLifecycle) error { - ctx, span := tracer.Start(ctx, "GitRepository::UpdateLifecycle", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "gitRepository::UpdateLifecycle", trace.WithAttributes()) defer span.End() + r.mutex.Lock() defer r.mutex.Unlock() - old := r.getLifecycle(ctx, pkgRev) + old := r.getLifecycle(pkgRev) if !v1alpha1.LifecycleIsPublished(old) { return fmt.Errorf("cannot update lifecycle for draft package revision") } @@ -1409,7 +1417,7 @@ func (r *gitRepository) UpdateLifecycle(ctx context.Context, pkgRev *gitPackageR } func (r *gitRepository) UpdateDraftResources(ctx context.Context, draft *gitPackageRevisionDraft, new *v1alpha1.PackageRevisionResources, change *v1alpha1.Task) error { - ctx, span := tracer.Start(ctx, "gitPackageDraft::UpdateResources", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "gitRepository::UpdateResources", trace.WithAttributes()) defer span.End() r.mutex.Lock() defer r.mutex.Unlock() @@ -1464,7 +1472,7 @@ func (r *gitRepository) UpdateDraftResources(ctx context.Context, draft *gitPack } func (r *gitRepository) ClosePackageRevisionDraft(ctx context.Context, prd repository.PackageRevisionDraft, version string) (repository.PackageRevision, error) { - ctx, span := tracer.Start(ctx, "GitRepository::UpdateLifecycle", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "gitRepository::ClosePackageRevisionDraft", trace.WithAttributes()) defer span.End() r.mutex.Lock() @@ -1590,6 +1598,8 @@ func (r *gitRepository) doGitWithAuth(ctx context.Context, op func(transport.Aut } func (r *gitRepository) commitPackageToMain(ctx context.Context, d *gitPackageRevisionDraft) (commitHash, newPackageTreeHash plumbing.Hash, base *plumbing.Reference, err error) { + ctx, span := tracer.Start(ctx, "gitRepository::commitPackageToMain", trace.WithAttributes()) + defer span.End() branch := r.branch localRef := branch.RefInLocal() @@ -1713,10 +1723,10 @@ func reverseSlice(s []v1alpha1.Task) { } } -func getPkgWorkspace(ctx context.Context, commit *object.Commit, p *packageListEntry, ref *plumbing.Reference) (v1alpha1.WorkspaceName, error) { +func getPkgWorkspace(commit *object.Commit, p *packageListEntry, ref *plumbing.Reference) (v1alpha1.WorkspaceName, error) { if ref == nil || (!isTagInLocalRepo(ref.Name()) && !isDraftBranchNameInLocal(ref.Name()) && !isProposedBranchNameInLocal(ref.Name())) { // packages on the main branch may have unrelated commits, we need to find the latest commit relevant to this package - c, err := p.parent.parent.findLatestPackageCommit(ctx, p.parent.commit, p.path) + c, err := p.parent.parent.findLatestPackageCommit(p.parent.commit, p.path) if err != nil { return "", err } diff --git a/pkg/git/package.go b/pkg/git/package.go index 64ff3151..7e2b84a5 100644 --- a/pkg/git/package.go +++ b/pkg/git/package.go @@ -30,6 +30,7 @@ import ( "github.com/nephio-project/porch/internal/kpt/pkg" kptfile "github.com/nephio-project/porch/pkg/kpt/api/kptfile/v1" "github.com/nephio-project/porch/pkg/repository" + "go.opentelemetry.io/otel/trace" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" @@ -122,6 +123,9 @@ func (p *gitPackageRevision) uid() types.UID { } func (p *gitPackageRevision) GetPackageRevision(ctx context.Context) (*v1alpha1.PackageRevision, error) { + ctx, span := tracer.Start(ctx, "gitPackageRevision::GetPackageRevision", trace.WithAttributes()) + defer span.End() + key := p.Key() _, lock, _ := p.GetUpstreamLock(ctx) @@ -150,7 +154,7 @@ func (p *gitPackageRevision) GetPackageRevision(ctx context.Context) (*v1alpha1. Conditions: repository.ToApiConditions(kf), } - if v1alpha1.LifecycleIsPublished(p.Lifecycle()) { + if v1alpha1.LifecycleIsPublished(p.Lifecycle(ctx)) { if !p.updated.IsZero() { status.PublishedAt = metav1.Time{Time: p.updated} } @@ -176,7 +180,7 @@ func (p *gitPackageRevision) GetPackageRevision(ctx context.Context) (*v1alpha1. Spec: v1alpha1.PackageRevisionSpec{ PackageName: key.Package, RepositoryName: key.Repository, - Lifecycle: p.Lifecycle(), + Lifecycle: p.Lifecycle(ctx), Tasks: p.tasks, ReadinessGates: repository.ToApiReadinessGates(kf), WorkspaceName: key.WorkspaceName, @@ -309,11 +313,14 @@ func (p *gitPackageRevision) GetLock() (kptfile.Upstream, kptfile.UpstreamLock, }, nil } -func (p *gitPackageRevision) Lifecycle() v1alpha1.PackageRevisionLifecycle { - return p.repo.GetLifecycle(context.Background(), p) +func (p *gitPackageRevision) Lifecycle(ctx context.Context) v1alpha1.PackageRevisionLifecycle { + return p.repo.GetLifecycle(ctx, p) } func (p *gitPackageRevision) UpdateLifecycle(ctx context.Context, new v1alpha1.PackageRevisionLifecycle) error { + ctx, span := tracer.Start(ctx, "gitPackageRevision::UpdateLifecycle", trace.WithAttributes()) + defer span.End() + return p.repo.UpdateLifecycle(ctx, p, new) } diff --git a/pkg/git/package_test.go b/pkg/git/package_test.go index 450b4d32..b39c1611 100644 --- a/pkg/git/package_test.go +++ b/pkg/git/package_test.go @@ -66,7 +66,7 @@ func (g GitSuite) TestLock(t *testing.T) { } for _, rev := range revisions { - if rev.Lifecycle() != v1alpha1.PackageRevisionLifecyclePublished { + if rev.Lifecycle(ctx) != v1alpha1.PackageRevisionLifecyclePublished { continue } diff --git a/pkg/git/package_tree.go b/pkg/git/package_tree.go index e352cdd7..92688a19 100644 --- a/pkg/git/package_tree.go +++ b/pkg/git/package_tree.go @@ -75,7 +75,7 @@ func (p *packageListEntry) buildGitPackageRevision(ctx context.Context, revision // the last commit for the package based on the porch commit tags. We don't // use the revision here, since we are looking at the package branch while // the revisions only helps identify the tags. - commit, err := repo.findLatestPackageCommit(ctx, p.parent.commit, p.path) + commit, err := repo.findLatestPackageCommit(p.parent.commit, p.path) if err != nil { return nil, err } diff --git a/pkg/git/primitives_test.go b/pkg/git/primitives_test.go index c33e8355..3f35cae7 100644 --- a/pkg/git/primitives_test.go +++ b/pkg/git/primitives_test.go @@ -467,7 +467,7 @@ func createTestCommit(t *testing.T, repo *git.Repository, parent plumbing.Hash, Email: "test@kpt.dev", When: time.Now(), } - commit, err := wt.Commit("Hello", &git.CommitOptions{ + commit, err := wt.Commit(message, &git.CommitOptions{ Author: &sig, Committer: &sig, Parents: []plumbing.Hash{parent}, diff --git a/pkg/meta/store.go b/pkg/meta/store.go index 6a172c78..0b2599d4 100644 --- a/pkg/meta/store.go +++ b/pkg/meta/store.go @@ -76,7 +76,7 @@ func (c *crdMetadataStore) Get(ctx context.Context, namespacedName types.Namespa return metav1.ObjectMeta{}, err } - return toPackageRevisionMeta(&internalPkgRev), nil + return toPackageRevisionMeta(ctx, &internalPkgRev), nil } func (c *crdMetadataStore) List(ctx context.Context, repo *configapi.Repository) ([]metav1.ObjectMeta, error) { @@ -90,7 +90,7 @@ func (c *crdMetadataStore) List(ctx context.Context, repo *configapi.Repository) } var pkgRevMetas []metav1.ObjectMeta for _, ipr := range internalPkgRevList.Items { - pkgRevMetas = append(pkgRevMetas, toPackageRevisionMeta(&ipr)) + pkgRevMetas = append(pkgRevMetas, toPackageRevisionMeta(ctx, &ipr)) } return pkgRevMetas, nil } @@ -131,7 +131,7 @@ func (c *crdMetadataStore) Create(ctx context.Context, pkgRevMeta metav1.ObjectM } return metav1.ObjectMeta{}, err } - return toPackageRevisionMeta(&internalPkgRev), nil + return toPackageRevisionMeta(ctx, &internalPkgRev), nil } func (c *crdMetadataStore) Update(ctx context.Context, pkgRevMeta metav1.ObjectMeta) (metav1.ObjectMeta, error) { @@ -175,7 +175,7 @@ func (c *crdMetadataStore) Update(ctx context.Context, pkgRevMeta metav1.ObjectM if err := c.coreClient.Update(ctx, &internalPkgRev); err != nil { return metav1.ObjectMeta{}, err } - return toPackageRevisionMeta(&internalPkgRev), nil + return toPackageRevisionMeta(ctx, &internalPkgRev), nil } func (c *crdMetadataStore) Delete(ctx context.Context, namespacedName types.NamespacedName, clearFinalizers bool) (metav1.ObjectMeta, error) { @@ -205,10 +205,13 @@ func (c *crdMetadataStore) Delete(ctx context.Context, namespacedName types.Name if err := c.coreClient.Delete(ctx, &internalPkgRev); err != nil { return metav1.ObjectMeta{}, err } - return toPackageRevisionMeta(&internalPkgRev), nil + return toPackageRevisionMeta(ctx, &internalPkgRev), nil } -func toPackageRevisionMeta(internalPkgRev *internalapi.PackageRev) metav1.ObjectMeta { +func toPackageRevisionMeta(ctx context.Context, internalPkgRev *internalapi.PackageRev) metav1.ObjectMeta { + ctx, span := tracer.Start(ctx, "store.go::toPackageRevisionMeta", trace.WithAttributes()) + defer span.End() + labels := internalPkgRev.Labels delete(labels, PkgRevisionRepoLabel) diff --git a/pkg/oci/mutate.go b/pkg/oci/mutate.go index 98964500..953492cc 100644 --- a/pkg/oci/mutate.go +++ b/pkg/oci/mutate.go @@ -98,7 +98,7 @@ func (r *ociRepository) UpdatePackageRevision(ctx context.Context, old repositor tasks: []v1alpha1.Task{}, base: base, tag: ref, - lifecycle: oldPackage.Lifecycle(), + lifecycle: oldPackage.Lifecycle(ctx), }, nil } @@ -241,11 +241,11 @@ func (r *ociRepository) ClosePackageRevisionDraft(ctx context.Context, prd repos } var revs []string for _, rev := range revisions { - if v1alpha1.LifecycleIsPublished(rev.Lifecycle()) { + if v1alpha1.LifecycleIsPublished(rev.Lifecycle(ctx)) { revs = append(revs, rev.Key().Revision) } } - nextRevisionNumber, err := repository.NextRevisionNumber(revs) + nextRevisionNumber, err := repository.NextRevisionNumber(ctx, revs) if err != nil { return nil, err } diff --git a/pkg/oci/oci.go b/pkg/oci/oci.go index a9c6be4e..e84427b3 100644 --- a/pkg/oci/oci.go +++ b/pkg/oci/oci.go @@ -32,6 +32,7 @@ import ( "github.com/nephio-project/porch/internal/kpt/pkg" kptfile "github.com/nephio-project/porch/pkg/kpt/api/kptfile/v1" "github.com/nephio-project/porch/pkg/repository" + "go.opentelemetry.io/otel/trace" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/klog/v2" @@ -192,7 +193,7 @@ func (r *ociRepository) ListPackageRevisions(ctx context.Context, filter reposit } p.tasks = tasks - if filter.Matches(p) { + if filter.Matches(ctx, p) { result = append(result, p) } } @@ -331,6 +332,9 @@ func (p *ociPackageRevision) Key() repository.PackageRevisionKey { } func (p *ociPackageRevision) GetPackageRevision(ctx context.Context) (*v1alpha1.PackageRevision, error) { + ctx, span := tracer.Start(ctx, "ociPackageRevision::GetPackageRevision", trace.WithAttributes()) + defer span.End() + key := p.Key() kf, err := p.GetKptfile(ctx) @@ -358,7 +362,7 @@ func (p *ociPackageRevision) GetPackageRevision(ctx context.Context) (*v1alpha1. Revision: key.Revision, WorkspaceName: key.WorkspaceName, - Lifecycle: p.Lifecycle(), + Lifecycle: p.Lifecycle(ctx), Tasks: p.tasks, ReadinessGates: repository.ToApiReadinessGates(kf), }, @@ -394,7 +398,7 @@ func (p *ociPackageRevision) GetLock() (kptfile.Upstream, kptfile.UpstreamLock, return kptfile.Upstream{}, kptfile.UpstreamLock{}, fmt.Errorf("lock is not supported for oci packages (%s)", p.KubeObjectName()) } -func (p *ociPackageRevision) Lifecycle() v1alpha1.PackageRevisionLifecycle { +func (p *ociPackageRevision) Lifecycle(ctx context.Context) v1alpha1.PackageRevisionLifecycle { return p.lifecycle } @@ -403,7 +407,10 @@ func (p *ociPackageRevision) Lifecycle() v1alpha1.PackageRevisionLifecycle { // This function is currently only partially implemented; it still needs to store whether the package has been // proposed for deletion somewhere in OCI, probably as another OCI image with a "deletionProposed" tag. func (p *ociPackageRevision) UpdateLifecycle(ctx context.Context, new v1alpha1.PackageRevisionLifecycle) error { - old := p.Lifecycle() + ctx, span := tracer.Start(ctx, "ociPackageRevision::UpdateLifecycle", trace.WithAttributes()) + defer span.End() + + old := p.Lifecycle(ctx) if old == v1alpha1.PackageRevisionLifecyclePublished { if new != v1alpha1.PackageRevisionLifecycleDeletionProposed { diff --git a/pkg/registry/porch/packagecommon.go b/pkg/registry/porch/packagecommon.go index 78400c2d..35f6ac0e 100644 --- a/pkg/registry/porch/packagecommon.go +++ b/pkg/registry/porch/packagecommon.go @@ -25,6 +25,7 @@ import ( "github.com/nephio-project/porch/pkg/engine" "github.com/nephio-project/porch/pkg/repository" "github.com/nephio-project/porch/pkg/util" + "go.opentelemetry.io/otel/trace" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/runtime" @@ -56,7 +57,10 @@ type packageCommon struct { } func (r *packageCommon) listPackageRevisions(ctx context.Context, filter packageRevisionFilter, - selector labels.Selector, callback func(p repository.PackageRevision) error) error { + selector labels.Selector, callback func(ctx context.Context, p repository.PackageRevision) error) error { + ctx, span := tracer.Start(ctx, "packageCommon::listPackageRevisions", trace.WithAttributes()) + defer span.End() + var opts []client.ListOption ns, namespaced := genericapirequest.NamespaceFrom(ctx) if namespaced && ns != "" { @@ -95,7 +99,7 @@ func (r *packageCommon) listPackageRevisions(ctx context.Context, filter package continue } - if err := callback(rev); err != nil { + if err := callback(ctx, rev); err != nil { return err } } @@ -173,6 +177,9 @@ func (r *packageCommon) getRepositoryObj(ctx context.Context, repositoryID types } func (r *packageCommon) getRepoPkgRev(ctx context.Context, name string) (repository.PackageRevision, error) { + ctx, span := tracer.Start(ctx, "packageCommon::getRepoPkgRev", trace.WithAttributes()) + defer span.End() + repositoryObj, err := r.getRepositoryObjFromName(ctx, name) if err != nil { return nil, err @@ -212,6 +219,9 @@ func (r *packageCommon) getPackage(ctx context.Context, name string) (repository // Common implementation of PackageRevision update logic. func (r *packageCommon) updatePackageRevision(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool) (runtime.Object, bool, error) { + ctx, span := tracer.Start(ctx, "packageCommon::updatePackageRevision", trace.WithAttributes()) + defer span.End() + // TODO: Is this all boilerplate?? ns, namespaced := genericapirequest.NamespaceFrom(ctx) @@ -309,19 +319,7 @@ func (r *packageCommon) updatePackageRevision(ctx context.Context, name string, parentPackage = p } - if !isCreate { - rev, err := r.cad.UpdatePackageRevision(ctx, "", &repositoryObj, oldRepoPkgRev, oldApiPkgRev.(*api.PackageRevision), newApiPkgRev, parentPackage) - if err != nil { - return nil, false, apierrors.NewInternalError(err) - } - - updated, err := rev.GetPackageRevision(ctx) - if err != nil { - return nil, false, apierrors.NewInternalError(err) - } - - return updated, false, nil - } else { + if isCreate { rev, err := r.cad.CreatePackageRevision(ctx, &repositoryObj, newApiPkgRev, parentPackage) if err != nil { klog.Infof("error creating package: %v", err) @@ -334,6 +332,18 @@ func (r *packageCommon) updatePackageRevision(ctx context.Context, name string, return createdApiPkgRev, true, nil } + + rev, err := r.cad.UpdatePackageRevision(ctx, "", &repositoryObj, oldRepoPkgRev, oldApiPkgRev.(*api.PackageRevision), newApiPkgRev, parentPackage) + if err != nil { + return nil, false, apierrors.NewInternalError(err) + } + + updated, err := rev.GetPackageRevision(ctx) + if err != nil { + return nil, false, apierrors.NewInternalError(err) + } + + return updated, false, nil } // Common implementation of Package update logic. diff --git a/pkg/registry/porch/packagerevision.go b/pkg/registry/porch/packagerevision.go index 64d0ff77..6969843b 100644 --- a/pkg/registry/porch/packagerevision.go +++ b/pkg/registry/porch/packagerevision.go @@ -32,7 +32,7 @@ import ( "k8s.io/klog/v2" ) -var tracer = otel.Tracer("apiserver") +var tracer = otel.Tracer("packagerevision") type packageRevisions struct { packageCommon @@ -70,7 +70,7 @@ func (r *packageRevisions) NamespaceScoped() bool { // List selects resources in the storage which match to the selector. 'options' can be nil. func (r *packageRevisions) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) { - ctx, span := tracer.Start(ctx, "packageRevisions::List", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisions::List", trace.WithAttributes()) defer span.End() result := &api.PackageRevisionList{ @@ -85,7 +85,7 @@ func (r *packageRevisions) List(ctx context.Context, options *metainternalversio return nil, err } - if err := r.packageCommon.listPackageRevisions(ctx, filter, options.LabelSelector, func(p repository.PackageRevision) error { + if err := r.packageCommon.listPackageRevisions(ctx, filter, options.LabelSelector, func(ctx context.Context, p repository.PackageRevision) error { item, err := p.GetPackageRevision(ctx) if err != nil { return err @@ -101,7 +101,7 @@ func (r *packageRevisions) List(ctx context.Context, options *metainternalversio // Get implements the Getter interface func (r *packageRevisions) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { - ctx, span := tracer.Start(ctx, "packageRevisions::Get", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisions::Get", trace.WithAttributes()) defer span.End() repoPkgRev, err := r.getRepoPkgRev(ctx, name) @@ -120,7 +120,7 @@ func (r *packageRevisions) Get(ctx context.Context, name string, options *metav1 // Create implements the Creater interface. func (r *packageRevisions) Create(ctx context.Context, runtimeObject runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) { - ctx, span := tracer.Start(ctx, "packageRevisions::Create", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisions::Create", trace.WithAttributes()) defer span.End() ns, namespaced := genericapirequest.NamespaceFrom(ctx) @@ -198,7 +198,7 @@ func (r *packageRevisions) Create(ctx context.Context, runtimeObject runtime.Obj // to true. func (r *packageRevisions) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { - ctx, span := tracer.Start(ctx, "packageRevisions::Update", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisions::Update", trace.WithAttributes()) defer span.End() return r.packageCommon.updatePackageRevision(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate) @@ -216,7 +216,7 @@ func (r *packageRevisions) Update(ctx context.Context, name string, objInfo rest // It also returns a boolean which is set to true if the resource was instantly // deleted or false if it will be deleted asynchronously. func (r *packageRevisions) Delete(ctx context.Context, name string, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions) (runtime.Object, bool, error) { - ctx, span := tracer.Start(ctx, "packageRevisions::Delete", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisions::Delete", trace.WithAttributes()) defer span.End() ns, namespaced := genericapirequest.NamespaceFrom(ctx) diff --git a/pkg/registry/porch/packagerevisionresources.go b/pkg/registry/porch/packagerevisionresources.go index 10388484..482f6962 100644 --- a/pkg/registry/porch/packagerevisionresources.go +++ b/pkg/registry/porch/packagerevisionresources.go @@ -68,7 +68,7 @@ func (r *packageRevisionResources) NamespaceScoped() bool { // List selects resources in the storage which match to the selector. 'options' can be nil. func (r *packageRevisionResources) List(ctx context.Context, options *metainternalversion.ListOptions) (runtime.Object, error) { - ctx, span := tracer.Start(ctx, "packageRevisionResources::List", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisionResources::List", trace.WithAttributes()) defer span.End() result := &api.PackageRevisionResourcesList{ @@ -83,7 +83,7 @@ func (r *packageRevisionResources) List(ctx context.Context, options *metaintern return nil, err } - if err := r.packageCommon.listPackageRevisions(ctx, filter, options.LabelSelector, func(p repository.PackageRevision) error { + if err := r.packageCommon.listPackageRevisions(ctx, filter, options.LabelSelector, func(ctx context.Context, p repository.PackageRevision) error { apiPkgResources, err := p.GetResources(ctx) if err != nil { return err @@ -99,7 +99,7 @@ func (r *packageRevisionResources) List(ctx context.Context, options *metaintern // Get implements the Getter interface func (r *packageRevisionResources) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { - ctx, span := tracer.Start(ctx, "packageRevisionResources::Get", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisionResources::Get", trace.WithAttributes()) defer span.End() pkg, err := r.packageCommon.getRepoPkgRev(ctx, name) @@ -118,7 +118,7 @@ func (r *packageRevisionResources) Get(ctx context.Context, name string, options // may allow updates creates the object - they should set the created boolean // to true. func (r *packageRevisionResources) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { - ctx, span := tracer.Start(ctx, "packageRevisionResources::Update", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisionResources::Update", trace.WithAttributes()) defer span.End() ns, namespaced := genericapirequest.NamespaceFrom(ctx) diff --git a/pkg/registry/porch/packagerevisions_approval.go b/pkg/registry/porch/packagerevisions_approval.go index 07f1d396..516f7b42 100644 --- a/pkg/registry/porch/packagerevisions_approval.go +++ b/pkg/registry/porch/packagerevisions_approval.go @@ -20,6 +20,7 @@ import ( "strings" api "github.com/nephio-project/porch/api/porch/v1alpha1" + "go.opentelemetry.io/otel/trace" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" @@ -61,6 +62,9 @@ func (a *packageRevisionsApproval) Get(ctx context.Context, name string, options // to true. func (a *packageRevisionsApproval) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { + ctx, span := tracer.Start(ctx, "[START]::packageRevisionsApproval::Update", trace.WithAttributes()) + defer span.End() + allowCreate := false // do not allow create on update return a.common.updatePackageRevision(ctx, name, objInfo, createValidation, updateValidation, allowCreate) } diff --git a/pkg/registry/porch/strategy.go b/pkg/registry/porch/strategy.go index 2935bb78..9aa67845 100644 --- a/pkg/registry/porch/strategy.go +++ b/pkg/registry/porch/strategy.go @@ -20,6 +20,7 @@ import ( "strings" api "github.com/nephio-project/porch/api/porch/v1alpha1" + "go.opentelemetry.io/otel/trace" "k8s.io/apimachinery/pkg/api/equality" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/validation/field" @@ -35,6 +36,9 @@ func (s packageRevisionStrategy) PrepareForUpdate(ctx context.Context, obj, old } func (s packageRevisionStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { + ctx, span := tracer.Start(ctx, "packageRevisionStrategy::ValidateUpdate", trace.WithAttributes()) + defer span.End() + allErrs := field.ErrorList{} oldRevision := old.(*api.PackageRevision) newRevision := obj.(*api.PackageRevision) @@ -116,6 +120,9 @@ var _ SimpleRESTCreateStrategy = packageRevisionStrategy{} // before the object is persisted. This method should not mutate the // object. func (s packageRevisionStrategy) Validate(ctx context.Context, runtimeObj runtime.Object) field.ErrorList { + ctx, span := tracer.Start(ctx, "packageRevisionStrategy::Validate", trace.WithAttributes()) + defer span.End() + allErrs := field.ErrorList{} obj := runtimeObj.(*api.PackageRevision) diff --git a/pkg/registry/porch/watch.go b/pkg/registry/porch/watch.go index 38102610..68897130 100644 --- a/pkg/registry/porch/watch.go +++ b/pkg/registry/porch/watch.go @@ -36,7 +36,7 @@ func (r *packageRevisions) Watch(ctx context.Context, options *metainternalversi // isn't supported. 'resourceVersion' allows for continuing/starting a watch at a // particular version. - ctx, span := tracer.Start(ctx, "packageRevisions::Watch", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "[START]::packageRevisions::Watch", trace.WithAttributes()) defer span.End() filter, err := parsePackageRevisionFieldSelector(options.FieldSelector) @@ -93,7 +93,7 @@ func (w *watcher) ResultChan() <-chan watch.Event { type packageReader interface { watchPackages(ctx context.Context, filter packageRevisionFilter, callback engine.ObjectWatcher) error - listPackageRevisions(ctx context.Context, filter packageRevisionFilter, selector labels.Selector, callback func(p repository.PackageRevision) error) error + listPackageRevisions(ctx context.Context, filter packageRevisionFilter, selector labels.Selector, callback func(ctx context.Context, p repository.PackageRevision) error) error } // listAndWatch implements watch by doing a list, then sending any observed changes. @@ -145,7 +145,7 @@ func (w *watcher) listAndWatchInner(ctx context.Context, r packageReader, filter sentAdd := 0 // TODO: Only if rv == 0? - if err := r.listPackageRevisions(ctx, filter, selector, func(p repository.PackageRevision) error { + if err := r.listPackageRevisions(ctx, filter, selector, func(ctx context.Context, p repository.PackageRevision) error { obj, err := p.GetPackageRevision(ctx) if err != nil { w.mutex.Lock() diff --git a/pkg/registry/porch/watch_test.go b/pkg/registry/porch/watch_test.go index fa21fa95..7f1808ea 100644 --- a/pkg/registry/porch/watch_test.go +++ b/pkg/registry/porch/watch_test.go @@ -97,6 +97,6 @@ func (f *fakePackageReader) watchPackages(ctx context.Context, filter packageRev return nil } -func (f *fakePackageReader) listPackageRevisions(ctx context.Context, filter packageRevisionFilter, selector labels.Selector, callback func(p repository.PackageRevision) error) error { +func (f *fakePackageReader) listPackageRevisions(ctx context.Context, filter packageRevisionFilter, selector labels.Selector, callback func(ctx context.Context, p repository.PackageRevision) error) error { return nil } diff --git a/pkg/repository/fake/packagerevision.go b/pkg/repository/fake/packagerevision.go index bd271d67..8c9a346f 100644 --- a/pkg/repository/fake/packagerevision.go +++ b/pkg/repository/fake/packagerevision.go @@ -63,7 +63,7 @@ func (pr *FakePackageRevision) Key() repository.PackageRevisionKey { return pr.PackageRevisionKey } -func (pr *FakePackageRevision) Lifecycle() v1alpha1.PackageRevisionLifecycle { +func (pr *FakePackageRevision) Lifecycle(ctx context.Context) v1alpha1.PackageRevisionLifecycle { return pr.PackageLifecycle } diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index dfb8cf3b..90136a3d 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -68,7 +68,7 @@ type PackageRevision interface { Key() PackageRevisionKey // Lifecycle returns the current lifecycle state of the package. - Lifecycle() v1alpha1.PackageRevisionLifecycle + Lifecycle(ctx context.Context) v1alpha1.PackageRevisionLifecycle // UpdateLifecycle updates the desired lifecycle of the package. This can only // be used for Published package revisions to go from Published to DeletionProposed @@ -150,7 +150,7 @@ type ListPackageRevisionFilter struct { } // Matches returns true if the provided PackageRevision satisfies the conditions in the filter. -func (f *ListPackageRevisionFilter) Matches(p PackageRevision) bool { +func (f *ListPackageRevisionFilter) Matches(ctx context.Context, p PackageRevision) bool { packageKey := p.Key() if f.Package != "" && f.Package != packageKey.Package { @@ -165,7 +165,7 @@ func (f *ListPackageRevisionFilter) Matches(p PackageRevision) bool { if f.KubeObjectName != "" && f.KubeObjectName != p.KubeObjectName() { return false } - if f.Lifecycle != "" && f.Lifecycle != p.Lifecycle() { + if f.Lifecycle != "" && f.Lifecycle != p.Lifecycle(ctx) { return false } return true diff --git a/pkg/repository/util.go b/pkg/repository/util.go index dbe5dd63..8353189e 100644 --- a/pkg/repository/util.go +++ b/pkg/repository/util.go @@ -15,6 +15,7 @@ package repository import ( + "context" "fmt" "regexp" "strconv" @@ -22,9 +23,13 @@ import ( api "github.com/nephio-project/porch/api/porch/v1alpha1" kptfile "github.com/nephio-project/porch/pkg/kpt/api/kptfile/v1" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/trace" "golang.org/x/mod/semver" ) +var tracer = otel.Tracer("repository/util") + func ToApiReadinessGates(kf kptfile.KptFile) []api.ReadinessGate { var readinessGates []api.ReadinessGate if kf.Info != nil { @@ -65,7 +70,10 @@ func toApiConditionStatus(s kptfile.ConditionStatus) api.ConditionStatus { } } -func NextRevisionNumber(revs []string) (string, error) { +func NextRevisionNumber(ctx context.Context, revs []string) (string, error) { + ctx, span := tracer.Start(ctx, "draft.go::NextRevisionNumber", trace.WithAttributes()) + defer span.End() + // Computes the next revision number as the latest revision number + 1. // This function only understands strict versioning format, e.g. v1, v2, etc. It will // ignore all revision numbers it finds that do not adhere to this format. diff --git a/pkg/task/builtin.go b/pkg/task/builtin.go index e6d56f3a..4f2ee35f 100644 --- a/pkg/task/builtin.go +++ b/pkg/task/builtin.go @@ -23,6 +23,7 @@ import ( "github.com/nephio-project/porch/internal/kpt/fnruntime" "github.com/nephio-project/porch/pkg/kpt/fn" "github.com/nephio-project/porch/pkg/repository" + "go.opentelemetry.io/otel/trace" "sigs.k8s.io/kustomize/kyaml/fn/runtime/runtimeutil" "sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/yaml" @@ -47,6 +48,9 @@ func newPackageContextGeneratorMutation(packageConfig *builtins.PackageConfig) ( var _ mutation = &builtinEvalMutation{} func (m *builtinEvalMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { + ctx, span := tracer.Start(ctx, "builtinEvalMutation::Apply", trace.WithAttributes()) + defer span.End() + ff := &runtimeutil.FunctionFilter{ Run: m.runner.Run, Results: &yaml.RNode{}, diff --git a/pkg/task/clone.go b/pkg/task/clone.go index 5e9bbf28..4214d0f3 100644 --- a/pkg/task/clone.go +++ b/pkg/task/clone.go @@ -51,7 +51,7 @@ type clonePackageMutation struct { } func (m *clonePackageMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - ctx, span := tracer.Start(ctx, "clonePackageMutation::Apply", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "clonePackageMutation::apply", trace.WithAttributes()) defer span.End() var cloned repository.PackageResources diff --git a/pkg/task/edit.go b/pkg/task/edit.go index 01841465..a6ce6c2a 100644 --- a/pkg/task/edit.go +++ b/pkg/task/edit.go @@ -35,7 +35,7 @@ type editPackageMutation struct { var _ mutation = &editPackageMutation{} func (m *editPackageMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - ctx, span := tracer.Start(ctx, "editPackageMutation::Apply", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "editPackageMutation::apply", trace.WithAttributes()) defer span.End() sourceRef := m.task.Edit.Source @@ -55,7 +55,7 @@ func (m *editPackageMutation) apply(ctx context.Context, resources repository.Pa } // We only allow edit to create new revisions from published packages. - if !api.LifecycleIsPublished(revision.Lifecycle()) { + if !api.LifecycleIsPublished(revision.Lifecycle(ctx)) { return repository.PackageResources{}, nil, fmt.Errorf("source revision must be published") } diff --git a/pkg/task/eval.go b/pkg/task/eval.go index 8aa657ac..8518560b 100644 --- a/pkg/task/eval.go +++ b/pkg/task/eval.go @@ -38,7 +38,7 @@ type evalFunctionMutation struct { } func (m *evalFunctionMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - ctx, span := tracer.Start(ctx, "evalFunctionMutation::Apply", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "evalFunctionMutation::apply", trace.WithAttributes()) defer span.End() e := m.task.Eval diff --git a/pkg/task/generictaskhandler.go b/pkg/task/generictaskhandler.go index 1bd938e2..77800518 100644 --- a/pkg/task/generictaskhandler.go +++ b/pkg/task/generictaskhandler.go @@ -443,6 +443,9 @@ func isRenderMutation(m mutation) bool { // applyResourceMutations mutates the resources and returns the most recent renderResult. func applyResourceMutations(ctx context.Context, draft repository.PackageRevisionDraft, baseResources repository.PackageResources, mutations []mutation) (applied repository.PackageResources, renderStatus *api.RenderStatus, err error) { + ctx, span := tracer.Start(ctx, "genericTaskHandler::applyResourceMutations", trace.WithAttributes()) + defer span.End() + var lastApplied mutation for _, m := range mutations { updatedResources, taskResult, err := m.apply(ctx, baseResources) diff --git a/pkg/task/init.go b/pkg/task/init.go index a5f7562b..2645d481 100644 --- a/pkg/task/init.go +++ b/pkg/task/init.go @@ -36,7 +36,7 @@ type initPackageMutation struct { var _ mutation = &initPackageMutation{} func (m *initPackageMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - ctx, span := tracer.Start(ctx, "initPackageMutation::Apply", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "initPackageMutation::apply", trace.WithAttributes()) defer span.End() fs := filesys.MakeFsInMemory() diff --git a/pkg/task/patchgen.go b/pkg/task/patchgen.go index 1046ba0d..0ae95d66 100644 --- a/pkg/task/patchgen.go +++ b/pkg/task/patchgen.go @@ -53,7 +53,7 @@ type applyPatchMutation struct { var _ mutation = &applyPatchMutation{} func (m *applyPatchMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - _, span := tracer.Start(ctx, "applyPatchMutation:::Apply", trace.WithAttributes()) + _, span := tracer.Start(ctx, "applyPatchMutation::apply", trace.WithAttributes()) defer span.End() result := repository.PackageResources{ diff --git a/pkg/task/render.go b/pkg/task/render.go index 56a3ae71..9d907c35 100644 --- a/pkg/task/render.go +++ b/pkg/task/render.go @@ -40,7 +40,7 @@ type renderPackageMutation struct { var _ mutation = &renderPackageMutation{} func (m *renderPackageMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - ctx, span := tracer.Start(ctx, "renderPackageMutation::Apply", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "renderPackageMutation::apply", trace.WithAttributes()) defer span.End() fs := filesys.MakeFsInMemory() diff --git a/pkg/task/replaceresources.go b/pkg/task/replaceresources.go index d3490786..9f2392d2 100644 --- a/pkg/task/replaceresources.go +++ b/pkg/task/replaceresources.go @@ -31,7 +31,7 @@ type replaceResourcesMutation struct { } func (m *replaceResourcesMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - _, span := tracer.Start(ctx, "mutationReplaceResources::Apply", trace.WithAttributes()) + _, span := tracer.Start(ctx, "mutationReplaceResources::apply", trace.WithAttributes()) defer span.End() patch := &api.PackagePatchTaskSpec{} diff --git a/pkg/task/update.go b/pkg/task/update.go index d0a3fea7..13898bf9 100644 --- a/pkg/task/update.go +++ b/pkg/task/update.go @@ -37,7 +37,7 @@ type updatePackageMutation struct { } func (m *updatePackageMutation) apply(ctx context.Context, resources repository.PackageResources) (repository.PackageResources, *api.TaskResult, error) { - ctx, span := tracer.Start(ctx, "updatePackageMutation::Apply", trace.WithAttributes()) + ctx, span := tracer.Start(ctx, "updatePackageMutation::apply", trace.WithAttributes()) defer span.End() currUpstreamPkgRef, err := m.currUpstream()