Skip to content

Commit

Permalink
fix issue "Refresh token #4"
Browse files Browse the repository at this point in the history
  • Loading branch information
alexopryshko committed Aug 28, 2021
1 parent f60d37a commit a746015
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
17 changes: 8 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
FROM golang:1.16-alpine as builder

WORKDIR $GOPATH/src/kts/push
WORKDIR $GOPATH/src/github.com/ktsstudio/selectel-exporter
COPY . .
RUN ls -al .
RUN go build pkg/main.go
RUN cp main /
RUN apk update && apk upgrade && apk add --no-cache ca-certificates
RUN update-ca-certificates
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/selectel-exporter pkg/main.go

FROM alpine:3.14

COPY --from=builder /main /app/
WORKDIR /app
CMD ./main
FROM scratch
COPY --from=builder /go/bin/selectel-exporter /go/bin/selectel-exporter
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
ENTRYPOINT ["/go/bin/selectel-exporter"]
32 changes: 16 additions & 16 deletions pkg/exporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ type selectelCollector interface {
}

type exporter struct {
token string
region string
project selapi.Project
token string
region string
project selapi.Project
openstackAccountToken string
lastTokenUpdate time.Time
lastTokenUpdate time.Time

refreshPeriod time.Duration
stopCh chan bool
wg sync.WaitGroup
collectors []selectelCollector
stopCh chan bool
wg sync.WaitGroup
collectors []selectelCollector

datastores []selapi.Datastore
}
Expand All @@ -47,11 +47,11 @@ func Init(config *config.ExporterConfig, refreshPeriod time.Duration) (*exporter
}

e := &exporter{
token: config.Token,
region: config.Region,
project: project,
token: config.Token,
region: config.Region,
project: project,
refreshPeriod: refreshPeriod,
stopCh: make(chan bool),
stopCh: make(chan bool),
}
err = e.obtainToken()
if err != nil {
Expand Down Expand Up @@ -79,10 +79,10 @@ func (e *exporter) obtainToken() error {
}

func (e *exporter) checkToken() error {
if e.lastTokenUpdate.Sub(time.Now()) > 24 * time.Hour {
return e.obtainToken()
}
return nil
if time.Now().Sub(e.lastTokenUpdate) > 20*time.Hour {
return e.obtainToken()
}
return nil
}

func (e *exporter) fetchDatastores() error {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (e *exporter) runCollectors() {
wg.Wait()
}

func (e *exporter) loop() {
func (e *exporter) loop() {
log.Println("exporter loop has started")
e.wg.Add(1)
for {
Expand Down

0 comments on commit a746015

Please sign in to comment.