-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #564 from gregschohn/PrintLongRunningWorkForDebugg…
…ingPart2 Print long running work for debugging
- Loading branch information
Showing
43 changed files
with
1,885 additions
and
838 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...e/coreUtilities/src/main/java/org/opensearch/migrations/tracing/ActiveContextTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.opensearch.migrations.tracing; | ||
|
||
import java.util.Comparator; | ||
import java.util.concurrent.ConcurrentSkipListSet; | ||
import java.util.stream.Stream; | ||
|
||
public class ActiveContextTracker implements IContextTracker { | ||
final ConcurrentSkipListSet<IScopedInstrumentationAttributes> orderedScopes; | ||
|
||
public ActiveContextTracker() { | ||
orderedScopes = makeScopeSkipList(); | ||
} | ||
|
||
static ConcurrentSkipListSet<IScopedInstrumentationAttributes> makeScopeSkipList() { | ||
return new ConcurrentSkipListSet<>(Comparator | ||
.comparingLong(IWithStartTimeAndAttributes::getStartTimeNano) | ||
.thenComparingInt(System::identityHashCode)); | ||
} | ||
|
||
@Override | ||
public void onContextCreated(IScopedInstrumentationAttributes scopedContext) { | ||
orderedScopes.add(scopedContext); | ||
} | ||
|
||
@Override | ||
public void onContextClosed(IScopedInstrumentationAttributes scopedContext) { | ||
orderedScopes.remove(scopedContext); | ||
} | ||
|
||
public Stream<IScopedInstrumentationAttributes> getActiveScopesByAge() { | ||
return orderedScopes.stream(); | ||
} | ||
|
||
public long size() { | ||
return orderedScopes.size(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...s/src/main/java/org/opensearch/migrations/tracing/ActiveContextTrackerByActivityType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package org.opensearch.migrations.tracing; | ||
|
||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentSkipListSet; | ||
import java.util.stream.Stream; | ||
|
||
public class ActiveContextTrackerByActivityType implements IContextTracker { | ||
final ConcurrentHashMap<Class<IScopedInstrumentationAttributes>, | ||
ConcurrentSkipListSet<IScopedInstrumentationAttributes>> orderedScopesByScopeType; | ||
|
||
public ActiveContextTrackerByActivityType() { | ||
orderedScopesByScopeType = new ConcurrentHashMap<>(); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public void onContextCreated(IScopedInstrumentationAttributes scopedContext) { | ||
orderedScopesByScopeType | ||
.computeIfAbsent((Class<IScopedInstrumentationAttributes>)scopedContext.getClass(), | ||
c->ActiveContextTracker.makeScopeSkipList()) | ||
.add(scopedContext); | ||
} | ||
|
||
@Override | ||
public void onContextClosed(IScopedInstrumentationAttributes scopedContext) { | ||
final var skipListByType = orderedScopesByScopeType.get(scopedContext.getClass()); | ||
assert skipListByType != null : "expected to have already added the scope to the collection, " + | ||
"so the top-level class mapping should be present"; | ||
skipListByType.remove(scopedContext); | ||
} | ||
|
||
public Stream<IScopedInstrumentationAttributes> | ||
getOldestActiveScopes(Class<IScopedInstrumentationAttributes> activityType) { | ||
return Optional.ofNullable(orderedScopesByScopeType.getOrDefault(activityType, null)) | ||
.stream() | ||
.flatMap(Collection::stream); | ||
} | ||
|
||
public Stream<Class<IScopedInstrumentationAttributes>> getActiveScopeTypes() { | ||
return orderedScopesByScopeType.entrySet().stream() | ||
.filter(kvp->!kvp.getValue().isEmpty()) | ||
.map(Map.Entry::getKey); | ||
} | ||
|
||
public long numScopesFor(Class<IScopedInstrumentationAttributes> c) { | ||
return orderedScopesByScopeType.get(c).size(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...oreUtilities/src/main/java/org/opensearch/migrations/tracing/CompositeContextTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.opensearch.migrations.tracing; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class CompositeContextTracker implements IContextTracker { | ||
private final List<IContextTracker> trackers; | ||
|
||
public CompositeContextTracker(IContextTracker...trackers) { | ||
this.trackers = Arrays.stream(trackers).collect(Collectors.toUnmodifiableList()); | ||
} | ||
public CompositeContextTracker(List<IContextTracker> trackers) { | ||
this.trackers = new ArrayList<>(trackers); | ||
} | ||
|
||
@Override | ||
public void onContextCreated(IScopedInstrumentationAttributes scopedContext) { | ||
trackers.forEach(ct->ct.onContextCreated(scopedContext)); | ||
} | ||
|
||
@Override | ||
public void onContextClosed(IScopedInstrumentationAttributes scopedContext) { | ||
trackers.forEach(ct->ct.onContextClosed(scopedContext)); | ||
} | ||
|
||
public Stream<IContextTracker> getTrackers() { | ||
return trackers.stream(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...apture/coreUtilities/src/main/java/org/opensearch/migrations/tracing/IContextTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.opensearch.migrations.tracing; | ||
|
||
/** | ||
* For debugging or observability purposes, this interface allows for tracking the | ||
* creation and termination of activities (such as those with spans). | ||
*/ | ||
public interface IContextTracker { | ||
default void onContextCreated(IScopedInstrumentationAttributes newScopedContext) {} | ||
|
||
/** | ||
* This can be overridden to track creation and termination of spans | ||
*/ | ||
default void onContextClosed(IScopedInstrumentationAttributes newScopedContext) {} | ||
|
||
final static IContextTracker DO_NOTHING_TRACKER = new IContextTracker() {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.