forked from openzipkin/zipkin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 openzipkin#2169.
- Loading branch information
Showing
18 changed files
with
1,194 additions
and
2 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
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
60 changes: 60 additions & 0 deletions
60
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,60 @@ | ||
/* | ||
* 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; | ||
import com.netflix.concurrency.limits.limiter.AbstractLimiter; | ||
import io.micrometer.core.instrument.Gauge; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
final class ActuateThrottleMetrics { | ||
private final MeterRegistry registryInstance; | ||
|
||
public ActuateThrottleMetrics(MeterRegistry registryInstance) { | ||
this.registryInstance = registryInstance; | ||
} | ||
|
||
public void bind(ExecutorService executor) { | ||
if(!(executor instanceof ThreadPoolExecutor)){ | ||
return; | ||
} | ||
|
||
ThreadPoolExecutor pool = (ThreadPoolExecutor) executor; | ||
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); | ||
} | ||
|
||
public void bind(Limiter<Void> limiter) { | ||
if(!(limiter instanceof AbstractLimiter)){ | ||
return; | ||
} | ||
|
||
AbstractLimiter abstractLimiter = (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", abstractLimiter::getInflight) | ||
.description("number of requests the limiter thinks are active") | ||
.register(registryInstance); | ||
} | ||
} |
Oops, something went wrong.