From e31b6b94d4986629d99824a3eb4294113c4b4ae1 Mon Sep 17 00:00:00 2001 From: Dery Rahman Ahaddienata Date: Sat, 3 May 2025 02:35:34 +0700 Subject: [PATCH] fix: logview to use public host --- mc2mc/internal/client/odps.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/mc2mc/internal/client/odps.go b/mc2mc/internal/client/odps.go index ceafa60..46658e9 100644 --- a/mc2mc/internal/client/odps.go +++ b/mc2mc/internal/client/odps.go @@ -5,6 +5,7 @@ import ( e "errors" "fmt" "log/slog" + "net/url" "strings" "time" @@ -46,7 +47,7 @@ func (c *odpsClient) ExecSQL(ctx context.Context, query string, additionalHints } // generate log view - url, err := odps.NewLogView(c.client).GenerateLogView(taskIns, c.logViewRetentionInDays*24) + url, err := c.generateLogView(taskIns) if err != nil { err = e.Join(err, taskIns.Terminate()) return errors.WithStack(err) @@ -109,6 +110,28 @@ func (c *odpsClient) GetOrderedColumns(tableID string) ([]string, error) { return columnNames, nil } +// generateLogView generates the log view for the given task instance +func (c *odpsClient) generateLogView(taskIns *odps.Instance) (string, error) { + u, err := c.client.LogView().GenerateLogView(taskIns, c.logViewRetentionInDays*24) + if err != nil { + return "", errors.WithStack(err) + } + + // change query parameter h to http://service.id-all.maxcompute.aliyun-inc.com + parsedURL, err := url.Parse(u) + if err != nil { + return "", errors.WithStack(err) + } + q := parsedURL.Query() + q.Set("h", "http://service.id-all.maxcompute.aliyun-inc.com/api") + + // reconstruct the URL with the new query parameter + parsedURL.RawQuery = q.Encode() + u = parsedURL.String() + + return u, nil +} + // wait waits for the task instance to finish on a separate goroutine func (c *odpsClient) wait(taskIns *odps.Instance) <-chan error { errChan := make(chan error)