Skip to content
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

Expose additional disk buffering configuration #596

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,15 @@ private StorageConfiguration createStorageConfiguration(ServiceManager serviceMa
throws IOException {
Preferences preferences = serviceManager.getPreferences();
CacheStorage storage = serviceManager.getCacheStorage();
DiskManager diskManager =
new DiskManager(storage, preferences, config.getDiskBufferingConfiguration());
DiskBufferingConfiguration config = this.config.getDiskBufferingConfiguration();
DiskManager diskManager = new DiskManager(storage, preferences, config);
return StorageConfiguration.builder()
.setRootDir(diskManager.getSignalsBufferDir())
.setMaxFileSize(diskManager.getMaxCacheFileSize())
.setMaxFolderSize(diskManager.getMaxFolderSize())
.setRootDir(diskManager.getSignalsBufferDir())
.setMaxFileAgeForWriteMillis(config.getMaxFileAgeForWriteMillis())
.setMaxFileAgeForReadMillis(config.getMaxFileAgeForReadMillis())
.setMinFileAgeForReadMillis(config.getMinFileAgeForReadMillis())
.setTemporaryFileProvider(
new SimpleTemporaryFileProvider(diskManager.getTemporaryDir()))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,29 @@

import io.opentelemetry.android.features.diskbuffering.scheduler.DefaultExportScheduleHandler;
import io.opentelemetry.android.features.diskbuffering.scheduler.ExportScheduleHandler;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

/** Configuration for disk buffering. */
public final class DiskBufferingConfiguration {
private static final int DEFAULT_MAX_CACHE_SIZE = 60 * 1024 * 1024;
private static final int MAX_FILE_SIZE = 1024 * 1024;

private final boolean enabled;
private final int maxCacheSize;
private final ExportScheduleHandler exportScheduleHandler;
private static final int DEFAULT_MAX_CACHE_SIZE = 60 * 1024 * 1024;
private static final int MAX_FILE_SIZE = 1024 * 1024;
private final long maxFileAgeForWriteMillis;
private final long minFileAgeForReadMillis;
private final long maxFileAgeForReadMillis;

private DiskBufferingConfiguration(Builder builder) {
this.enabled = builder.enabled;
this.maxCacheSize = builder.maxCacheSize;
this.exportScheduleHandler = builder.exportScheduleHandler;
enabled = builder.enabled;
maxCacheSize = builder.maxCacheSize;
exportScheduleHandler = builder.exportScheduleHandler;
maxFileAgeForWriteMillis = builder.maxFileAgeForWriteMillis;
minFileAgeForReadMillis = builder.minFileAgeForReadMillis;
maxFileAgeForReadMillis = builder.maxFileAgeForReadMillis;
}

public static Builder builder() {
Expand All @@ -42,9 +52,25 @@ public ExportScheduleHandler getExportScheduleHandler() {
return exportScheduleHandler;
}

public long getMaxFileAgeForWriteMillis() {
return maxFileAgeForWriteMillis;
}

public long getMaxFileAgeForReadMillis() {
return maxFileAgeForReadMillis;
}

public long getMinFileAgeForReadMillis() {
return minFileAgeForReadMillis;
}

public static final class Builder {
private boolean enabled = false;
private int maxCacheSize = DEFAULT_MAX_CACHE_SIZE;
private long maxFileAgeForWriteMillis = TimeUnit.SECONDS.toMillis(30);
private long minFileAgeForReadMillis = TimeUnit.SECONDS.toMillis(33);
private long maxFileAgeForReadMillis = TimeUnit.HOURS.toMillis(18);

private ExportScheduleHandler exportScheduleHandler = DefaultExportScheduleHandler.create();

/** Enables or disables disk buffering. */
Expand All @@ -53,6 +79,30 @@ public Builder setEnabled(boolean enabled) {
return this;
}

/** Sets the max amount of time a file can receive new data. Default is 30 seconds. */
public Builder setMaxFileAgeForWriteMillis(long maxFileAgeForWriteMillis) {
this.maxFileAgeForWriteMillis = maxFileAgeForWriteMillis;
return this;
}

/**
* Sets the min amount of time that must pass before a file is read. This value must be
* greater than maxFileAgeForWriteMillis.
*/
public Builder setMinFileAgeForReadMillis(long minFileAgeForReadMillis) {
this.minFileAgeForReadMillis = minFileAgeForReadMillis;
return this;
}

/**
* Sets the max age in ms for which a file is considered not-stale. Files older than this
* will be dropped.
*/
public Builder setMaxFileAgeForReadMillis(long maxFileAgeForReadMillis) {
this.maxFileAgeForReadMillis = maxFileAgeForReadMillis;
return this;
}

/**
* Sets the maximum amount of bytes that this tool can use to store cached signals in disk.
* A smaller amount of space will be used if there's not enough space in disk to allocate
Expand All @@ -73,6 +123,21 @@ public Builder setExportScheduleHandler(ExportScheduleHandler exportScheduleHand
}

public DiskBufferingConfiguration build() {
// See note in StorageConfiguration.getMinFileAgeForReadMillis()
if (minFileAgeForReadMillis <= maxFileAgeForWriteMillis) {
Logger logger = Logger.getLogger(DiskBufferingConfiguration.class.getName());
logger.log(
Level.WARNING,
"minFileAgeForReadMillis must be greater than maxFileAgeForWriteMillis");
logger.log(
Level.WARNING,
"overriding minFileAgeForReadMillis from "
+ minFileAgeForReadMillis
+ " to "
+ minFileAgeForReadMillis
+ 5);
minFileAgeForReadMillis = maxFileAgeForWriteMillis + 5;
}
return new DiskBufferingConfiguration(this);
}
}
Expand Down