santosh-d3vpl3x commented on code in PR #18843: URL: https://github.com/apache/druid/pull/18843#discussion_r2901256129
########## extensions-contrib/consul-extensions/src/main/java/org/apache/druid/consul/discovery/ConsulDiscoveryConfig.java: ########## @@ -0,0 +1,770 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.druid.consul.discovery; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.druid.java.util.common.IAE; +import org.apache.druid.java.util.common.StringUtils; +import org.apache.druid.java.util.common.logger.Logger; +import org.joda.time.Duration; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Configuration for Consul-based service discovery. + */ +public class ConsulDiscoveryConfig +{ + private static final Logger LOGGER = new Logger(ConsulDiscoveryConfig.class); + private static final long MIN_LEADER_SESSION_TTL_SECONDS = 10; + + @JsonProperty("connection") + private final ConnectionConfig connection; + + @JsonProperty("auth") + private final AuthConfig auth; + + @JsonProperty("service") + private final ServiceConfig service; + + @JsonProperty("leader") + private final LeaderElectionConfig leader; + + @JsonProperty("watch") + private final WatchConfig watch; + + @JsonCreator + public static ConsulDiscoveryConfig create( + @JsonProperty("connection") @Nullable ConnectionConfig connection, + @JsonProperty("auth") @Nullable AuthConfig auth, + @JsonProperty("service") ServiceConfig service, + @JsonProperty("leader") @Nullable LeaderElectionConfig leader, + @JsonProperty("watch") @Nullable WatchConfig watch + ) + { + if (service == null) { + throw new IAE("service cannot be null"); + } + + LeaderElectionConfig finalLeader = computeLeaderElectionConfig(leader, service.getHealthCheckInterval()); + return new ConsulDiscoveryConfig(connection, auth, service, finalLeader, watch); + } + + private static LeaderElectionConfig computeLeaderElectionConfig( + @Nullable LeaderElectionConfig leader, + Duration healthCheckInterval + ) + { + if (leader != null) { + // Compute default TTL based on health check interval when not explicitly set + if (leader.getLeaderSessionTtl() == null) { + return new LeaderElectionConfig( + leader.getCoordinatorLeaderLockPath(), + leader.getOverlordLeaderLockPath(), + null, + leader.getLeaderMaxErrorRetries(), + leader.getLeaderRetryBackoffMax(), + healthCheckInterval + ); + } else { + return leader; + } + } else { + return new LeaderElectionConfig(null, null, null, null, null, healthCheckInterval); + } Review Comment: Fixed by tracking whether `leaderSessionTtl` was explicitly provided and recomputing the default from `healthCheckInterval` when the `leader` block omits it. That keeps the documented `max(45s, 3 * healthCheckInterval)` behavior intact after Jackson deserialization. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
