Skip to content

Commit

Permalink
Trace node api does not contain repo and branch #10458
Browse files Browse the repository at this point in the history
  • Loading branch information
rymsha committed Mar 14, 2024
1 parent e40dc34 commit 55fed48
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() ) );
}

Expand All @@ -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() ) );
}

Expand Down Expand Up @@ -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() );
Expand All @@ -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() ) );
}

Expand Down Expand Up @@ -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 )
Expand All @@ -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 )
Expand All @@ -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() ) ) );
}

Expand Down Expand Up @@ -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() ) );
}

Expand Down Expand Up @@ -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() ) );
}

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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 ) );
}

Expand Down Expand Up @@ -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 ) );
Expand All @@ -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
Expand All @@ -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 ) );

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,16 +138,18 @@ public void run()

private void doRun()
{
final Map<ScheduledJobName, ScheduledJob> jobs =
OsgiSupport.withService( SchedulerService.class, schedulerService -> adminContext().callWith( schedulerService::list ) )
.stream()
.collect( Collectors.toMap( ScheduledJob::getName, job -> job ) );
Tracer.trace( "system.rescheduleTask", () -> {
final Map<ScheduledJobName, ScheduledJob> jobs =
OsgiSupport.withService( SchedulerService.class, schedulerService -> adminContext().callWith( schedulerService::list ) )
.stream()
.collect( Collectors.toMap( ScheduledJob::getName, job -> job ) );

fillJobsToSchedule( jobs );
fillJobsToSchedule( jobs );

final List<FailedJob> failedJobs = scheduleJobs( jobs );
final List<FailedJob> failedJobs = scheduleJobs( jobs );

retryFailedJobs( failedJobs );
retryFailedJobs( failedJobs );
} );
}

private List<FailedJob> scheduleJobs( final Map<ScheduledJobName, ScheduledJob> jobs )
Expand Down

0 comments on commit 55fed48

Please sign in to comment.