-
Notifications
You must be signed in to change notification settings - Fork 32
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
Print long running work for debugging #564
Changes from 10 commits
d166f24
c3f8477
eb9d957
02027a1
9856daa
69f2c6d
c58661d
9631c06
20d333b
8134dbb
2605255
ad7cd40
0e2ce10
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 |
---|---|---|
@@ -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(); | ||
} | ||
} |
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(); | ||
} | ||
} |
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); | ||
} | ||
Check warning on line 17 in TrafficCapture/coreUtilities/src/main/java/org/opensearch/migrations/tracing/CompositeContextTracker.java
|
||
|
||
@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(); | ||
Check warning on line 30 in TrafficCapture/coreUtilities/src/main/java/org/opensearch/migrations/tracing/CompositeContextTracker.java
|
||
} | ||
} |
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() {}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to make sure I understand why we're using each of these:
Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty much. startTime is for logs correlation. I've added these comments to the base interface to explain...