-
Notifications
You must be signed in to change notification settings - Fork 45
Periodically Export Stacktraces From StagingArea #2298
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
Changes from 19 commits
23e6c9c
4dcbfeb
65922be
f291c53
2f631f8
5f13f30
7a3eb30
f7db0f1
1ca2291
1dd6131
55a58cd
fb83db2
0909970
4d03248
66dfc45
7e61fb1
7b48c90
28da0f8
ce6fde4
1327e7c
f798040
50b0b17
a45ff9b
6a0fa09
b7f8dea
ea9881c
b9ff741
b020a09
5d70bf9
1d293ab
c565d7f
37998fc
1c9dbda
4fc150b
3d630bb
96acf30
279cccb
421978b
960516e
07ea81f
b7378d3
1844b1f
9e7d1a4
feddbd5
fd0bb8e
1b2819a
e1141de
c27db01
677203c
39a5a90
2bb2c86
c0cb4a8
bb20b4c
3ecf6f9
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 |
|---|---|---|
|
|
@@ -81,6 +81,15 @@ public class Configuration implements AutoConfigurationCustomizerProvider { | |
| "splunk.snapshot.profiler.sampling.interval"; | ||
| private static final Duration DEFAULT_SNAPSHOT_PROFILER_SAMPLING_INTERVAL = Duration.ofMillis(10); | ||
|
|
||
| private static final String CONFIG_KEY_SNAPSHOT_PROFILER_STAGING_EMPTY_INTERVAL = | ||
| "splunk.snapshot.profiler.staging.empty.interval"; | ||
| private static final Duration DEFAULT_SNAPSHOT_PROFILER_STAGING_EMPTY_INTERVAL = | ||
| Duration.ofSeconds(5); | ||
|
||
|
|
||
| private static final String CONFIG_KEY_SNAPSHOT_PROFILER_STAGING_CAPACITY = | ||
| "splunk.snapshot.profiler.staging.capacity"; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sdk uses |
||
| private static final int DEFAULT_SNAPSHOT_PROFILER_STAGING_CAPACITY = 2000; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't have a reason for the chosen defaults. Happy to change them.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think 2000 is reasonable for start. |
||
|
|
||
| @Override | ||
| public void customize(AutoConfigurationCustomizer autoConfiguration) { | ||
| autoConfiguration.addPropertiesSupplier(this::defaultProperties); | ||
|
|
@@ -228,4 +237,15 @@ public static Duration getSnapshotProfilerSamplingInterval(ConfigProperties prop | |
| CONFIG_KEY_SNAPSHOT_PROFILER_SAMPLING_INTERVAL, | ||
| DEFAULT_SNAPSHOT_PROFILER_SAMPLING_INTERVAL); | ||
| } | ||
|
|
||
| public static Duration getSnapshotProfilerStagingEmptyInterval(ConfigProperties properties) { | ||
| return properties.getDuration( | ||
| CONFIG_KEY_SNAPSHOT_PROFILER_STAGING_EMPTY_INTERVAL, | ||
| DEFAULT_SNAPSHOT_PROFILER_STAGING_EMPTY_INTERVAL); | ||
| } | ||
|
|
||
| public static int getSnapshotProfilerStagingCapacity(ConfigProperties properties) { | ||
| return properties.getInt( | ||
| CONFIG_KEY_SNAPSHOT_PROFILER_STAGING_CAPACITY, DEFAULT_SNAPSHOT_PROFILER_STAGING_CAPACITY); | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /* | ||
| * Copyright Splunk Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.splunk.opentelemetry.profiler.snapshot; | ||
|
|
||
| import com.splunk.opentelemetry.profiler.util.HelpfulExecutors; | ||
| import java.io.Closeable; | ||
| import java.time.Duration; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
| import java.util.concurrent.ScheduledExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Supplier; | ||
|
|
||
| class PeriodicallyExportingStagingArea implements StagingArea, Closeable { | ||
| private final ScheduledExecutorService scheduler = | ||
| HelpfulExecutors.newSingleThreadedScheduledExecutor("periodically-exporting-staging-area"); | ||
| private final Set<StackTrace> stackTraces = Collections.newSetFromMap(new ConcurrentHashMap<>()); | ||
laurit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| private final Supplier<StackTraceExporter> exporter; | ||
| private final int capacity; | ||
| private volatile boolean closed = false; | ||
|
|
||
| PeriodicallyExportingStagingArea( | ||
| Supplier<StackTraceExporter> exporter, Duration emptyDuration, int capacity) { | ||
| this.exporter = exporter; | ||
| this.capacity = capacity; | ||
| scheduler.scheduleAtFixedRate( | ||
| this::empty, emptyDuration.toMillis(), emptyDuration.toMillis(), TimeUnit.MILLISECONDS); | ||
| } | ||
|
|
||
| @Override | ||
| public void stage(StackTrace stackTrace) { | ||
| if (closed) { | ||
| return; | ||
| } | ||
| stackTraces.add(stackTrace); | ||
| if (stackTraces.size() >= capacity) { | ||
laurit marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| empty(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void empty() { | ||
| if (stackTraces.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| List<StackTrace> stackTracesToExport = new ArrayList<>(stackTraces); | ||
| exporter.get().export(stackTracesToExport); | ||
| stackTracesToExport.forEach(stackTraces::remove); | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| this.closed = true; | ||
|
|
||
| stopScheduledExecutor(); | ||
| empty(); | ||
| } | ||
|
|
||
| private void stopScheduledExecutor() { | ||
| try { | ||
| scheduler.shutdown(); | ||
| if (!scheduler.awaitTermination(1, TimeUnit.SECONDS)) { | ||
| scheduler.shutdownNow(); | ||
| } | ||
| } catch (InterruptedException e) { | ||
| scheduler.shutdownNow(); | ||
| Thread.currentThread().interrupt(); | ||
| } | ||
|
||
| } | ||
| } | ||
laurit marked this conversation as resolved.
Show resolved
Hide resolved
|
laurit marked this conversation as resolved.
Show resolved
Hide resolved
|
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.
Perhaps use
splunk.snapshot.profiler.export.interval? The fact that the implementation stages the stacks somehow is irrelevant for users. Sdk usesotel.bsp.schedule.delayfor similar purpose.