Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ public class InferredProxyContext implements ImplicitContextKeyed {
ContextKey.named("inferred-proxy-key");
private final Map<String, String> inferredProxy;

// at most 6 x-dd-proxy http headers to be extracted and stored into the Context hashmap,
// following API Gateway RFC
private final int DEFAULT_CAPACITY = 6;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HashMap uses a load factor of 0.75, so if you use 6 as the initial capacity it will rehash when you add the 5th entry

I'd suggest using a capacity of 8 (6 / 0.75) which would let you add 6 entries without rehashing.


public static InferredProxyContext fromContext(Context context) {
return context.get(CONTEXT_KEY);
}

public InferredProxyContext(Map<String, String> contextInfo) {
this.inferredProxy =
(contextInfo == null || contextInfo.isEmpty())
? new HashMap<>()
? new HashMap<>(DEFAULT_CAPACITY)
: new HashMap<>(contextInfo);
}

public InferredProxyContext() {
this.inferredProxy = new HashMap<>();
this.inferredProxy = new HashMap<>(DEFAULT_CAPACITY);
}

public Map<String, String> getInferredProxyContext() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import datadog.context.Context;
import datadog.context.InferredProxyContext;
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiConsumer;

public class InferredProxyPropagator implements Propagator {
Expand Down Expand Up @@ -48,11 +46,6 @@ public static class InferredProxyContextExtractor implements BiConsumer<String,

InferredProxyContextExtractor() {}

private Map<String, String> parseInferredProxyHeaders(String input) {
Map<String, String> parsedHeaders = new HashMap<>();
return parsedHeaders;
}

/**
* Performs this operation on the given arguments.
*
Expand All @@ -64,7 +57,6 @@ public void accept(String key, String value) {
if (key == null || key.isEmpty() || !key.startsWith(INFERRED_PROXY_KEY)) {
return;
}
Map<String, String> inferredProxyMap = parseInferredProxyHeaders(value);
if (extractedContext == null) {
extractedContext = new InferredProxyContext();
}
Expand Down
Loading