historyserver: include OSS root dir in GetContent keys. Fixes #4820
Summary
- build Aliyun OSS
GetContentobject keys withOssRootDir, cluster ID, and file name - use the same root-dir-inclusive path when falling back to directory listing
- add unit coverage for object key, fallback directory prefix, and realistic base-name matching
Verification
go test ./pkg/storage/aliyunoss/raygo test ./pkg/... ./cmd/...fromhistoryserver/autoreview --mode local --engine claudereturned clean after accepted test-gap fixes
Fixes #4820
cc @KunWuLuan to take a look, tks
Hi @MikeTomlin19, I ran into this same bug independently and had a fix ready before I found your PR. Yours came first and the production change matches what I arrived at, so I am not going to open a competing one. Two things that might help move this along: a gap in the tests, and an independent confirmation that the approach is correct.
The tests never call GetContent.
TestObjectKeyIncludesRootDir and TestObjectDirIncludesRootDir assert that objectKey and objectDir return what path.Join returns, which holds by construction. If someone later changes Key: oss.Ptr(fullPath) back to Key: oss.Ptr(fileName), every test in the file still passes and the bug is back with no signal. The same applies to the fallback: nothing checks which prefix _listFiles is given.
You can assert on the key that actually goes out on the wire without a real bucket. Point the SDK at an httptest server and turn on path style addressing so the full object key stays in r.URL.Path:
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewStaticCredentialsProvider("test-ak", "test-sk")).
WithRegion("cn-hangzhou").
WithEndpoint(srv.URL).
WithUsePathStyle(true).
WithRetryMaxAttempts(1)
Have the handler 404 everything except the expected key. On current master the test then fails with the buggy key printed in the message, which makes the regression obvious rather than silent. A second test that places the object one directory deeper covers the fallback, since only the list-and-match-on-base-name path can reach it there.
I have both tests working against your change if you want them as a patch.
Independent confirmation of the direction, in case it saves a reviewer some time.
The first argument is a root-dir-relative prefix, not an absolute one, so joining the root dir here applies it exactly once. All three reader side call sites build it with an empty root dir:
pkg/historyserver/router.go:1204pkg/eventserver/eventserver.go:467pkg/eventserver/log_event_reader.go:57
and only the collector passes a real one, at pkg/collector/logcollector/runtime/runtime.go:55. The asymmetry the issue describes is also easy to confirm: router.go:997 calls ListFiles(clusterLogPathPrefix, ...) and router.go:1012 calls GetContent(clusterLogPathPrefix, ...) with the same local variable, so the two really were building different keys from one input. s3.go:194 and azureblob.go:200 already join the root dir the way this PR does.
For deployments with no root dir configured, behavior is unchanged. Before this PR the first GetObject missed on the bare key and the fallback listing quietly rescued it; after it, the first fetch hits, saving one failed GET and one LIST per file.
One heads up: #5068 renames this function's first parameter from clusterId to prefix, so whichever lands second will need a small rebase.
Disclosure: I used AI assistance while investigating this. The call site tracing and the test behavior described above are things I ran and checked myself.
Thanks for the careful trace—agreed that the helper-only assertions were tautological and would not catch a regression in GetContent.
I pushed commit 13817180, which replaces those tests with two SDK-level httptest cases:
- the direct path asserts exactly one GET to the root-dir-inclusive object key;
- the fallback path forces the first GET to fail, asserts the root-dir-inclusive LIST prefix, returns a same-basename object one directory deeper, and verifies the final GET and content.
I also mutation-checked the tests by restoring the old Key: oss.Ptr(fileName) and root-less LIST prefix; both tests fail and print the incorrect wire paths. The focused package test, race test, full History Server package/command suite, and go vet all pass locally.
#5068 is still open, so there is no parameter-rename conflict yet; I’ll handle the small rebase if it lands first.
Rebased onto 72b97677. The original production change is now present in master via #4874, so this branch intentionally retains only the stronger SDK-level regression tests for direct and fallback GetContent request paths. Verified: go test ./pkg/storage/aliyunoss/ray, go test -race ./pkg/storage/aliyunoss/ray, and git diff --check upstream/master...HEAD.
LGTM @Future-Outlier . @MikeTomlin19 Could you update the PR title to "test: cover OSS GetContent root-dir-inclusive request paths" cause the fix has already been merged?
Rebased onto current master (feeaf72f) at head 41fd8fbb; the branch is now 0 commits behind.
Verification on the rebased head:
go test ./pkg/storage/aliyunoss/raygo test -race ./pkg/storage/aliyunoss/raygo test ./pkg/... ./cmd/...go vet ./pkg/... ./cmd/...git diff --check upstream/master...HEAD
All passed. @Future-Outlier, could you provide the required maintainer review when convenient? @KunWuLuan has already approved the test coverage.