-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathApp.go
More file actions
63 lines (56 loc) · 1.72 KB
/
App.go
File metadata and controls
63 lines (56 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"github.com/devtron-labs/chart-sync/internals"
"github.com/devtron-labs/chart-sync/pkg"
"github.com/devtron-labs/common-lib/securestore"
"github.com/go-pg/pg"
"github.com/prometheus/client_golang/prometheus/promhttp"
"go.uber.org/zap"
"net/http"
"strconv"
"time"
)
type App struct {
Logger *zap.SugaredLogger
db *pg.DB
syncService pkg.SyncService
configuration *internals.Configuration
}
func NewApp(Logger *zap.SugaredLogger,
db *pg.DB,
syncService pkg.SyncService,
configuration *internals.Configuration) *App {
err := securestore.SetEncryptionKey()
if err != nil {
Logger.Errorw("error in setting encryption key", "err", err)
}
return &App{
Logger: Logger,
db: db,
syncService: syncService,
configuration: configuration,
}
}
func (app *App) Start() {
// Set up the /metrics endpoint for Prometheus to scrape
http.Handle("/metrics", promhttp.Handler())
go func() {
// Then modify the line to:
err := http.ListenAndServe(":"+strconv.Itoa(app.configuration.PrometheusMatrixPort), nil)
if err != nil {
app.Logger.Errorw("error in starting prometheus server", "err", err)
}
}()
// Track overall sync time
start := time.Now()
// Start the sync service
_, err := app.syncService.Sync()
if err != nil {
app.Logger.Errorw("err", "err", err)
internals.RepoSyncDuration.WithLabelValues("all", "all", err.Error()).Observe(time.Since(start).Seconds())
} else {
internals.RepoSyncDuration.WithLabelValues("all", "all", "").Observe(time.Since(start).Seconds())
}
// sleep for ShutDownInterval seconds to give time for prometheus to scrape the metrics
time.Sleep(time.Duration(app.configuration.AppSyncJobShutDownWaitDuration) * time.Second)
}