Skip to content

Commit

Permalink
Merge pull request #12 from chatwork/timezone
Browse files Browse the repository at this point in the history
Make timezone configurable
  • Loading branch information
ada-u authored Jan 18, 2021
2 parents 8b091f7 + ca1d55d commit 9d09ad0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Prometheus exporter for SendGrid daily metrics exposed by SendGrid Stats API(v3)

```
$ make
$ ./exporter --sendgrid.api-key='secret' --web.listen-address=':9154' --web.disable-exporter-metrics
$ ./dist/exporter --sendgrid.api-key='secret' --web.listen-address=':9154' --web.disable-exporter-metrics
```

```
Expand All @@ -31,6 +31,8 @@ Flags:
--sendgrid.api-key="secret"
[Required] Set SendGrid API key
--sendgrid.username="" [Optional] Set SendGrid username as a label for each metrics. This is for identifying multiple SendGrid users metrics.
--sendgrid.location="" [Optional] Set a zone name.(e.g. 'Asia/Tokyo') The default is UTC.
--sendgrid.time-offset=0 [Optional] Specify the offset in second from UTC as an integer.(e.g. '32400') This needs to be set along with location.
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
--version Show application version.
Expand Down
2 changes: 1 addition & 1 deletion charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ name: sendgrid-stats-exporter
description: A Helm chart for chatwork/sendgrid-stats-exporter
type: application
version: 0.0.1
appVersion: 0.0.3
appVersion: 0.0.7
1 change: 1 addition & 0 deletions charts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The following table lists the configurable parameters of the Sendgrid-stats-expo
| `podSecurityContext` | Security context for the pod | `{}` |
| `securityContext` | Security context for container | `{}` |
| `envFrom` | Extra custom environment variables from ConfigMaps | `[]` |
| `extraEnv` | Pod extra environment value | `[]`|
| `secret.apiKey` | SendGrid api token | `{}` |
| `secret.username` | SendGrid username | `[]` |
| `service.type` | Service Type | `"ClusterIP"` |
Expand Down
4 changes: 0 additions & 4 deletions charts/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,5 @@ Create the name of the service account to use
Return secret name to be used based on provided values.
*/}}
{{- define "sendgrid-stats-exporter.secretName" -}}
{{- if not .Values.secret.existingSecretName -}}
{{ default (printf "%s-secret" (include "sendgrid-stats-exporter.fullname" . )) }}
{{- else -}}
{{ .Values.secret.existingSecretName }}
{{- end -}}
{{- end -}}
2 changes: 2 additions & 0 deletions charts/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ spec:
secretKeyRef:
name: {{ include "sendgrid-stats-exporter.secretName" . }}
key: apiKey
{{- with .Values.extraEnv }}{{ toYaml . | nindent 12 }}
{{- end }}
ports:
- name: http
containerPort: 9154
Expand Down
4 changes: 2 additions & 2 deletions charts/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ replicaCount: 1
image:
repository: chatwork/sendgrid-stats-exporter
pullPolicy: IfNotPresent
tag: "0.0.3"
tag: "0.0.7"

imagePullSecrets: []
nameOverride: ""
Expand All @@ -28,9 +28,9 @@ securityContext: {}
# runAsUser: 1000

envFrom: []
extraEnv: []

secret:
existingSecretName:
username: ""
apiKey: ""

Expand Down
9 changes: 8 additions & 1 deletion collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,14 @@ func collector(logger log.Logger) *Collector {
}

func (c *Collector) Collect(ch chan<- prometheus.Metric) {
today := time.Now()
var today time.Time

if *location != "" && *timeOffset != 0 {
loc := time.FixedZone(*location, *timeOffset)
today = time.Now().In(loc)
} else {
today = time.Now()
}

statistics, err := collectByDate(today)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ var (
"sendgrid.username",
"[Optional] Set SendGrid username as a label for each metrics. This is for identifying multiple SendGrid users metrics.",
).Default("").Envar("SENDGRID_USER_NAME").String()
location = kingpin.Flag(
"sendgrid.location",
"[Optional] Set a zone name.(e.g. 'Asia/Tokyo') The default is UTC.",
).Default("").Envar("SENDGRID_LOCATION").String()
timeOffset = kingpin.Flag(
"sendgrid.time-offset",
"[Optional] Specify the offset in second from UTC as an integer.(e.g. '32400') This needs to be set along with location.",
).Default("0").Envar("SENDGRID_TIME_OFFSET").Int()
)

func main() {
Expand Down

0 comments on commit 9d09ad0

Please sign in to comment.