Skip to content

Commit

Permalink
Use https://github.com/nikhilsbhat/gocd-sdk-go while interacting with…
Browse files Browse the repository at this point in the history
… GoCD.
  • Loading branch information
nikhilsbhat committed Oct 12, 2022
1 parent 85a4260 commit 4ec61da
Show file tree
Hide file tree
Showing 26 changed files with 182 additions and 1,056 deletions.
33 changes: 12 additions & 21 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -44,6 +43,7 @@ const (

const (
defaultAppPort = 8090
defaultTimeout = 30
)

var (
Expand Down Expand Up @@ -203,37 +203,21 @@ func goCdExport(context *cli.Context) error {
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP, syscall.SIGQUIT) //nolint:govet

promLogConfig := &promlog.Config{Level: &promlog.AllowedLevel{}, Format: &promlog.AllowedFormat{}}
if err := promLogConfig.Level.Set(finalConfig.LogLevel); err != nil {
if err = promLogConfig.Level.Set(finalConfig.LogLevel); err != nil {
return fmt.Errorf("configuring logger errored with: %w", err)
}
logger := promlog.New(promLogConfig)

var caContent []byte
if len(finalConfig.CaPath) != 0 {
ca, err := ioutil.ReadFile(finalConfig.CaPath)
ca, err := os.ReadFile(finalConfig.CaPath)
if err != nil {
level.Error(logger).Log(common.LogCategoryErr, getCAErrMsg(finalConfig.CaPath)) //nolint:errcheck
}
caContent = ca
}

pipelinePaths := make([]string, 0)
pipelinePaths = append(pipelinePaths, finalConfig.GoCdPipelinesRootPath)
pipelinePaths = append(pipelinePaths, finalConfig.GoCdPipelinesPath...)

client := gocd.NewClient(
finalConfig.GoCdBaseURL,
finalConfig.GoCdUserName,
finalConfig.GoCdPassword,
finalConfig.LogLevel,
finalConfig.APICron,
finalConfig.DiskCron,
finalConfig.MetricCron,
caContent,
pipelinePaths,
finalConfig.SkipMetrics,
logger,
)
client := gocd.NewClient(*finalConfig, logger, caContent)

// running schedules
go func() {
Expand All @@ -258,8 +242,15 @@ func goCdExport(context *cli.Context) error {

level.Info(logger).Log(common.LogCategoryMsg, fmt.Sprintf("metrics will be exposed on port: %d", finalConfig.Port)) //nolint:errcheck
level.Info(logger).Log(common.LogCategoryMsg, fmt.Sprintf("metrics will be exposed on endpoint: %s", finalConfig.Endpoint)) //nolint:errcheck

http.Handle(finalConfig.Endpoint, promhttp.Handler())
if err := http.ListenAndServe(fmt.Sprintf(":%d", finalConfig.Port), nil); err != nil {

server := &http.Server{
Addr: fmt.Sprintf(":%d", finalConfig.Port),
ReadHeaderTimeout: defaultTimeout * time.Second,
}

if err = server.ListenAndServe(); err != nil {
return fmt.Errorf("starting server on specified port failed with: %w", err)
}

Expand Down
13 changes: 7 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module github.com/nikhilsbhat/gocd-prometheus-exporter

go 1.17
go 1.19

require (
github.com/basgys/goxml2json v1.1.0
github.com/go-co-op/gocron v1.16.2
github.com/go-kit/log v0.2.0
github.com/go-resty/resty/v2 v2.7.0
github.com/imdario/mergo v0.3.13
github.com/nikhilsbhat/gocd-sdk-go v0.0.2
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.34.0
github.com/stretchr/testify v1.8.0
Expand All @@ -22,21 +21,23 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/jinzhu/copier v0.3.5 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220502124256-b6088ccd6cba // indirect
golang.org/x/text v0.3.7 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
13 changes: 6 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,12 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/basgys/goxml2json v1.1.0 h1:4ln5i4rseYfXNd86lGEB+Vi652IsIXIvggKM/BhUKVw=
github.com/basgys/goxml2json v1.1.0/go.mod h1:wH7a5Np/Q4QoECFIU8zTQlZwZkrilY0itPfecMw41Dw=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
Expand All @@ -56,7 +53,6 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -142,6 +138,8 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk=
github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg=
github.com/jinzhu/copier v0.3.5 h1:GlvfUwHk62RokgqVNvYsku0TATCF7bAHVwEXoBh3iJg=
github.com/jinzhu/copier v0.3.5/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
Expand All @@ -153,6 +151,7 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
Expand All @@ -161,7 +160,6 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
Expand All @@ -172,6 +170,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nikhilsbhat/gocd-sdk-go v0.0.2 h1:g1/KVBxmGjynDTCdnhnw1+t/fClu4MxGFrj2kJloyyM=
github.com/nikhilsbhat/gocd-sdk-go v0.0.2/go.mod h1:3XwSMe/nFH/I0Kt2+ToKKWFyD6yvJb4HaoP0dBHytY4=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -209,6 +209,7 @@ github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -369,7 +370,6 @@ golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
Expand Down Expand Up @@ -500,7 +500,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
3 changes: 1 addition & 2 deletions pkg/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package app
import (
"errors"
"fmt"
"io/ioutil"
"log"
"os"
"time"
Expand Down Expand Up @@ -39,7 +38,7 @@ func GetConfig(conf Config, path string) (*Config, error) {
return &conf, fmt.Errorf("fetching config file information failed with: %w", err)
}

fileOUT, err := ioutil.ReadFile(path)
fileOUT, err := os.ReadFile(path)
if err != nil {
log.Println("failed to read the config file, dropping configurations from file")

Expand Down
12 changes: 2 additions & 10 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/thoas/go-funk"

goCD "github.com/nikhilsbhat/gocd-sdk-go"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -83,16 +84,8 @@ func (e *Exporter) collect(channel chan<- prometheus.Metric) { //nolint:funlen
e.backupConfigured.Collect(channel)
}

// fetching pipeline sizes
if !funk.Contains(e.skipMetrics, common.MetricPipelineSize) {
for pipeline, pipelineInfo := range gocd.CurrentPipelineSize {
e.pipelinesDiskUsage.WithLabelValues(pipeline, pipelineInfo.Type).Set(pipelineInfo.Size)
}
e.pipelinesDiskUsage.Collect(channel)
}

if !funk.Contains(e.skipMetrics, common.MetricVersion) {
if (gocd.CurrentVersion == gocd.VersionInfo{}) {
if (gocd.CurrentVersion == goCD.VersionInfo{}) {
e.versionInfo.WithLabelValues("", "", "").Set(0)
} else {
e.versionInfo.WithLabelValues(gocd.CurrentVersion.Version, gocd.CurrentVersion.GitSHA, gocd.CurrentVersion.FullVersion).Set(1)
Expand Down Expand Up @@ -132,7 +125,6 @@ func (e *Exporter) collect(channel chan<- prometheus.Metric) { //nolint:funlen
}

func (e *Exporter) Describe(channel chan<- *prometheus.Desc) {
e.pipelinesDiskUsage.Describe(channel)
e.agentsCount.Describe(channel)
e.agentDown.Describe(channel)
e.agentDisk.Describe(channel)
Expand Down
7 changes: 0 additions & 7 deletions pkg/exporter/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ type Exporter struct {
skipMetrics []string
agentsCount *prometheus.GaugeVec
agentDisk *prometheus.GaugeVec
pipelinesDiskUsage *prometheus.GaugeVec
agentDown *prometheus.GaugeVec
serverHealth *prometheus.GaugeVec
configRepoCount *prometheus.GaugeVec
Expand Down Expand Up @@ -51,12 +50,6 @@ func NewExporter(logger log.Logger, skipMetrics []string) *Exporter {
Help: "latest information on GoCD agent's state",
}, []string{"name", "id", "version", "os", "sandbox", "state", "config_state"},
),
pipelinesDiskUsage: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: common.Namespace,
Name: common.MetricPipelineSize,
Help: "disk size that GoCD pipeline have occupied in bytes",
}, []string{"pipeline_path", "type"},
),
serverHealth: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Namespace: common.Namespace,
Name: common.MetricServerHealth,
Expand Down
35 changes: 7 additions & 28 deletions pkg/gocd/admins.go
Original file line number Diff line number Diff line change
@@ -1,44 +1,23 @@
package gocd

import (
"fmt"
"net/http"

"github.com/nikhilsbhat/gocd-prometheus-exporter/pkg/common"

"github.com/go-kit/log/level"
)

// GetAdminsInfo fetches information of all system admins present in GoCD server.
func (conf *client) GetAdminsInfo() (SystemAdmins, error) {
conf.client.SetHeaders(map[string]string{
"Accept": common.GoCdHeaderVersionTwo,
})
level.Debug(conf.logger).Log(common.LogCategoryMsg, getTryMessages("admins")) //nolint:errcheck
func (conf *client) updateAdminsInfo() {
conf.lock.Lock()
client := conf.getCronClient()

var adminsConf SystemAdmins
resp, err := conf.client.R().SetResult(&adminsConf).Get(common.GoCdSystemAdminEndpoint)
admins, err := client.GetSystemAdmins()
if err != nil {
return SystemAdmins{}, fmt.Errorf("call made to get system admin errored with: %w", err)
}
if resp.StatusCode() != http.StatusOK {
return SystemAdmins{}, apiWithCodeError(resp.StatusCode())
level.Error(conf.logger).Log(common.LogCategoryErr, apiError("system admin", err.Error())) //nolint:errcheck
}

level.Debug(conf.logger).Log(common.LogCategoryMsg, getSuccessMessages("admins")) //nolint:errcheck

return adminsConf, nil
}

func (conf *client) updateAdminsInfo() {
newConf := conf.getCronClient()
newConf.lock.Lock()
admins, err := newConf.GetAdminsInfo()
if err != nil {
level.Error(newConf.logger).Log(common.LogCategoryErr, apiError("system admin", err.Error())) //nolint:errcheck
}
if err == nil {
CurrentSystemAdmins = admins
}
defer newConf.lock.Unlock()

defer conf.lock.Unlock()
}
Loading

0 comments on commit 4ec61da

Please sign in to comment.