diff --git a/go.mod b/go.mod index 3915df1..a539d30 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,11 @@ require ( golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094 ) +require ( + go.uber.org/atomic v1.7.0 // indirect + go.uber.org/multierr v1.6.0 // indirect +) + require ( github.com/andybalholm/brotli v1.0.4 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -32,9 +37,11 @@ require ( github.com/savsgio/gotils v0.0.0-20220530130905-52f3993e8d6d // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect + go.uber.org/zap v1.23.0 golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect + golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect - golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect + golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.28.1 // indirect ) diff --git a/go.sum b/go.sum index 477a23e..c9fde31 100644 --- a/go.sum +++ b/go.sum @@ -242,6 +242,12 @@ go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= +go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= +go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= +go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4= +go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= +go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY= +go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -261,6 +267,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= +golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 h1:sBdrWpxhGDdTAYNqbgBLAR+ULAPPhfgncLr1X0lyWtg= +golang.org/x/exp v0.0.0-20221012211006-4de253d81b95/go.mod h1:cyybsKvd6eL0RnXn6p/Grxp8F5bW7iYuBgsNCOHpMYE= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -375,6 +383,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/main.go b/main.go index 665f6c4..06579ca 100644 --- a/main.go +++ b/main.go @@ -1,28 +1,36 @@ package main import ( - "log" "os" "github.com/urfave/cli/v2" + "go.uber.org/zap" "github.com/spendesk/github-actions-exporter/pkg/config" + "github.com/spendesk/github-actions-exporter/pkg/logging" "github.com/spendesk/github-actions-exporter/pkg/server" ) var ( version = "development" + logger *zap.SugaredLogger ) func main() { - app := cli.NewApp() - app.Name = "github-actions-exporter" - app.Flags = config.InitConfiguration() - app.Version = version - app.Action = server.RunServer + app := &cli.App{ + Name: "github-actions-exporter", + Flags: config.InitConfiguration(), + Action: func(ctx *cli.Context) error { + logger = logging.InitLogger() + server.RunServer(ctx, logger) + return nil + }, + Version: version, + } err := app.Run(os.Args) + if err != nil { - log.Fatal(err) + logger.Fatal(err) } } diff --git a/pkg/config/config.go b/pkg/config/config.go index 3a9fc9e..ee7f297 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -22,6 +22,7 @@ var ( Debug bool EnterpriseName string WorkflowFields string + LogFormat string ) // InitConfiguration - set configuration from env vars or command parameters @@ -127,5 +128,12 @@ func InitConfiguration() []cli.Flag { Usage: "Size of Github HTTP cache in bytes", Destination: &Github.CacheSizeBytes, }, + &cli.StringFlag{ + Name: "log_format", + EnvVars: []string{"LOG_FORMAT"}, + Usage: "Log output format. Valid formats: json, plain", + Value: "json", + Destination: &LogFormat, + }, } } diff --git a/pkg/logging/logging.go b/pkg/logging/logging.go new file mode 100644 index 0000000..8b1f636 --- /dev/null +++ b/pkg/logging/logging.go @@ -0,0 +1,40 @@ +package logging + +import ( + "log" + + "github.com/spendesk/github-actions-exporter/pkg/config" + "go.uber.org/zap" + "golang.org/x/exp/slices" +) + +var logger *zap.SugaredLogger + +func validateFormat(text string) { + if !slices.Contains([]string{"json", "plain"}, text) { + logger.Fatalf("Invalid log_format '%v'", text) + } +} + +func InitLogger() *zap.SugaredLogger { + var ( + freshLogger *zap.Logger + err error + ) + if config.LogFormat == "plain" { + freshLogger, err = zap.NewDevelopment() + } else { + freshLogger, err = zap.NewProduction() + } + + if err != nil { + log.Fatalf("Can't initialize logger: %v", err) + } + + defer freshLogger.Sync() + logger = freshLogger.Sugar() + + validateFormat(config.LogFormat) + + return logger +} diff --git a/pkg/metrics/get_billable_from_github.go b/pkg/metrics/get_billable_from_github.go index 23f2fc8..0ba5725 100644 --- a/pkg/metrics/get_billable_from_github.go +++ b/pkg/metrics/get_billable_from_github.go @@ -2,7 +2,6 @@ package metrics import ( "context" - "log" "strconv" "strings" "time" @@ -33,11 +32,11 @@ func getBillableFromGithub() { for { resp, _, err := client.Actions.GetWorkflowUsageByID(context.Background(), r[0], r[1], k) if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("GetWorkflowUsageByID ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + logger.Infof("GetWorkflowUsageByID ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) time.Sleep(time.Until(rl_err.Rate.Reset.Time)) continue } else if err != nil { - log.Printf("GetWorkflowUsageByID error for %s: %s", repo, err.Error()) + logger.Infof("GetWorkflowUsageByID error for %s: %s", repo, err.Error()) break } workflowBillGauge.WithLabelValues(repo, strconv.FormatInt(*v.ID, 10), *v.NodeID, *v.Name, *v.State, "MACOS").Set(float64(resp.GetBillable().MacOS.GetTotalMS()) / 1000) diff --git a/pkg/metrics/get_runners_enterprise_from_github.go b/pkg/metrics/get_runners_enterprise_from_github.go index c041121..ddc2e77 100644 --- a/pkg/metrics/get_runners_enterprise_from_github.go +++ b/pkg/metrics/get_runners_enterprise_from_github.go @@ -1,67 +1,66 @@ -package metrics - -import ( - "context" - "log" - "strconv" - "time" - - "github.com/spendesk/github-actions-exporter/pkg/config" - - "github.com/google/go-github/v45/github" - "github.com/prometheus/client_golang/prometheus" -) - -var ( - runnersEnterpriseGauge = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Name: "github_runner_enterprise_status", - Help: "runner status", - }, - []string{"os", "name", "id"}, - ) -) - -func getAllEnterpriseRunners() []*github.Runner { - var runners []*github.Runner - opt := &github.ListOptions{PerPage: 200} - - for { - resp, rr, err := client.Enterprise.ListRunners(context.Background(), config.EnterpriseName, nil) - if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("ListRunners ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) - time.Sleep(time.Until(rl_err.Rate.Reset.Time)) - continue - } else if err != nil { - log.Printf("ListRunners error for enterprise %s: %s", config.EnterpriseName, err.Error()) - return nil - } - - runners = append(runners, resp.Runners...) - if rr.NextPage == 0 { - break - } - opt.Page = rr.NextPage - } - - return runners -} - -func getRunnersEnterpriseFromGithub() { - if config.EnterpriseName == "" { - return - } - for { - runners := getAllEnterpriseRunners() - - for _, runner := range runners { - var integerStatus float64 - if integerStatus = 0; runner.GetStatus() == "online" { - integerStatus = 1 - } - runnersEnterpriseGauge.WithLabelValues(*runner.OS, *runner.Name, strconv.FormatInt(runner.GetID(), 10)).Set(integerStatus) - } - - time.Sleep(time.Duration(config.Github.Refresh) * time.Second) - } -} +package metrics + +import ( + "context" + "strconv" + "time" + + "github.com/spendesk/github-actions-exporter/pkg/config" + + "github.com/google/go-github/v45/github" + "github.com/prometheus/client_golang/prometheus" +) + +var ( + runnersEnterpriseGauge = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Name: "github_runner_enterprise_status", + Help: "runner status", + }, + []string{"os", "name", "id"}, + ) +) + +func getAllEnterpriseRunners() []*github.Runner { + var runners []*github.Runner + opt := &github.ListOptions{PerPage: 200} + + for { + resp, rr, err := client.Enterprise.ListRunners(context.Background(), config.EnterpriseName, nil) + if rl_err, ok := err.(*github.RateLimitError); ok { + logger.Infof("ListRunners ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + time.Sleep(time.Until(rl_err.Rate.Reset.Time)) + continue + } else if err != nil { + logger.Infof("ListRunners error for enterprise %s: %s", config.EnterpriseName, err.Error()) + return nil + } + + runners = append(runners, resp.Runners...) + if rr.NextPage == 0 { + break + } + opt.Page = rr.NextPage + } + + return runners +} + +func getRunnersEnterpriseFromGithub() { + if config.EnterpriseName == "" { + return + } + for { + runners := getAllEnterpriseRunners() + + for _, runner := range runners { + var integerStatus float64 + if integerStatus = 0; runner.GetStatus() == "online" { + integerStatus = 1 + } + runnersEnterpriseGauge.WithLabelValues(*runner.OS, *runner.Name, strconv.FormatInt(runner.GetID(), 10)).Set(integerStatus) + } + + time.Sleep(time.Duration(config.Github.Refresh) * time.Second) + } +} diff --git a/pkg/metrics/get_runners_from_github.go b/pkg/metrics/get_runners_from_github.go index f0b2260..efd68fc 100644 --- a/pkg/metrics/get_runners_from_github.go +++ b/pkg/metrics/get_runners_from_github.go @@ -2,7 +2,6 @@ package metrics import ( "context" - "log" "strconv" "strings" "time" @@ -30,11 +29,11 @@ func getAllRepoRunners(owner string, repo string) []*github.Runner { for { resp, rr, err := client.Actions.ListRunners(context.Background(), owner, repo, opt) if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("ListRunners ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + logger.Infof("ListRunners ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) time.Sleep(time.Until(rl_err.Rate.Reset.Time)) continue } else if err != nil { - log.Printf("ListRunners error for repo %s: %s", repo, err.Error()) + logger.Infof("ListRunners error for repo %s: %s", repo, err.Error()) return nil } diff --git a/pkg/metrics/get_runners_organization_from_github.go b/pkg/metrics/get_runners_organization_from_github.go index d4f0d40..3df571d 100644 --- a/pkg/metrics/get_runners_organization_from_github.go +++ b/pkg/metrics/get_runners_organization_from_github.go @@ -2,7 +2,6 @@ package metrics import ( "context" - "log" "strconv" "time" @@ -29,11 +28,11 @@ func getAllOrgRunners(orga string) []*github.Runner { for { resp, rr, err := client.Actions.ListOrganizationRunners(context.Background(), orga, opt) if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("ListOrganizationRunners ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + logger.Infof("ListOrganizationRunners ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) time.Sleep(time.Until(rl_err.Rate.Reset.Time)) continue } else if err != nil { - log.Printf("ListOrganizationRunners error for org %s: %s", orga, err.Error()) + logger.Infof("ListOrganizationRunners error for org %s: %s", orga, err.Error()) return runners } diff --git a/pkg/metrics/get_workflow_runs_from_github.go b/pkg/metrics/get_workflow_runs_from_github.go index 4e376f1..7000082 100644 --- a/pkg/metrics/get_workflow_runs_from_github.go +++ b/pkg/metrics/get_workflow_runs_from_github.go @@ -2,7 +2,6 @@ package metrics import ( "context" - "log" "strconv" "strings" "time" @@ -32,12 +31,12 @@ func getFieldValue(repo string, run github.WorkflowRun, field string) string { case "workflow": r, exist := workflows[repo] if !exist { - log.Printf("Couldn't fetch repo '%s' from workflow cache.", repo) + logger.Infof("Couldn't fetch repo '%s' from workflow cache.", repo) return "unknown" } w, exist := r[*run.WorkflowID] if !exist { - log.Printf("Couldn't fetch repo '%s', workflow '%d' from workflow cache.", repo, *run.WorkflowID) + logger.Infof("Couldn't fetch repo '%s', workflow '%d' from workflow cache.", repo, *run.WorkflowID) return "unknown" } return *w.Name @@ -46,7 +45,7 @@ func getFieldValue(repo string, run github.WorkflowRun, field string) string { case "status": return *run.Status } - log.Printf("Tried to fetch invalid field '%s'", field) + logger.Infof("Tried to fetch invalid field '%s'", field) return "" } @@ -70,11 +69,11 @@ func getRecentWorkflowRuns(owner string, repo string) []*github.WorkflowRun { for { resp, rr, err := client.Actions.ListRepositoryWorkflowRuns(context.Background(), owner, repo, opt) if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("ListRepositoryWorkflowRuns ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + logger.Infof("ListRepositoryWorkflowRuns ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) time.Sleep(time.Until(rl_err.Rate.Reset.Time)) continue } else if err != nil { - log.Printf("ListRepositoryWorkflowRuns error for repo %s/%s: %s", owner, repo, err.Error()) + logger.Infof("ListRepositoryWorkflowRuns error for repo %s/%s: %s", owner, repo, err.Error()) return runs } @@ -92,11 +91,11 @@ func getRunUsage(owner string, repo string, runId int64) *github.WorkflowRunUsag for { resp, _, err := client.Actions.GetWorkflowRunUsageByID(context.Background(), owner, repo, runId) if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("GetWorkflowRunUsageByID ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + logger.Infof("GetWorkflowRunUsageByID ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) time.Sleep(time.Until(rl_err.Rate.Reset.Time)) continue } else if err != nil { - log.Printf("GetWorkflowRunUsageByID error for repo %s/%s and runId %d: %s", owner, repo, runId, err.Error()) + logger.Infof("GetWorkflowRunUsageByID error for repo %s/%s and runId %d: %s", owner, repo, runId, err.Error()) return nil } return resp diff --git a/pkg/metrics/github_fetcher.go b/pkg/metrics/github_fetcher.go index cb79fdf..612ba85 100644 --- a/pkg/metrics/github_fetcher.go +++ b/pkg/metrics/github_fetcher.go @@ -2,7 +2,6 @@ package metrics import ( "context" - "log" "strings" "time" @@ -28,11 +27,11 @@ func getAllReposForOrg(orga string) []string { for { repos_page, resp, err := client.Repositories.ListByOrg(context.Background(), orga, opt) if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("ListByOrg ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + logger.Infof("ListByOrg ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) time.Sleep(time.Until(rl_err.Rate.Reset.Time)) continue } else if err != nil { - log.Printf("ListByOrg error for %s: %s", orga, err.Error()) + logger.Infof("ListByOrg error for %s: %s", orga, err.Error()) break } for _, repo := range repos_page { @@ -57,11 +56,11 @@ func getAllWorkflowsForRepo(owner string, repo string) map[int64]github.Workflow for { workflows_page, resp, err := client.Actions.ListWorkflows(context.Background(), owner, repo, opt) if rl_err, ok := err.(*github.RateLimitError); ok { - log.Printf("ListWorkflows ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) + logger.Infof("ListWorkflows ratelimited. Pausing until %s", rl_err.Rate.Reset.Time.String()) time.Sleep(time.Until(rl_err.Rate.Reset.Time)) continue } else if err != nil { - log.Printf("ListWorkflows error for %s: %s", repo, err.Error()) + logger.Infof("ListWorkflows error for %s: %s", repo, err.Error()) return res } for _, w := range workflows_page.Workflows { @@ -101,7 +100,7 @@ func periodicGithubFetcher() { } non_empty_repos = append(non_empty_repos, repo) ww[repo] = workflows_for_repo - log.Printf("Fetched %d workflows for repository %s", len(ww[repo]), repo) + logger.Infof("Fetched %d workflows for repository %s", len(ww[repo]), repo) } repositories = non_empty_repos workflows = ww diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index e803203..c17546c 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -3,12 +3,12 @@ package metrics import ( "context" "fmt" - "log" "net/http" "net/url" "strings" "github.com/spendesk/github-actions-exporter/pkg/config" + "go.uber.org/zap" "github.com/bradleyfalzon/ghinstallation/v2" "github.com/die-net/lrucache" @@ -23,10 +23,12 @@ var ( err error workflowRunStatusGauge *prometheus.GaugeVec workflowRunDurationGauge *prometheus.GaugeVec + logger *zap.SugaredLogger ) // InitMetrics - register metrics in prometheus lib and start func for monitor -func InitMetrics() { +func InitMetrics(freshLogger *zap.SugaredLogger) { + logger = freshLogger workflowRunStatusGauge = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Name: "github_workflow_run_status", @@ -50,7 +52,7 @@ func InitMetrics() { client, err = NewClient() if err != nil { - log.Fatalln("Error: Client creation failed." + err.Error()) + logger.Fatalln("Error: Client creation failed." + err.Error()) } go periodicGithubFetcher() @@ -80,12 +82,12 @@ func NewClient() (*github.Client, error) { cachedTransport = httpcache.NewTransport(cache) if len(config.Github.Token) > 0 { - log.Printf("authenticating with Github Token") + logger.Info("authenticating with Github Token") ctx := context.Background() ctx = context.WithValue(ctx, "HTTPClient", cachedTransport.Client()) httpClient = oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.Github.Token})) } else { - log.Printf("authenticating with Github App") + logger.Info("authenticating with Github App") transport, err := ghinstallation.NewKeyFromFile(cachedTransport, config.Github.AppID, config.Github.AppInstallationID, config.Github.AppPrivateKey) if err != nil { return nil, fmt.Errorf("authentication failed: %v", err) diff --git a/pkg/server/server.go b/pkg/server/server.go index c99a0be..41c3a07 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -1,20 +1,20 @@ package server import ( - "log" "strconv" "github.com/fasthttp/router" "github.com/urfave/cli/v2" "github.com/valyala/fasthttp" + "go.uber.org/zap" "github.com/spendesk/github-actions-exporter/pkg/config" "github.com/spendesk/github-actions-exporter/pkg/metrics" ) // RunServer - run http server for expose metrics -func RunServer(ctx *cli.Context) error { - metrics.InitMetrics() +func RunServer(ctx *cli.Context, logger *zap.SugaredLogger) error { + metrics.InitMetrics(logger) r := router.New() r.GET("/", func(ctx *fasthttp.RequestCtx) { @@ -30,6 +30,6 @@ func RunServer(ctx *cli.Context) error { r.GET("/debug/pprof/{profile}", pprofHandlerIndex) } - log.Print("exporter listening on 0.0.0.0:" + strconv.Itoa(config.Port)) + logger.Info("exporter listening on 0.0.0.0:" + strconv.Itoa(config.Port)) return fasthttp.ListenAndServe(":"+strconv.Itoa(config.Port), r.Handler) }