-
Notifications
You must be signed in to change notification settings - Fork 304
Implement APIGW Inferred Proxy Spans #8336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
934f400
add draft inferred proxy spans as http request parent
jordan-wong d0aa92b
revert accidental change to docs
jordan-wong 25ec7b8
add draft http header parsing using Propagator design
jordan-wong 6e6f67b
add BiConsumer logic for header visitor
jordan-wong a67d0da
merge master
jordan-wong 7170583
merge master
jordan-wong bac390a
add misc fixes after merge master
jordan-wong 4e5d8c7
add inferred proxy config
jordan-wong 8216eb1
use inferred proxy config
jordan-wong 0724360
add in progress debugging for header parsing
jordan-wong 9938175
fix putting info in context object
jordan-wong ecee7d7
rename inferredProxySpan
jordan-wong 6141896
remove unused InferredProxyCodec
jordan-wong 3c74099
Merge branch 'master' into inferred-span-tags
jordan-wong c63ef4c
working version happy path using context
jordan-wong ddbc584
Merge branch 'master' into inferred-span-tags
zarirhamza 9abec59
refactor code, remove debugging printlns
jordan-wong b004c19
fixed code
zarirhamza 9016603
Merge branch 'master' into inferred-span-tags
zarirhamza 77119c7
add tests for inferredProxySpans
jordan-wong c9882da
remove comments
jordan-wong 1458e52
Merge branch 'master' into inferred-span-tags
zarirhamza bb26be8
Remove HttpServerDecorator.java.rej file
jordan-wong 27cfb94
Update integrations-core submodule to latest master
jordan-wong ca4d546
Undo change to integrations-core submodule
jordan-wong d71753e
remove inferredProxyContext inject, remove stub isApiGatewaySupported…
jordan-wong dfcc717
Merge branch 'master' into inferred-span-tags
jordan-wong d9f55c5
fix env var reading
zarirhamza 9c45d87
Merge branch 'master' into inferred-span-tags
zarirhamza 9ed4910
add tests
zarirhamza d73cee5
fix context
zarirhamza ce06b40
Merge branch 'master' into inferred-span-tags
zarirhamza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
components/context/src/main/java/datadog/context/InferredProxyContext.java
This file contains hidden or 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,50 @@ | ||
package datadog.context; | ||
|
||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class InferredProxyContext implements ImplicitContextKeyed { | ||
public static final ContextKey<InferredProxyContext> CONTEXT_KEY = | ||
ContextKey.named("inferred-proxy-key"); | ||
private final Map<String, String> inferredProxy; | ||
|
||
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<>(contextInfo); | ||
} | ||
|
||
public InferredProxyContext() { | ||
this.inferredProxy = new HashMap<>(); | ||
} | ||
|
||
public Map<String, String> getInferredProxyContext() { | ||
return Collections.unmodifiableMap(inferredProxy); | ||
} | ||
|
||
public void putInferredProxyInfo(String key, String value) { | ||
inferredProxy.put(key, value); | ||
} | ||
|
||
public void removeInferredProxyInfo(String key) { | ||
inferredProxy.remove(key); | ||
} | ||
|
||
/** | ||
* Creates a new context with this value under its chosen key. | ||
* | ||
* @param context the context to copy the original values from. | ||
* @return the new context with the implicitly keyed value. | ||
* @see Context#with(ImplicitContextKeyed) | ||
*/ | ||
@Override | ||
public Context storeInto(Context context) { | ||
return context.with(CONTEXT_KEY, this); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
components/context/src/main/java/datadog/context/propagation/InferredProxyPropagator.java
This file contains hidden or 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,74 @@ | ||
package datadog.context.propagation; | ||
|
||
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 { | ||
public static final String INFERRED_PROXY_KEY = "x-dd-proxy"; | ||
/** | ||
* METHOD STUB: InferredProxy is currently not meant to be injected to downstream services Injects | ||
* a context into a downstream service using the given carrier. | ||
* | ||
* @param context the context containing the values to be injected. | ||
* @param carrier the instance that will receive the key/value pairs to propagate. | ||
* @param setter the callback to set key/value pairs into the carrier. | ||
*/ | ||
@Override | ||
public <C> void inject(Context context, C carrier, CarrierSetter<C> setter) {} | ||
|
||
/** | ||
* Extracts a context from un upstream service. | ||
* | ||
* @param context the base context to store the extracted values on top, use {@link | ||
* Context#root()} for a default base context. | ||
* @param carrier the instance to fetch the propagated key/value pairs from. | ||
* @param visitor the callback to walk over the carrier and extract its key/value pais. | ||
* @return A context with the extracted values on top of the given base context. | ||
*/ | ||
@Override | ||
public <C> Context extract(Context context, C carrier, CarrierVisitor<C> visitor) { | ||
if (context == null || carrier == null || visitor == null) { | ||
return context; | ||
} | ||
InferredProxyContextExtractor extractor = new InferredProxyContextExtractor(); | ||
visitor.forEachKeyValue(carrier, extractor); | ||
|
||
InferredProxyContext extractedContext = extractor.extractedContext; | ||
if (extractedContext == null) { | ||
return context; | ||
} | ||
return extractedContext.storeInto(context); | ||
} | ||
|
||
public static class InferredProxyContextExtractor implements BiConsumer<String, String> { | ||
private InferredProxyContext extractedContext; | ||
|
||
InferredProxyContextExtractor() {} | ||
|
||
private Map<String, String> parseInferredProxyHeaders(String input) { | ||
Map<String, String> parsedHeaders = new HashMap<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's happening here? |
||
return parsedHeaders; | ||
} | ||
|
||
/** | ||
* Performs this operation on the given arguments. | ||
* | ||
* @param key the first input argument from an http header | ||
* @param value the second input argument from an http header | ||
*/ | ||
@Override | ||
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(); | ||
} | ||
extractedContext.putInferredProxyInfo(key, value); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to adjust the capacity
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's your recommendation on standardizing capacity? I see an example like this (link)
but this is kind of unclear on how it works to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you know about how many elements that you are going to put into the Map, then initialize the capacity to that.
HashMap is automatically going to pick the next power of 2 up from the capacity specified.