-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable rate limits to automatically update based on the amount of ava…
…ilable preprocessors (#1215) * Enable rate limits to automatically scale based on the amount of available preprocessors. This should effectively unlock the ability to enable autoscaling on preprocessors as a whole * Remove this bit * Readd this other bit
- Loading branch information
1 parent
dd6e2ac
commit 35bdc0a
Showing
12 changed files
with
307 additions
and
12 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
33 changes: 33 additions & 0 deletions
33
astra/src/main/java/com/slack/astra/metadata/preprocessor/PreprocessorMetadata.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,33 @@ | ||
package com.slack.astra.metadata.preprocessor; | ||
|
||
import com.slack.astra.metadata.core.AstraMetadata; | ||
import java.util.UUID; | ||
|
||
/** A container for all the metadata needed by preprocessors. */ | ||
public class PreprocessorMetadata extends AstraMetadata { | ||
|
||
public PreprocessorMetadata() { | ||
super(UUID.randomUUID().toString()); | ||
} | ||
|
||
public PreprocessorMetadata(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof PreprocessorMetadata that)) return false; | ||
return !super.equals(o); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return super.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PreprocessorMetadata{" + '\'' + "name='" + name + '\'' + '}'; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...a/src/main/java/com/slack/astra/metadata/preprocessor/PreprocessorMetadataSerializer.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,33 @@ | ||
package com.slack.astra.metadata.preprocessor; | ||
|
||
import com.google.protobuf.InvalidProtocolBufferException; | ||
import com.google.protobuf.util.JsonFormat; | ||
import com.slack.astra.metadata.core.MetadataSerializer; | ||
import com.slack.astra.proto.metadata.Metadata; | ||
|
||
public class PreprocessorMetadataSerializer implements MetadataSerializer<PreprocessorMetadata> { | ||
private static PreprocessorMetadata fromPreprocessorMetadataProto( | ||
Metadata.PreprocessorMetadata preprocessorMetadataProto) { | ||
return new PreprocessorMetadata(preprocessorMetadataProto.getName()); | ||
} | ||
|
||
private static Metadata.PreprocessorMetadata toPreprocessorMetadataProto( | ||
PreprocessorMetadata metadata) { | ||
return Metadata.PreprocessorMetadata.newBuilder().setName(metadata.name).build(); | ||
} | ||
|
||
@Override | ||
public String toJsonStr(PreprocessorMetadata metadata) throws InvalidProtocolBufferException { | ||
if (metadata == null) throw new IllegalArgumentException("metadata object can't be null"); | ||
|
||
return printer.print(toPreprocessorMetadataProto(metadata)); | ||
} | ||
|
||
@Override | ||
public PreprocessorMetadata fromJsonStr(String data) throws InvalidProtocolBufferException { | ||
Metadata.PreprocessorMetadata.Builder preProcessorBuilder = | ||
Metadata.PreprocessorMetadata.newBuilder(); | ||
JsonFormat.parser().ignoringUnknownFields().merge(data, preProcessorBuilder); | ||
return fromPreprocessorMetadataProto(preProcessorBuilder.build()); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
astra/src/main/java/com/slack/astra/metadata/preprocessor/PreprocessorMetadataStore.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,27 @@ | ||
package com.slack.astra.metadata.preprocessor; | ||
|
||
import com.slack.astra.metadata.core.AstraMetadataStore; | ||
import com.slack.astra.proto.config.AstraConfigs; | ||
import org.apache.curator.x.async.AsyncCuratorFramework; | ||
import org.apache.zookeeper.CreateMode; | ||
|
||
public class PreprocessorMetadataStore extends AstraMetadataStore<PreprocessorMetadata> { | ||
public static final String PREPROCESSOR_ZK_PATH = "/preprocessors"; | ||
|
||
/** | ||
* Initializes a cache slot metadata store at the CACHE_SLOT_ZK_PATH. This should be used to | ||
* create/update the cache slots, and for listening to all cache slot events. | ||
*/ | ||
public PreprocessorMetadataStore( | ||
AsyncCuratorFramework curatorFramework, | ||
AstraConfigs.ZookeeperConfig zkConfig, | ||
boolean shouldCache) { | ||
super( | ||
curatorFramework, | ||
zkConfig, | ||
CreateMode.EPHEMERAL, | ||
shouldCache, | ||
new PreprocessorMetadataSerializer().toModelSerializer(), | ||
PREPROCESSOR_ZK_PATH); | ||
} | ||
} |
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
Oops, something went wrong.