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 worker versioning via spring boot autoconfig #1869

Merged
merged 1 commit into from
Oct 2, 2023
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 @@ -32,6 +32,7 @@ public class WorkerProperties {
private final @Nullable Collection<String> activityBeans;
private final @Nullable CapacityConfigurationProperties capacity;
private final @Nullable RateLimitsConfigurationProperties rateLimits;
private final @Nullable BuildIdConfigurationProperties buildId;

@ConstructorBinding
public WorkerProperties(
Expand All @@ -40,13 +41,15 @@ public WorkerProperties(
@Nullable Collection<Class<?>> workflowClasses,
@Nullable Collection<String> activityBeans,
@Nullable CapacityConfigurationProperties capacity,
@Nullable RateLimitsConfigurationProperties rateLimits) {
@Nullable RateLimitsConfigurationProperties rateLimits,
@Nullable BuildIdConfigurationProperties buildId) {
this.name = name;
this.taskQueue = taskQueue;
this.workflowClasses = workflowClasses;
this.activityBeans = activityBeans;
this.capacity = capacity;
this.rateLimits = rateLimits;
this.buildId = buildId;
}

@Nonnull
Expand Down Expand Up @@ -79,6 +82,11 @@ public RateLimitsConfigurationProperties getRateLimits() {
return rateLimits;
}

@Nullable
public BuildIdConfigurationProperties getBuildId() {
return buildId;
}

public static class CapacityConfigurationProperties {
private final @Nullable Integer maxConcurrentWorkflowTaskExecutors;
private final @Nullable Integer maxConcurrentActivityExecutors;
Expand Down Expand Up @@ -166,4 +174,32 @@ public Double getMaxTaskQueueActivitiesPerSecond() {
return maxTaskQueueActivitiesPerSecond;
}
}

public static class BuildIdConfigurationProperties {
private final @Nullable String workerBuildId;
private final @Nullable boolean enabledWorkerVersioning;

/**
* @param workerBuildId defines {@link
* io.temporal.worker.WorkerOptions.Builder#setBuildId(String)}}
* @param enabledWorkerVersioning defines {@link
* io.temporal.worker.WorkerOptions.Builder#setUseBuildIdForVersioning(boolean)}
*/
@ConstructorBinding
public BuildIdConfigurationProperties(
@Nullable String workerBuildId, @Nullable boolean enabledWorkerVersioning) {
this.workerBuildId = workerBuildId;
this.enabledWorkerVersioning = enabledWorkerVersioning;
}

@Nullable
public String getWorkerBuildId() {
return workerBuildId;
}

@Nullable
public boolean getEnabledWorkerVersioning() {
return enabledWorkerVersioning;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,16 @@ WorkerOptions createWorkerOptions() {
Optional.ofNullable(rateLimitConfiguration.getMaxTaskQueueActivitiesPerSecond())
.ifPresent(options::setMaxTaskQueueActivitiesPerSecond);
}
}

WorkerProperties.BuildIdConfigurationProperties buildIdConfigurations =
workerProperties.getBuildId();
if (buildIdConfigurations != null) {
Optional.ofNullable(buildIdConfigurations.getWorkerBuildId())
.ifPresent(options::setBuildId);
Optional.ofNullable(buildIdConfigurations.getEnabledWorkerVersioning())
.ifPresent(options::setUseBuildIdForVersioning);
}
}
if (customizer != null) {
options = customizer.customize(options);
if (customizer instanceof WorkerOptionsCustomizer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ public TemporalOptionsCustomizer<WorkerOptions.Builder> workerCustomizer() {
1.0,
options.getMaxTaskQueueActivitiesPerSecond(),
"Values from the Spring Config should be respected");

assertEquals(
"1.0.0", options.getBuildId(), "Values from the Spring Config should be respected");
assertEquals(
true,
options.isUsingBuildIdForVersioning(),
"Values from the Spring Config should be respected");
return optionsBuilder;
};
return mock(TemporalOptionsCustomizer.class, delegatesTo(customizer));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ spring:
rate-limits:
max-worker-activities-per-second: 1.0
max-task-queue-activities-per-second: 1.0
build-id:
worker-build-id: "1.0.0"
enabled-worker-versioning: true
workflow-cache:
max-instances: 10
max-threads: 10
Expand Down