From 55fed489cb6eae115a8543439b3aca7b430cfedf Mon Sep 17 00:00:00 2001 From: rymsha Date: Thu, 14 Mar 2024 13:53:35 +0100 Subject: [PATCH] Trace node api does not contain repo and branch #10458 --- .../xp/repo/impl/node/NodeServiceImpl.java | 69 +++++++++++++++---- .../scheduler/distributed/RescheduleTask.java | 17 +++-- 2 files changed, 65 insertions(+), 21 deletions(-) diff --git a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/node/NodeServiceImpl.java b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/node/NodeServiceImpl.java index d8c38dca409..4c4575cf49e 100644 --- a/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/node/NodeServiceImpl.java +++ b/modules/core/core-repo/src/main/java/com/enonic/xp/repo/impl/node/NodeServiceImpl.java @@ -129,7 +129,11 @@ public NodeServiceImpl( @Reference final IndexServiceInternal indexServiceIntern @Override public Node getById( final NodeId id ) { - return Tracer.trace( "node.getById", trace -> trace.put( "id", id ), () -> executeGetById( id ), + return Tracer.trace( "node.getById", trace -> { + trace.put( "id", id ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); + }, () -> executeGetById( id ), ( trace, node ) -> trace.put( "path", node.path() ) ); } @@ -153,6 +157,8 @@ public Node getByIdAndVersionId( final NodeId id, final NodeVersionId versionId return Tracer.trace( "node.getByIdAndVersionId", trace -> { trace.put( "id", id ); trace.put( "versionId", versionId ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeGetByIdAndVersionId( id, versionId ), ( trace, node ) -> trace.put( "path", node.path() ) ); } @@ -191,7 +197,11 @@ private Node doGetById( final NodeId id ) @Override public Node getByPath( final NodePath path ) { - return Tracer.trace( "node.getByPath", trace -> trace.put( "path", path ), () -> executeGetByPath( path ), ( trace, node ) -> { + return Tracer.trace( "node.getByPath", trace -> { + trace.put( "path", path ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); + }, () -> executeGetByPath( path ), ( trace, node ) -> { if ( node != null ) { trace.put( "id", node.id() ); @@ -218,6 +228,8 @@ public Node getByPathAndVersionId( final NodePath path, final NodeVersionId vers return Tracer.trace( "node.getByPathAndVersionId", trace -> { trace.put( "path", path ); trace.put( "versionId", versionId ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeGetByPathAndVersionId( path, versionId ), ( trace, node ) -> trace.put( "id", node.id() ) ); } @@ -245,7 +257,11 @@ private Node executeGetByPathAndVersionId( final NodePath path, final NodeVersio @Override public Nodes getByIds( final NodeIds ids ) { - return Tracer.trace( "node.getByIds", trace -> trace.put( "id", ids ), () -> executeGetByIds( ids ) ); + return Tracer.trace( "node.getByIds", trace -> { + trace.put( "id", ids ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); + }, () -> executeGetByIds( ids ) ); } private Nodes executeGetByIds( final NodeIds ids ) @@ -263,7 +279,11 @@ private Nodes executeGetByIds( final NodeIds ids ) @Override public Nodes getByPaths( final NodePaths paths ) { - return Tracer.trace( "node.getByPaths", trace -> trace.put( "path", paths ), () -> executeGetByPaths( paths ) ); + return Tracer.trace( "node.getByPaths", trace -> { + trace.put( "path", paths ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); + }, () -> executeGetByPaths( paths ) ); } private Nodes executeGetByPaths( final NodePaths paths ) @@ -285,6 +305,8 @@ public FindNodesByParentResult findByParent( final FindNodesByParentParams param trace.put( "parent", params.getParentPath() != null ? params.getParentPath() : params.getParentId() ); trace.put( "from", params.getFrom() ); trace.put( "size", params.getSize() ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeFindByParent( params ), ( ( trace, result ) -> trace.put( "hits", result.getTotalHits() ) ) ); } @@ -315,6 +337,8 @@ public FindNodesByQueryResult findByQuery( final NodeQuery nodeQuery ) trace.put( "filter", nodeQuery.getQueryFilters() ); trace.put( "from", nodeQuery.getFrom() ); trace.put( "size", nodeQuery.getSize() ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeFindByQuery( nodeQuery ), ( trace, result ) -> trace.put( "hits", result.getTotalHits() ) ); } @@ -357,6 +381,8 @@ public FindNodesByMultiRepoQueryResult findByQuery( final MultiRepoNodeQuery mul trace.put( "filter", multiNodeQuery.getNodeQuery().getQueryFilters() ); trace.put( "from", multiNodeQuery.getNodeQuery().getFrom() ); trace.put( "size", multiNodeQuery.getNodeQuery().getSize() ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeFindByQuery( multiNodeQuery ), ( trace, result ) -> trace.put( "hits", result.getTotalHits() ) ); } @@ -770,7 +796,10 @@ public ReorderChildNodesResult reorderChildren( final ReorderChildNodesParams pa @Override public void refresh( final RefreshMode refreshMode ) { - Tracer.trace( "node.refresh", trace -> trace.put( "refreshMode", refreshMode ), () -> executeRefresh( refreshMode ) ); + Tracer.trace( "node.refresh", trace -> { + trace.put( "refreshMode", refreshMode ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + }, () -> executeRefresh( refreshMode ) ); } private Void executeRefresh( final RefreshMode refreshMode ) @@ -807,6 +836,8 @@ public ByteSource getBinary( final NodeId nodeId, final BinaryReference referenc return Tracer.trace( "node.getBinary", trace -> { trace.put( "id", nodeId ); trace.put( "reference", reference ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeGetBinary( nodeId, reference ), ( trace, byteSource ) -> { if ( byteSource != null ) { @@ -836,6 +867,8 @@ public ByteSource getBinary( final NodeId nodeId, final NodeVersionId nodeVersio trace.put( "id", nodeId ); trace.put( "versionId", nodeVersionId ); trace.put( "reference", reference ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeGetBinary( nodeId, nodeVersionId, reference ), ( trace, byteSource ) -> { if ( byteSource != null ) { @@ -865,6 +898,8 @@ public String getBinaryKey( final NodeId nodeId, final BinaryReference reference return Tracer.trace( "node.getBinaryKey", trace -> { trace.put( "id", nodeId ); trace.put( "reference", reference ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); }, () -> executeGetBinaryKey( nodeId, reference ), ( trace, binaryKey ) -> trace.put( "binaryKey", binaryKey ) ); } @@ -980,7 +1015,11 @@ public LoadNodeResult loadNode( final LoadNodeParams params ) @Override public boolean nodeExists( final NodeId nodeId ) { - return Tracer.trace( "node.exists", trace -> trace.put( "id", nodeId ), () -> { + return Tracer.trace( "node.exists", trace -> { + trace.put( "id", nodeId ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); + }, () -> { verifyContext(); return NodeHelper.runAsAdmin( () -> doGetById( nodeId ) ) != null; }, (trace, exists) -> trace.put( "exists", exists ) ); @@ -989,9 +1028,11 @@ public boolean nodeExists( final NodeId nodeId ) @Override public boolean nodeExists( final NodePath nodePath ) { - return Tracer.trace( "node.exists", trace -> trace.put( "path", nodePath ), - () -> NodeHelper.runAsAdmin( () -> executeGetByPath( nodePath ) ) != null, - ( trace, exists ) -> trace.put( "exists", exists ) ); + return Tracer.trace( "node.exists", trace -> { + trace.put( "path", nodePath ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); + }, () -> NodeHelper.runAsAdmin( () -> executeGetByPath( nodePath ) ) != null, ( trace, exists ) -> trace.put( "exists", exists ) ); } @Override @@ -1014,11 +1055,11 @@ public NodesHasChildrenResult hasChildren( final Nodes nodes ) public boolean hasChildren( final Node node ) { verifyContext(); - return Tracer.trace( "node.hasChildren", trace -> trace.put( "path", node.path() ), - () -> NodeHasChildResolver.create(). - searchService( this.nodeSearchService ). - build(). - resolve( node.path() ), + return Tracer.trace( "node.hasChildren", trace -> { + trace.put( "path", node.path() ); + trace.put( "repo", ContextAccessor.current().getRepositoryId().toString() ); + trace.put( "branch", ContextAccessor.current().getBranch() ); + }, () -> NodeHasChildResolver.create().searchService( this.nodeSearchService ).build().resolve( node.path() ), ( trace, hasChildren ) -> trace.put( "hasChildren", hasChildren ) ); } diff --git a/modules/core/core-scheduler/src/main/java/com/enonic/xp/impl/scheduler/distributed/RescheduleTask.java b/modules/core/core-scheduler/src/main/java/com/enonic/xp/impl/scheduler/distributed/RescheduleTask.java index 56be8063934..c32db9ae27e 100644 --- a/modules/core/core-scheduler/src/main/java/com/enonic/xp/impl/scheduler/distributed/RescheduleTask.java +++ b/modules/core/core-scheduler/src/main/java/com/enonic/xp/impl/scheduler/distributed/RescheduleTask.java @@ -34,6 +34,7 @@ import com.enonic.xp.task.SubmitTaskParams; import com.enonic.xp.task.TaskId; import com.enonic.xp.task.TaskService; +import com.enonic.xp.trace.Tracer; public class RescheduleTask implements SchedulableTask @@ -137,16 +138,18 @@ public void run() private void doRun() { - final Map jobs = - OsgiSupport.withService( SchedulerService.class, schedulerService -> adminContext().callWith( schedulerService::list ) ) - .stream() - .collect( Collectors.toMap( ScheduledJob::getName, job -> job ) ); + Tracer.trace( "system.rescheduleTask", () -> { + final Map jobs = + OsgiSupport.withService( SchedulerService.class, schedulerService -> adminContext().callWith( schedulerService::list ) ) + .stream() + .collect( Collectors.toMap( ScheduledJob::getName, job -> job ) ); - fillJobsToSchedule( jobs ); + fillJobsToSchedule( jobs ); - final List failedJobs = scheduleJobs( jobs ); + final List failedJobs = scheduleJobs( jobs ); - retryFailedJobs( failedJobs ); + retryFailedJobs( failedJobs ); + } ); } private List scheduleJobs( final Map jobs )