Skip to content

Commit

Permalink
add develop mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alexei-led committed May 22, 2023
1 parent 6307b58 commit 9aef6bc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
13 changes: 12 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ func run(ctx context.Context, log *logrus.Entry, cfg config.Config) error {
ctx, ctxCancel := context.WithCancel(ctx)
defer ctxCancel()

log.Infof("eks-lens agent started")
// add debug mode to context
if cfg.DevelopMode {
ctx = context.WithValue(ctx, "develop-mode", true)
}

log.WithField("develop-mode", cfg.DevelopMode).Infof("eks-lens agent started")

restconfig, err := retrieveKubeConfig(log, cfg)
if err != nil {
Expand Down Expand Up @@ -163,6 +168,12 @@ func main() {
EnvVars: []string{"LOG_JSON"},
Category: "Logging",
},
&cli.BoolFlag{
Name: "develop-mode",
Usage: "enable develop mode",
EnvVars: []string{"DEV_MODE"},
Category: "Configuration",
},
},
Action: runCmd,
},
Expand Down
22 changes: 15 additions & 7 deletions internal/aws/firehose/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,22 @@ func (u *firehoseUploader) Upload(ctx context.Context, records []*usage.PodInfo)
})
}

// send records[i:j] to Amazon Kinesis Data Firehose
input := &firehose.PutRecordBatchInput{
DeliveryStreamName: aws.String(u.stream),
Records: batch,
// get develop-mode flag from context
developMode := false
if val := ctx.Value("develop-mode"); val != nil {
developMode = val.(bool)
}
_, err := u.client.PutRecordBatch(ctx, input)
if err != nil {
return errors.Wrap(err, "putting record batch to Amazon Kinesis Data Firehose")

// send records[i:j] to Amazon Kinesis Data Firehose, if not in develop-mode
if developMode {
input := &firehose.PutRecordBatchInput{
DeliveryStreamName: aws.String(u.stream),
Records: batch,
}
_, err := u.client.PutRecordBatch(ctx, input)
if err != nil {
return errors.Wrap(err, "putting record batch to Amazon Kinesis Data Firehose")
}
}
}
return nil
Expand Down
3 changes: 3 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ type Config struct {
ClusterName string `json:"cluster-name"`
// Amazon Kinesis Data Stream name
StreamName string `json:"stream-name"`
// DevelopMode mode
DevelopMode bool `json:"develop-mode"`
}

func LoadConfig(c *cli.Context) Config {
var cfg Config
cfg.KubeConfigPath = c.String("kubeconfig")
cfg.ClusterName = c.String("cluster-name")
cfg.StreamName = c.String("stream-name")
cfg.DevelopMode = c.Bool("develop-mode")
return cfg
}
14 changes: 11 additions & 3 deletions internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
)

const (
syncPeriod = 15 * time.Minute
syncPeriod = 15 * time.Minute
syncPeriodDebug = 5 * time.Minute
)

type Scanner interface {
Expand Down Expand Up @@ -105,8 +106,15 @@ func (s *scanner) Run(ctx context.Context) error {
return errors.New("failed to sync cache")
}

// get pod list from the cache every "syncPeriod" minutes
ticker := time.NewTicker(syncPeriod)
// define sybc period
tick := syncPeriod
// get develop-mode mode from context
if val := ctx.Value("develop-mode"); val != nil && val.(bool) {
tick = syncPeriodDebug
}

// get pod list from the cache every "syncPeriod/DevelopMode" minutes
ticker := time.NewTicker(tick)
defer ticker.Stop()
for {
upload := func() {
Expand Down

0 comments on commit 9aef6bc

Please sign in to comment.