Skip to content

Commit

Permalink
Update from fluxninja/aperture
Browse files Browse the repository at this point in the history
  • Loading branch information
fluxninjaops committed Dec 5, 2023
1 parent 08ff7f4 commit 778fc51
Show file tree
Hide file tree
Showing 8 changed files with 406 additions and 4 deletions.
35 changes: 33 additions & 2 deletions lib/core/src/main/java/com/fluxninja/aperture/sdk/ApertureSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.fluxninja.aperture.sdk.Constants.SOURCE_LABEL;
import static com.fluxninja.aperture.sdk.Constants.WORKLOAD_START_TIMESTAMP_LABEL;

import com.fluxninja.generated.aperture.flowcontrol.check.v1.CacheLookupRequest;
import com.fluxninja.generated.aperture.flowcontrol.check.v1.CheckRequest;
import com.fluxninja.generated.aperture.flowcontrol.check.v1.CheckResponse;
import com.fluxninja.generated.aperture.flowcontrol.check.v1.FlowControlServiceGrpc;
Expand Down Expand Up @@ -85,7 +86,15 @@ public Flow startFlow(FeatureFlowParameters parameters) {
} catch (java.io.UnsupportedEncodingException e) {
// This should never happen, as `StandardCharsets.UTF_8.name()` is a valid
// encoding
throw new RuntimeException(e);
return new Flow(
null,
null,
false,
parameters.getRampMode(),
this.flowControlClient,
parameters.getResultCacheKey(),
parameters.getControlPoint(),
e);
}
labels.put(entry.getKey(), value);
}
Expand All @@ -99,6 +108,11 @@ public Flow startFlow(FeatureFlowParameters parameters) {
.setControlPoint(parameters.getControlPoint())
.putAllLabels(labels)
.setRampMode(parameters.getRampMode())
.setCacheLookupRequest(
CacheLookupRequest.newBuilder()
.addAllGlobalCacheKeys(parameters.getGlobalCacheKeys())
.setResultCacheKey(parameters.getResultCacheKey())
.build())
.build();

Span span =
Expand All @@ -121,10 +135,27 @@ public Flow startFlow(FeatureFlowParameters parameters) {
}
} catch (StatusRuntimeException e) {
// deadline exceeded or couldn't reach agent - request should not be blocked
return new Flow(
res,
span,
false,
parameters.getRampMode(),
this.flowControlClient,
parameters.getResultCacheKey(),
parameters.getControlPoint(),
e);
}
span.setAttribute(WORKLOAD_START_TIMESTAMP_LABEL, Utils.getCurrentEpochNanos());

return new Flow(res, span, false, parameters.getRampMode());
return new Flow(
res,
span,
false,
parameters.getRampMode(),
this.flowControlClient,
parameters.getResultCacheKey(),
parameters.getControlPoint(),
null);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.fluxninja.aperture.sdk;

import java.time.Duration;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class FeatureFlowParameters {
private String controlPoint;
private Map<String, String> explicitLabels;
private Boolean rampMode;
private Duration flowTimeout;
private String resultCacheKey;

private List<String> globalCacheKeys;

public static Builder newBuilder(String controlPoint) {
return new Builder(controlPoint);
Expand All @@ -34,6 +39,14 @@ public Duration getFlowTimeout() {
return flowTimeout;
}

public String getResultCacheKey() {
return resultCacheKey;
}

public List<String> getGlobalCacheKeys() {
return globalCacheKeys;
}

public static class Builder {
private final FeatureFlowParameters params;

Expand All @@ -44,6 +57,8 @@ public Builder(String controlPoint) {
params.explicitLabels = new HashMap<>();
params.rampMode = false;
params.flowTimeout = Constants.DEFAULT_RPC_TIMEOUT;
params.resultCacheKey = "";
params.globalCacheKeys = Collections.emptyList();
}

/**
Expand Down Expand Up @@ -80,6 +95,39 @@ public Builder setFlowTimeout(Duration flowTimeout) {
return this;
}

/**
* Set the result cache key for result cache request
*
* @param resultCacheKey The result cache key
* @return This builder for method chaining
*/
public Builder setResultCacheKey(String resultCacheKey) {
params.resultCacheKey = resultCacheKey;
return this;
}

/**
* Add global cache keys for global cache request
*
* @param globalCacheKeys The global cache keys to add
* @return This builder for method chaining
*/
public Builder addGlobalCacheKeys(List<String> globalCacheKeys) {
params.globalCacheKeys.addAll(globalCacheKeys);
return this;
}

/**
* Add a global cache key for global cache request
*
* @param globalCacheKey The global cache key to add
* @return This builder for method chaining
*/
public Builder addGlobalCacheKey(String globalCacheKey) {
params.globalCacheKeys.add(globalCacheKey);
return this;
}

/**
* Build the FeatureFlowParameters object with the provided parameters.
*
Expand Down
Loading

0 comments on commit 778fc51

Please sign in to comment.