Skip to content

Commit

Permalink
feat(mc2mc): configurable log view duration in days (#65)
Browse files Browse the repository at this point in the history
* feat: increase log view to 2 days

* feat: configurable log view retention
  • Loading branch information
deryrahman authored Jan 8, 2025
1 parent 89abe78 commit 317cfeb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions mc2mc/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
type OdpsClient interface {
ExecSQL(ctx context.Context, query string) error
SetDefaultProject(project string)
SetLogViewRetentionInDays(days int)
}

type Client struct {
Expand Down
14 changes: 11 additions & 3 deletions mc2mc/internal/client/odps.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ import (
type odpsClient struct {
logger *slog.Logger
client *odps.Odps

logViewRetentionInDays int
}

// NewODPSClient creates a new odpsClient instance
func NewODPSClient(logger *slog.Logger, client *odps.Odps) *odpsClient {
return &odpsClient{
logger: logger,
client: client,
logger: logger,
client: client,
logViewRetentionInDays: 2,
}
}

Expand All @@ -35,7 +38,7 @@ func (c *odpsClient) ExecSQL(ctx context.Context, query string) error {
}

// generate log view
url, err := odps.NewLogView(c.client).GenerateLogView(taskIns, 1)
url, err := odps.NewLogView(c.client).GenerateLogView(taskIns, c.logViewRetentionInDays*24)
if err != nil {
err = e.Join(err, taskIns.Terminate())
return errors.WithStack(err)
Expand All @@ -54,6 +57,11 @@ func (c *odpsClient) ExecSQL(ctx context.Context, query string) error {
}
}

// SetLogViewRetentionInDays sets the log view retention in days
func (c *odpsClient) SetLogViewRetentionInDays(days int) {
c.logViewRetentionInDays = days
}

// SetDefaultProject sets the default project of the odps client
func (c *odpsClient) SetDefaultProject(project string) {
c.client.SetDefaultProjectName(project)
Expand Down
12 changes: 12 additions & 0 deletions mc2mc/internal/client/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ import (

type SetupFn func(c *Client) error

func SetUpLogViewRetentionInDays(days int) SetupFn {
return func(c *Client) error {
if c.OdpsClient == nil {
return errors.New("odps client is required")
}
if days > 0 {
c.OdpsClient.SetLogViewRetentionInDays(days)
}
return nil
}
}

func SetupDefaultProject(project string) SetupFn {
return func(c *Client) error {
if c.OdpsClient == nil {
Expand Down
1 change: 1 addition & 0 deletions mc2mc/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ConfigEnv struct {
DStart string `env:"DSTART"`
DEnd string `env:"DEND"`
ExecutionProject string `env:"EXECUTION_PROJECT"`
LogViewRetentionInDays int `env:"LOG_VIEW_RETENTION_IN_DAYS" envDefault:"2"`
// TODO: delete this
DevEnablePartitionValue string `env:"DEV__ENABLE_PARTITION_VALUE" envDefault:"false"`
DevEnableAutoPartition string `env:"DEV__ENABLE_AUTO_PARTITION" envDefault:"false"`
Expand Down
1 change: 1 addition & 0 deletions mc2mc/mc2mc.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func mc2mc(envs []string) error {
client.SetupOTelSDK(cfg.OtelCollectorGRPCEndpoint, cfg.OtelAttributes),
client.SetupODPSClient(cfg.GenOdps()),
client.SetupDefaultProject(cfg.ExecutionProject),
client.SetUpLogViewRetentionInDays(cfg.LogViewRetentionInDays),
)
if err != nil {
return errors.WithStack(err)
Expand Down

0 comments on commit 317cfeb

Please sign in to comment.