Skip to content

File delivery range support#7319

Open
pzl wants to merge 7 commits into
elastic:mainfrom
pzl:file-delivery-range-support
Open

File delivery range support#7319
pzl wants to merge 7 commits into
elastic:mainfrom
pzl:file-delivery-range-support

Conversation

@pzl

@pzl pzl commented Jul 4, 2026

Copy link
Copy Markdown
Member

What is the problem this PR solves?

Enables clients (e.g. endpoint) to gracefully resume downloads of (large) files via the HTTP Range header.

This allows for completing large file transfers under unstable or periodic network conditions, as opposed to starting the file download over.

N.B.:

  • This only supports single ranges (e.g. bytes=100-400) and not multipart range requests (e.g. bytes=0-500, 1024-2048, -600).
  • Also HTTP Spec allows for graceful degradation here. For unclear range headers (or for any reason if the server chooses not to fulfill a particular range), either a 416 Range Unsatisfiable error OR HTTP 200 with full file contents are both acceptable responses. This implementation mostly generates 416s for clients to handle malformed byte strings, but in narrow cases where intent is unclear (e.g. the header is present without a value: Range: ) then we do fall back to HTTP 200 with file contents, as spec defines.

How does this PR solve the problem?

Only fetch chunks that fall inside the requested range

Design Checklist

  • I have ensured my design is stateless and will work when multiple fleet-server instances are behind a load balancer.
  • I have or intend to scale test my changes, ensuring it will work reliably with 100K+ agents connected.
  • I have included fail safe mechanisms to limit the load on fleet-server: rate limiting, circuit breakers, caching, load shedding, etc.

Checklist

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool

Related issues

@pzl pzl requested a review from a team as a code owner July 4, 2026 11:55
@pzl pzl requested review from blakerouse and samuelvl July 4, 2026 11:55
@pzl pzl added enhancement New feature or request backport-skip Skip notification from the automated backport with mergify labels Jul 4, 2026
@pzl pzl added the Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team label Jul 6, 2026
@pzl

pzl commented Jul 6, 2026

Copy link
Copy Markdown
Member Author

@elastic/elastic-agent-control-plane sorry for the short turnaround, could this be looked over before FF?

It is additional behavior only: when serving files through the file delivery route, if a Range header is present, delivers the subset of bytes instead of the whole file (follows HTTP spec). Oherwise all behavior is the same

Comment thread internal/pkg/api/handleFileDelivery.go Outdated
return r.ReplaceAllString(strings.ToLower(strings.TrimSpace(s)), "")
}

func (ft *FileDeliveryT) sendFileAsRanges(zlog zerolog.Logger, w http.ResponseWriter, r *http.Request, fileID string, info file.MetaDoc, chunks []file.ChunkInfo, ranges []httpRange) error {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You don't set X-File-SHA2 on this path, should you?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ambiguous when sending byte ranges (would it apply to the range or still the hash of the whole file?) so it wasn't used for range requests. It could be, it would just have to be an explicit call if it were needed

Comment thread internal/pkg/api/handleFileDelivery.go Outdated
Comment thread internal/pkg/api/handleFileDelivery.go
Comment thread internal/pkg/api/handleFileDelivery.go
@pzl pzl requested a review from cmacknz July 6, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-skip Skip notification from the automated backport with mergify enhancement New feature or request Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants