Skip to content
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

feat: upgrading golang version as well as golang promtheus client #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.15-buster AS build
FROM golang:1.19.5-bullseye AS build

ADD . /tmp/s3_exporter

Expand Down
11 changes: 3 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@ go 1.15

require (
github.com/aws/aws-sdk-go v1.35.9
github.com/go-sql-driver/mysql v1.5.0 // indirect
github.com/prometheus/client_golang v1.8.0
github.com/prometheus/common v0.14.0
github.com/sirupsen/logrus v1.7.0 // indirect
github.com/stretchr/testify v1.5.1 // indirect
golang.org/x/sys v0.0.0-20201018121011-98379d014ca7 // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/protobuf v1.25.0 // indirect
github.com/go-kit/kit v0.9.0
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/common v0.39.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
590 changes: 331 additions & 259 deletions go.sum

Large diffs are not rendered by default.

33 changes: 22 additions & 11 deletions s3_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"os"
"time"


"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/go-kit/kit/log/level"
"github.com/go-kit/kit/log"
"github.com/prometheus/common/promlog"
"github.com/prometheus/common/promlog/flag"
"github.com/prometheus/common/version"
kingpin "gopkg.in/alecthomas/kingpin.v2"

Expand Down Expand Up @@ -63,8 +67,11 @@ var (
"A count of all the keys between the prefix and the next occurrence of the string specified by the delimiter",
[]string{"bucket", "prefix", "delimiter"}, nil,
)

)

var logger log.Logger

// Exporter is our exporter type
type Exporter struct {
bucket string
Expand Down Expand Up @@ -108,9 +115,9 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
for {
resp, err := e.svc.ListObjectsV2(query)
if err != nil {
log.Errorln(err)
level.Error(logger).Log(err)
ch <- prometheus.MustNewConstMetric(
s3ListSuccess, prometheus.GaugeValue, 0, e.bucket, e.prefix,
s3ListSuccess, prometheus.GaugeValue, 0, e.bucket, e.prefix, e.delimiter,
)
return
}
Expand Down Expand Up @@ -195,7 +202,7 @@ type discoveryTarget struct {
func discoveryHandler(w http.ResponseWriter, r *http.Request, svc s3iface.S3API) {
result, err := svc.ListBuckets(&s3.ListBucketsInput{})
if err != nil {
log.Errorln(err)
level.Error(logger).Log(err)
http.Error(w, "error listing buckets", http.StatusInternalServerError)
return
}
Expand Down Expand Up @@ -239,31 +246,35 @@ func main() {
forcePathStyle = app.Flag("s3.force-path-style", "Custom force path style").Bool()
)

log.AddFlags(app)

app.Version(version.Print(namespace + "_exporter"))
app.HelpFlag.Short('h')
var promlogConfig = &promlog.Config{}
flag.AddFlags(app,promlogConfig)
kingpin.MustParse(app.Parse(os.Args[1:]))

logger = promlog.New(promlogConfig)
var sess *session.Session
var err error

sess, err = session.NewSession()
if err != nil {
log.Errorln("Error creating sessions ", err)
level.Error(logger).Log("Error creating sessions ", err)
}

cfg := aws.NewConfig()
if *endpointURL != "" {
cfg.WithEndpoint(*endpointURL)
}

level.Info(logger).Log("Endpoint Url", *endpointURL)
cfg.WithDisableSSL(*disableSSL)
cfg.WithS3ForcePathStyle(*forcePathStyle)

svc := s3.New(sess, cfg)

log.Infoln("Starting "+namespace+"_exporter", version.Info())
log.Infoln("Build context", version.BuildContext())
level.Info(logger).Log("Starting "+namespace+"_exporter", version.Info())
level.Info(logger).Log("Build context", version.BuildContext())


http.Handle(*metricsPath, promhttp.Handler())
http.HandleFunc(*probePath, func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -284,6 +295,6 @@ func main() {
</html>`))
})

log.Infoln("Listening on", *listenAddress)
log.Fatal(http.ListenAndServe(*listenAddress, nil))
level.Info(logger).Log("Listening on", *listenAddress)
level.Error(logger).Log(http.ListenAndServe(*listenAddress, nil))
}
27 changes: 0 additions & 27 deletions vendor/github.com/alecthomas/template/LICENSE

This file was deleted.

25 changes: 0 additions & 25 deletions vendor/github.com/alecthomas/template/README.md

This file was deleted.

Loading