-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding storage-throttle module to address "over capacity" issues (#2502)
Adding ThrottledStorageComponent/etc. to contain logic for wrapping other storage implementations and limiting the number of requests that can go through to them at a given time. Elasticsearch storage's maxRequests can be override by throttle properties if the throttle is enabled. Inspired by work done on #2169.
- Loading branch information
1 parent
7e6c076
commit b3eefbe
Showing
16 changed files
with
1,049 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
zipkin-server/src/main/java/zipkin2/server/internal/ConditionalOnThrottledStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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 zipkin2.server.internal; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; | ||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; | ||
import org.springframework.context.annotation.ConditionContext; | ||
import org.springframework.context.annotation.Conditional; | ||
import org.springframework.core.type.AnnotatedTypeMetadata; | ||
|
||
@Conditional(ConditionalOnThrottledStorage.ThrottledStorageCondition.class) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.TYPE, ElementType.METHOD}) | ||
@interface ConditionalOnThrottledStorage { | ||
class ThrottledStorageCondition extends SpringBootCondition { | ||
@Override | ||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata a) { | ||
String throttleEnabled = context.getEnvironment() | ||
.getProperty("zipkin.storage.throttle.enabled"); | ||
|
||
if (!Boolean.valueOf(throttleEnabled)) { | ||
return ConditionOutcome.noMatch("zipkin.storage.throttle.enabled isn't true"); | ||
} | ||
|
||
return ConditionOutcome.match(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
zipkin-server/src/main/java/zipkin2/server/internal/throttle/ActuateThrottleMetrics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 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 zipkin2.server.internal.throttle; | ||
|
||
import com.netflix.concurrency.limits.limiter.AbstractLimiter; | ||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
import zipkin2.server.internal.ActuateCollectorMetrics; | ||
|
||
/** Follows the same naming convention as {@link ActuateCollectorMetrics} */ | ||
final class ActuateThrottleMetrics { | ||
final MeterRegistry registryInstance; | ||
|
||
ActuateThrottleMetrics(MeterRegistry registryInstance) { | ||
this.registryInstance = registryInstance; | ||
} | ||
|
||
void bind(ThreadPoolExecutor pool) { | ||
Gauge.builder("zipkin_storage.throttle.concurrency", pool::getCorePoolSize) | ||
.description("number of threads running storage requests") | ||
.register(registryInstance); | ||
Gauge.builder("zipkin_storage.throttle.queue_size", pool.getQueue()::size) | ||
.description("number of items queued waiting for access to storage") | ||
.register(registryInstance); | ||
} | ||
|
||
void bind(AbstractLimiter limiter) { | ||
// This value should parallel (zipkin_storage.throttle.queue_size + zipkin_storage.throttle.concurrency) | ||
// It is tracked to make sure it doesn't perpetually increase. If it does then we're not resolving LimitListeners. | ||
Gauge.builder("zipkin_storage.throttle.in_flight_requests", limiter::getInflight) | ||
.description("number of requests the limiter thinks are active") | ||
.register(registryInstance); | ||
} | ||
} |
Oops, something went wrong.