kuberay icon indicating copy to clipboard operation
kuberay copied to clipboard

historyserver: include OSS root dir in GetContent keys. Fixes #4820

Open MikeTomlin19 opened this issue 5 months ago • 1 comments

Summary

  • build Aliyun OSS GetContent object keys with OssRootDir, 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/ray
  • go test ./pkg/... ./cmd/... from historyserver/
  • autoreview --mode local --engine claude returned clean after accepted test-gap fixes

Fixes #4820

MikeTomlin19 avatar Jun 06 '26 23:06 MikeTomlin19

cc @KunWuLuan to take a look, tks

Future-Outlier avatar Jun 18 '26 02:06 Future-Outlier

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:1204
  • pkg/eventserver/eventserver.go:467
  • pkg/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.

stantheman0128 avatar Aug 04 '26 09:08 stantheman0128

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.

MikeTomlin19 avatar Aug 04 '26 20:08 MikeTomlin19

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.

MikeTomlin19 avatar Aug 05 '26 21:08 MikeTomlin19

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?

KunWuLuan avatar Aug 20 '26 06:08 KunWuLuan

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/ray
  • go test -race ./pkg/storage/aliyunoss/ray
  • go 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.

MikeTomlin19 avatar Aug 26 '26 16:08 MikeTomlin19