Skip to content

Commit 23a6aa6

Browse files
authored
Fix file matching in Aliyun OSS GetContent (#4692)
Was comparing path.Base(f) against full fileName, so they'd never match. Fixed by comparing basenames on both sides and added found flag with break to exit early.
1 parent f94bf11 commit 23a6aa6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

historyserver/pkg/storage/aliyunoss/ray/ray.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ func (r *RayLogsHandler) GetContent(clusterId string, fileName string) io.Reader
206206
allFiles := r._listFiles(clusterId+"/"+path.Dir(fileName), "", false)
207207
found := false
208208
for _, f := range allFiles {
209-
if path.Base(f) == fileName {
209+
if path.Base(f) == path.Base(fileName) {
210210
logrus.Infof("Get object %s info success", f)
211211
result, err = r.OssClient.GetObject(ctx, &oss.GetObjectRequest{
212212
Bucket: oss.Ptr(r.OssBucket),
@@ -216,6 +216,8 @@ func (r *RayLogsHandler) GetContent(clusterId string, fileName string) io.Reader
216216
logrus.Errorf("Failed to get object %s: %v", f, err)
217217
return nil
218218
}
219+
found = true
220+
break
219221
}
220222
}
221223
if !found {

historyserver/pkg/storage/aliyunoss/ray/ray_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ func TestTrim(t *testing.T) {
3030
t.Logf("test_path_join [%s]", test_path_join)
3131
}
3232

33+
func TestGetContentPathComparison(t *testing.T) {
34+
// fileName is a full path like the caller passes
35+
fileName := "session_2026-04-09_06-41-42_754637_1/logs/abc123/events/event_RAYLET.log"
36+
// f is a full key returned by _listFiles (onlyBase=false)
37+
f := "session_2026-04-09_06-41-42_754637_1/logs/abc123/events/event_RAYLET.log"
38+
39+
if path.Base(f) != path.Base(fileName) {
40+
t.Errorf("expected path.Base(%q) == path.Base(%q)", f, fileName)
41+
}
42+
// Verify old buggy comparison would fail
43+
if path.Base(f) == fileName {
44+
t.Errorf("old comparison should not match: path.Base(%q) == %q", f, fileName)
45+
}
46+
}
47+
3348
func TestWalk(t *testing.T) {
3449
watchPath := "/tmp/ray/test/LLogs/"
3550
filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {

0 commit comments

Comments
 (0)