-
Notifications
You must be signed in to change notification settings - Fork 300
Create insight collector #1287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create insight collector #1287
Changes from 29 commits
0fc0b7d
6a44216
85e9a15
dddcf8f
26993d4
eb9eeab
7014aba
f5fcc50
065356a
b4f5d81
fd7d585
185d231
ca85ff5
8d199dc
21e55a4
af2261e
6c3d89e
3e8419b
f32a508
b5dbab9
ff11d73
9d3b3c1
77ff912
5b352d1
08e8b14
31c3187
5c288cd
5065a06
c14aaec
79f2b91
be05090
38c4be2
dc6e7f1
c951140
1945ac5
a9e258c
4641521
d85c48b
ca698ba
cdc6f9f
4c051d2
afde1f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,22 +19,25 @@ import ( | |
| "net/http" | ||
| "time" | ||
|
|
||
| "github.com/robfig/cron/v3" | ||
| "github.com/spf13/cobra" | ||
| "go.uber.org/zap" | ||
| "golang.org/x/sync/errgroup" | ||
|
|
||
| "github.com/pipe-cd/pipe/pkg/admin" | ||
| "github.com/pipe-cd/pipe/pkg/app/ops/handler" | ||
| "github.com/pipe-cd/pipe/pkg/app/ops/insightcollector" | ||
| "github.com/pipe-cd/pipe/pkg/cli" | ||
| "github.com/pipe-cd/pipe/pkg/datastore" | ||
| "github.com/pipe-cd/pipe/pkg/version" | ||
| ) | ||
|
|
||
| type ops struct { | ||
| httpPort int | ||
| adminPort int | ||
| gracePeriod time.Duration | ||
| configFile string | ||
| httpPort int | ||
| adminPort int | ||
| gracePeriod time.Duration | ||
| enableInsightCollector bool | ||
| configFile string | ||
| } | ||
|
|
||
| func NewOpsCommand() *cobra.Command { | ||
|
|
@@ -51,7 +54,7 @@ func NewOpsCommand() *cobra.Command { | |
| cmd.Flags().IntVar(&s.httpPort, "http-port", s.httpPort, "The port number used to run http server.") | ||
| cmd.Flags().IntVar(&s.adminPort, "admin-port", s.adminPort, "The port number used to run a HTTP server for admin tasks such as metrics, healthz.") | ||
| cmd.Flags().DurationVar(&s.gracePeriod, "grace-period", s.gracePeriod, "How long to wait for graceful shutdown.") | ||
|
|
||
| cmd.Flags().BoolVar(&s.enableInsightCollector, "enable-insight-collector", s.enableInsightCollector, "enable insight collector.") | ||
| cmd.Flags().StringVar(&s.configFile, "config-file", s.configFile, "The path to the configuration file.") | ||
| return cmd | ||
| } | ||
|
|
@@ -82,6 +85,31 @@ func (s *ops) run(ctx context.Context, t cli.Telemetry) error { | |
| } | ||
| }() | ||
|
|
||
| fs, err := createFilestore(ctx, cfg, t.Logger) | ||
| if err != nil { | ||
| t.Logger.Error("failed to create filestore", zap.Error(err)) | ||
| return err | ||
| } | ||
| defer func() { | ||
| if err := fs.Close(); err != nil { | ||
| t.Logger.Error("failed to close filestore client", zap.Error(err)) | ||
| } | ||
| }() | ||
|
|
||
| // Set insight collector | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: "Starting a cron job for insight collector." |
||
| if s.enableInsightCollector { | ||
| collector := insightcollector.NewInsightCollector(ds, fs, t.Logger) | ||
| c := cron.New(cron.WithLocation(time.UTC)) | ||
| _, err := c.AddFunc(cfg.InsightCollector.Schedule, func() { | ||
| if err := collector.Run(ctx); err != nil { | ||
| t.Logger.Error("failed to run the insight collector", zap.Error(err)) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw, Could you add a log to show how long does each function take to run?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, added:+1: |
||
| }) | ||
| if err != nil { | ||
| t.Logger.Error("failed to configure the insight collector", zap.Error(err)) | ||
| } | ||
| } | ||
|
|
||
| // Start running HTTP server. | ||
| { | ||
| handler := handler.NewHandler(s.httpPort, datastore.NewProjectStore(ds), cfg.SharedSSOConfigs, s.gracePeriod, t.Logger) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Enable"