gcp-resources: add connect and read timeout, add response body limit#2883
Open
jack-berg wants to merge 1 commit into
Open
gcp-resources: add connect and read timeout, add response body limit#2883jack-berg wants to merge 1 commit into
jack-berg wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds explicit connect and read timeouts to the GCP metadata HTTP fetch and bounds the response body size read from the metadata server to 4096 characters, replacing the prior BufferedReader.readLine() call with a fixed-size character read.
Changes:
- Introduce
CONNECT_TIMEOUT_MS(1s) andREAD_TIMEOUT_MS(1s) constants and apply them to theHttpURLConnection. - Cap metadata response reads at
MAX_METADATA_VALUE_CHARS(4096) via a singleReader.readinto a char buffer. - Add a unit test asserting an oversized metadata body is truncated to 4096 characters.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| gcp-resources/src/main/java/io/opentelemetry/contrib/gcp/resource/GcpMetadataConfig.java | Adds connect/read timeouts and replaces line-based read with bounded char-buffer read. |
| gcp-resources/src/test/java/io/opentelemetry/contrib/gcp/resource/GcpMetadataConfigTest.java | Adds test verifying 8192-char response is truncated to 4096 chars. |
Comment on lines
+163
to
+165
| char[] buffer = new char[MAX_METADATA_VALUE_CHARS]; | ||
| int n = reader.read(buffer, 0, buffer.length); | ||
| return n > 0 ? new String(buffer, 0, n) : null; |
Comment on lines
+164
to
+165
| int n = reader.read(buffer, 0, buffer.length); | ||
| return n > 0 ? new String(buffer, 0, n) : null; |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.