Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
FROM golang:1.18.2 as build
FROM golang:1.24.4 as build

COPY ./ /go/src/github.com/chatwork/sendgrid-stats-exporter
WORKDIR /go/src/github.com/chatwork/sendgrid-stats-exporter

RUN go mod download \
# && go test ./... \
&& CGO_ENABLED=0 GOOS=linux go build -o /bin/exporter
# && go test ./... \
&& CGO_ENABLED=0 GOOS=linux go build -o /bin/exporter

FROM alpine:3.15

RUN apk --no-cache add ca-certificates \
&& addgroup exporter \
&& adduser -S -G exporter exporter
&& addgroup exporter \
&& adduser -S -G exporter exporter
USER exporter
COPY --from=build /bin/exporter /bin/exporter

Expand Down
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
USER := ada-u
REPO := sendgrid-stats-exporter
REGISTRY ?= chatwork
REPO ?= sendgrid-stats-exporter
GIT_TAG := $(shell git tag --points-at HEAD)
GIT_HASH := $(shell git rev-parse HEAD)
VERSION := $(shell if [ -n "$(GIT_TAG)" ]; then echo "$(GIT_TAG)"; else echo "$(GIT_HASH)"; fi)
VERSION ?= $(shell if [ -n "$(GIT_TAG)" ]; then echo "$(GIT_TAG)"; else echo "$(GIT_HASH)"; fi)

DIST_DIR := $(shell if [ -n "$(GOOS)$(GOARCH)" ]; then echo "./dist/$(GOOS)-$(GOARCH)"; else echo "./dist"; fi)

Expand All @@ -21,15 +21,15 @@ build:

.PHONY: build-image
build-image:
docker build -t chatwork/"$(REPO)" .
docker tag chatwork/"$(REPO)":latest chatwork/"$(REPO)":"$(VERSION)"
docker build -t ${REGISTRY}/$(REPO) .
docker tag "${REGISTRY}/$(REPO):latest "${REGISTRY}/$(REPO):$(VERSION)

.PHONY: push-image
push-image:
docker push chatwork/"$(REPO)"
docker push ${REGISTRY}/$(REPO)

build-image-multi:
docker buildx build -t chatwork/"$(REPO)":"$(VERSION)" --platform=$(DOCKER_BUILD_PLATFORMS) .
docker buildx build -t ${REGISTRY}/$(REPO):$(VERSION) --platform=$(DOCKER_BUILD_PLATFORMS) .

push-image-multi:
docker buildx build $(DOCKER_BUILDX_ARGS) -t chatwork/"$(REPO)":"$(VERSION)" --platform=$(DOCKER_BUILD_PLATFORMS) .
docker buildx build $(DOCKER_BUILDX_ARGS) -t ${REGISTRY}/$(REPO):$(VERSION) --platform=$(DOCKER_BUILD_PLATFORMS) .
41 changes: 20 additions & 21 deletions collect.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package main

import (
"log/slog"
"time"

"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/jinzhu/now"
"github.com/prometheus/client_golang/prometheus"
)

type Collector struct {
logger log.Logger
logger slog.Logger

blocks *prometheus.Desc
bounceDrops *prometheus.Desc
Expand All @@ -30,102 +29,102 @@ type Collector struct {
unsubscribes *prometheus.Desc
}

func collector(logger log.Logger) *Collector {
func collector(logger slog.Logger) *Collector {
return &Collector{
logger: logger,

blocks: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "blocks"),
prometheus.BuildFQName(namespace, "", "blocks_total"),
"blocks",
[]string{"user_name"},
nil,
),
bounceDrops: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "bounce_drops"),
prometheus.BuildFQName(namespace, "", "bounce_drops_total"),
"bounce_drops",
[]string{"user_name"},
nil,
),
bounces: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "bounces"),
prometheus.BuildFQName(namespace, "", "bounces_total"),
"bounces",
[]string{"user_name"},
nil,
),
clicks: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "clicks"),
prometheus.BuildFQName(namespace, "", "clicks_total"),
"clicks",
[]string{"user_name"},
nil,
),
deferred: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "deferred"),
prometheus.BuildFQName(namespace, "", "deferred_total"),
"deferred",
[]string{"user_name"},
nil,
),
delivered: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "delivered"),
prometheus.BuildFQName(namespace, "", "delivered_total"),
"delivered",
[]string{"user_name"},
nil,
),
invalidEmails: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "invalid_emails"),
prometheus.BuildFQName(namespace, "", "invalid_emails_total"),
"invalid_emails",
[]string{"user_name"},
nil,
),
opens: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "opens"),
prometheus.BuildFQName(namespace, "", "opens_total"),
"opens",
[]string{"user_name"},
nil,
),
processed: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "processed"),
prometheus.BuildFQName(namespace, "", "processed_total"),
"processed",
[]string{"user_name"},
nil,
),
requests: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "requests"),
prometheus.BuildFQName(namespace, "", "requests_total"),
"requests",
[]string{"user_name"},
nil,
),
spamReportDrops: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "spam_report_drops"),
prometheus.BuildFQName(namespace, "", "spam_report_drops_total"),
"spam_report_drops",
[]string{"user_name"},
nil,
),
spamReports: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "spam_reports"),
prometheus.BuildFQName(namespace, "", "spam_reports_total"),
"spam_reports",
[]string{"user_name"},
nil,
),
uniqueClicks: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "unique_clicks"),
prometheus.BuildFQName(namespace, "", "unique_clicks_total"),
"unique_clicks",
[]string{"user_name"},
nil,
),
uniqueOpens: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "unique_opens"),
prometheus.BuildFQName(namespace, "", "unique_opens_total"),
"unique_opens",
[]string{"user_name"},
nil,
),
unsubscribeDrops: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "unsubscribe_drops"),
prometheus.BuildFQName(namespace, "", "unsubscribe_drops_total"),
"unsubscribe_drops",
[]string{"user_name"},
nil,
),
unsubscribes: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "unsubscribes"),
prometheus.BuildFQName(namespace, "", "unsubscribes_total"),
"unsubscribes",
[]string{"user_name"},
nil,
Expand All @@ -150,7 +149,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {

statistics, err := collectByDate(queryDate, today)
if err != nil {
level.Error(c.logger).Log(err)
c.logger.Error("collectByDate error", "err", err)

return
}
Expand Down
28 changes: 12 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
module github.com/chatwork/sendgrid-stats-exporter

go 1.18
go 1.24

require (
github.com/go-kit/kit v0.12.0
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/jinzhu/now v1.1.5
github.com/prometheus/client_golang v1.12.2
github.com/prometheus/common v0.34.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
github.com/prometheus/client_golang v1.22.0
github.com/prometheus/common v0.64.0
)

require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/go-kit/log v0.2.0 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 // indirect
google.golang.org/protobuf v1.27.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
golang.org/x/sys v0.33.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
)
Loading