Skip to content

gcp-resources: add connect and read timeout, add response body limit#2883

Open
jack-berg wants to merge 1 commit into
open-telemetry:mainfrom
jack-berg:gcp-metadata-timeout-limit
Open

gcp-resources: add connect and read timeout, add response body limit#2883
jack-berg wants to merge 1 commit into
open-telemetry:mainfrom
jack-berg:gcp-metadata-timeout-limit

Conversation

@jack-berg
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 28, 2026 20:40
@jack-berg jack-berg requested a review from a team as a code owner May 28, 2026 20:40
@github-actions github-actions Bot requested review from jsuereth and psx95 May 28, 2026 20:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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) and READ_TIMEOUT_MS (1s) constants and apply them to the HttpURLConnection.
  • Cap metadata response reads at MAX_METADATA_VALUE_CHARS (4096) via a single Reader.read into 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants