[
https://issues.apache.org/jira/browse/CASSANDRA-21195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18121030#comment-18121030
]
Stefan Miklosovic commented on CASSANDRA-21195:
-----------------------------------------------
The logs of a node in EC2, verifying the resolution:
{code}
DEBUG [main] 2026-09-30T09:13:43,806 HttpService.java:250 - Executing HTTP PUT
request to URL: http://169.254.169.254/latest/api/token with connection
timeout: 30000ms, read timeout
: 0ms
TRACE [main] 2026-09-30T09:13:43,806 HttpService.java:259 - Request header
names: [X-aws-ec2-metadata-token-ttl-seconds]
TRACE [main] 2026-09-30T09:13:43,809 HttpService.java:278 - Setting request
header: X-aws-ec2-metadata-token-ttl-seconds
TRACE [main] 2026-09-30T09:13:43,809 HttpService.java:282 - Opening connection
to http://169.254.169.254/latest/api/token
DEBUG [main] 2026-09-30T09:13:43,812 HttpService.java:290 - HTTP PUT request to
http://169.254.169.254/latest/api/token completed in 6ms with status: 200 OK
TRACE [main] 2026-09-30T09:13:43,813 HttpService.java:335 - Reading response
body with content length: 56
TRACE [main] 2026-09-30T09:13:43,814 HttpService.java:377 - Successfully read
56 bytes from response
TRACE [main] 2026-09-30T09:13:43,814 HttpService.java:299 - Response body
length: 56 bytes
TRACE [main] 2026-09-30T09:13:43,814 HttpService.java:315 - Disconnecting HTTP
connection to http://169.254.169.254/latest/api/token
DEBUG [main] 2026-09-30T09:13:43,814 HttpService.java:250 - Executing HTTP GET
request to URL:
http://169.254.169.254/latest/meta-data/placement/availability-zone with
connection ti
meout: 30000ms, read timeout: 0ms
TRACE [main] 2026-09-30T09:13:43,814 HttpService.java:259 - Request header
names: [X-aws-ec2-metadata-token]
TRACE [main] 2026-09-30T09:13:43,814 HttpService.java:278 - Setting request
header: X-aws-ec2-metadata-token
TRACE [main] 2026-09-30T09:13:43,814 HttpService.java:282 - Opening connection
to http://169.254.169.254/latest/meta-data/placement/availability-zone
DEBUG [main] 2026-09-30T09:13:43,815 HttpService.java:290 - HTTP GET request to
http://169.254.169.254/latest/meta-data/placement/availability-zone completed
in 1ms with status: 200
OK
TRACE [main] 2026-09-30T09:13:43,815 HttpService.java:335 - Reading response
body with content length: 13
TRACE [main] 2026-09-30T09:13:43,815 HttpService.java:377 - Successfully read
13 bytes from response
TRACE [main] 2026-09-30T09:13:43,815 HttpService.java:299 - Response body
length: 13 bytes
TRACE [main] 2026-09-30T09:13:43,815 HttpService.java:315 - Disconnecting HTTP
connection to
http://169.254.169.254/latest/meta-data/placement/availability-zone
INFO [main] 2026-09-30T09:13:43,815 CloudMetadataLocationProvider.java:53 -
org.apache.cassandra.locator.Ec2LocationProvider using datacenter:
eu-central-1, rack: eu-central-1c, co
nnector:
org.apache.cassandra.locator.Ec2MetadataServiceConnector$V2Connector{metadata_url=http://169.254.169.254,ec2_metadata_token_ttl_seconds=21600},
properties: SnitchProperties
{properties={rack=rack1, metadata_url=http://169.254.169.254, dc=dc1}}
{code}
> Extract HTTP-related code around cloud snitches so it can be reusable across
> the codebase
> -----------------------------------------------------------------------------------------
>
> Key: CASSANDRA-21195
> URL: https://issues.apache.org/jira/browse/CASSANDRA-21195
> Project: Apache Cassandra
> Issue Type: Task
> Components: Legacy/Core
> Reporter: Stefan Miklosovic
> Assignee: BHARATH KUMAR
> Priority: Normal
> Fix For: 7.x
>
> Attachments: CASSANDRA-21195.patch
>
> Time Spent: 2h 10m
> Remaining Estimate: 0h
>
> *Overview*
> Several components in Apache Cassandra require making HTTP calls to external
> services (e.g., cloud metadata services or external authentication
> providers). Currently, HTTP logic exists within specific implementations such
> as {{{}AbstractCloudMetadataServiceConnector{}}}, which limits reuse and
> leads to duplication when additional components require a similar
> functionality.
> This proposal introduces a generic, reusable HTTP utility in the {{utils}}
> package that can be leveraged across Cassandra components requiring
> synchronous HTTP interactions.
> *Goals*
> * Introduce a generic HTTP utility that can be reused across the Cassandra
> codebase
> * Avoid modifying existing behavior during the initial implementation
> * Refactor existing cloud metadata connectors to leverage the shared utility
> * Provide a foundation that can support additional HTTP methods and use
> cases in the future
> * Keep response parsing outside the utility to maintain separation of
> concerns
> *Non-Goals*
> The following are intentionally out of scope for the initial implementation:
> * Introducing asynchronous HTTP clients
> * Implementing automatic response parsing
> * Adding external dependencies
> * Changing existing public interfaces
> * Modifying the behavior of existing cloud metadata connectors
> The goal is strictly to extract and centralize HTTP logic, not redesign the
> existing functionality.
> *Design Principles*
> # *Simplicity* - The utility will support synchronous HTTP requests only
> # *Reusability* - Minimal interface that allows reuse across different
> Cassandra components
> # *Separation of Concerns* - Utility responsible only for executing HTTP
> requests and returning raw responses; parsing remains the caller's
> responsibility
> # *Backward Compatibility* - Existing functionality must remain unchanged
> during early phases
> *Implementation Plan*
> The implementation will be delivered in phases:
> *Phase 1: Introduce HTTP Utility*
> * Create a new {{HttpUtil}} class in {{org.apache.cassandra.utils}} package
> * Encapsulate common HTTP logic from cloud metadata connectors
> * Support synchronous HTTP requests with configurable timeouts and headers
> * No modifications to existing classes (zero behavioral impact)
> *Phase 2: Refactor Cloud Metadata Implementations*
> * Update existing cloud metadata implementations to use {{HttpUtil}}
> internally
> * Replace duplicated HTTP code with a shared utility
> * Preserve existing external behavior and APIs
> *Phase 3: Validation and Regression Testing*
> * Ensure all cloud metadata implementations behave exactly as before
> * Validate through existing tests
> * Confirm no regressions in metadata retrieval or authentication flows
> *Phase 4: Extend the HTTP Utility*
> * Add support for additional HTTP methods (POST, PUT, DELETE)
> * Improve header handling
> * Add reusable configuration patterns
> *Phase 5: Maintain Clear Response Handling Boundaries*
> * Keep utility transport-focused only
> * Execute HTTP request and return raw response
> * Response parsing remains with the calling implementation
> *Current HTTP Usage in Cassandra*
> *Analysis of existing code shows:*
> * {*}GET requests{*}: Used by all cloud metadata services (AWS EC2, Azure,
> GCP, Alibaba Cloud, Cloudstack)
> * {*}PUT requests{*}: Used by AWS IMDSv2 for token retrieval
> ({{{}Ec2MetadataServiceConnector.V2Connector{}}})
> * Pattern: {{AbstractCloudMetadataServiceConnector.apiCall()}} method (lines
> 100-135)
> *Benefits*
> * *Reduced Code Duplication* - HTTP logic centralized rather than
> reimplemented
> * *Improved Maintainability* - Bug fixes/improvements in one place
> * *Better Extensibility* - Future features can reuse the same utility
> * *Low Risk Migration* - Phased approach ensures minimal disruption
> *Future Opportunities*
> Once stable, the utility may be reused for:
> * External secret managers (HashiCorp Vault)
> * Metadata services
> * Authentication integrations
> * Configuration services
> This utility could become the standard HTTP interaction mechanism within
> Cassandra for startup-time operations.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]