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 storage-throttle module/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. Making sure RejectedExecutionExceptions are "first class" citizens since they are used to reduce the throttle. Removing HttpCall's Semaphore in favor of the throttle (same purpose, different implementations). Inspired by work done on openzipkin#2169.
- Loading branch information
Showing
23 changed files
with
1,063 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright 2015-2019 The OpenZipkin Authors | ||
Licensed 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. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>io.zipkin.java</groupId> | ||
<artifactId>zipkin-autoconfigure</artifactId> | ||
<version>2.12.10-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>zipkin-autoconfigure-storage-throttle</artifactId> | ||
<name>Auto Configuration: Storage Throttle</name> | ||
|
||
<properties> | ||
<main.basedir>${project.basedir}/../..</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.zipkin.zipkin2</groupId> | ||
<artifactId>zipkin-storage-throttle</artifactId> | ||
</dependency> | ||
</dependencies> | ||
</project> |
62 changes: 62 additions & 0 deletions
62
...src/main/java/zipkin2/autoconfigure/storage/throttle/ZipkinStorageThrottleProperties.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,62 @@ | ||
/* | ||
* Copyright 2015-2019 The OpenZipkin Authors | ||
* | ||
* Licensed 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.autoconfigure.storage.throttle; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("zipkin.storage.throttle") | ||
public class ZipkinStorageThrottleProperties { | ||
/** Should we throttle at all? */ | ||
private boolean enabled; | ||
/** Minimum number of storage requests to allow through at a given time. */ | ||
private int minConcurrency; | ||
/** Maximum number of storage requests to allow through at a given time. */ | ||
private int maxConcurrency; | ||
/** | ||
* Maximum number of storage requests to buffer while waiting for open Thread. | ||
* 0 = no buffering. */ | ||
private int maxQueueSize; | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public int getMinConcurrency() { | ||
return minConcurrency; | ||
} | ||
|
||
public void setMinConcurrency(int minConcurrency) { | ||
this.minConcurrency = minConcurrency; | ||
} | ||
|
||
public int getMaxConcurrency() { | ||
return maxConcurrency; | ||
} | ||
|
||
public void setMaxConcurrency(int maxConcurrency) { | ||
this.maxConcurrency = maxConcurrency; | ||
} | ||
|
||
public int getMaxQueueSize() { | ||
return maxQueueSize; | ||
} | ||
|
||
public void setMaxQueueSize(int maxQueueSize) { | ||
this.maxQueueSize = maxQueueSize; | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
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,43 @@ | ||
/* | ||
* Copyright 2015-2019 The OpenZipkin Authors | ||
* | ||
* Licensed 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}) | ||
public @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(); | ||
} | ||
} | ||
} |
Oops, something went wrong.