Skip to content

Commit 9d09ad0

Browse files
authored
Merge pull request #12 from chatwork/timezone
Make timezone configurable
2 parents 8b091f7 + ca1d55d commit 9d09ad0

File tree

8 files changed

+25
-9
lines changed

8 files changed

+25
-9
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Prometheus exporter for SendGrid daily metrics exposed by SendGrid Stats API(v3)
1010

1111
```
1212
$ make
13-
$ ./exporter --sendgrid.api-key='secret' --web.listen-address=':9154' --web.disable-exporter-metrics
13+
$ ./dist/exporter --sendgrid.api-key='secret' --web.listen-address=':9154' --web.disable-exporter-metrics
1414
```
1515

1616
```
@@ -31,6 +31,8 @@ Flags:
3131
--sendgrid.api-key="secret"
3232
[Required] Set SendGrid API key
3333
--sendgrid.username="" [Optional] Set SendGrid username as a label for each metrics. This is for identifying multiple SendGrid users metrics.
34+
--sendgrid.location="" [Optional] Set a zone name.(e.g. 'Asia/Tokyo') The default is UTC.
35+
--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.
3436
--log.level=info Only log messages with the given severity or above. One of: [debug, info, warn, error]
3537
--log.format=logfmt Output format of log messages. One of: [logfmt, json]
3638
--version Show application version.

charts/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ name: sendgrid-stats-exporter
33
description: A Helm chart for chatwork/sendgrid-stats-exporter
44
type: application
55
version: 0.0.1
6-
appVersion: 0.0.3
6+
appVersion: 0.0.7

charts/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The following table lists the configurable parameters of the Sendgrid-stats-expo
3939
| `podSecurityContext` | Security context for the pod | `{}` |
4040
| `securityContext` | Security context for container | `{}` |
4141
| `envFrom` | Extra custom environment variables from ConfigMaps | `[]` |
42+
| `extraEnv` | Pod extra environment value | `[]`|
4243
| `secret.apiKey` | SendGrid api token | `{}` |
4344
| `secret.username` | SendGrid username | `[]` |
4445
| `service.type` | Service Type | `"ClusterIP"` |

charts/templates/_helpers.tpl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,5 @@ Create the name of the service account to use
6565
Return secret name to be used based on provided values.
6666
*/}}
6767
{{- define "sendgrid-stats-exporter.secretName" -}}
68-
{{- if not .Values.secret.existingSecretName -}}
6968
{{ default (printf "%s-secret" (include "sendgrid-stats-exporter.fullname" . )) }}
70-
{{- else -}}
71-
{{ .Values.secret.existingSecretName }}
7269
{{- end -}}
73-
{{- end -}}

charts/templates/deployment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ spec:
4646
secretKeyRef:
4747
name: {{ include "sendgrid-stats-exporter.secretName" . }}
4848
key: apiKey
49+
{{- with .Values.extraEnv }}{{ toYaml . | nindent 12 }}
50+
{{- end }}
4951
ports:
5052
- name: http
5153
containerPort: 9154

charts/values.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ replicaCount: 1
33
image:
44
repository: chatwork/sendgrid-stats-exporter
55
pullPolicy: IfNotPresent
6-
tag: "0.0.3"
6+
tag: "0.0.7"
77

88
imagePullSecrets: []
99
nameOverride: ""
@@ -28,9 +28,9 @@ securityContext: {}
2828
# runAsUser: 1000
2929

3030
envFrom: []
31+
extraEnv: []
3132

3233
secret:
33-
existingSecretName:
3434
username: ""
3535
apiKey: ""
3636

collect.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ func collector(logger log.Logger) *Collector {
133133
}
134134

135135
func (c *Collector) Collect(ch chan<- prometheus.Metric) {
136-
today := time.Now()
136+
var today time.Time
137+
138+
if *location != "" && *timeOffset != 0 {
139+
loc := time.FixedZone(*location, *timeOffset)
140+
today = time.Now().In(loc)
141+
} else {
142+
today = time.Now()
143+
}
137144

138145
statistics, err := collectByDate(today)
139146
if err != nil {

main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ var (
4444
"sendgrid.username",
4545
"[Optional] Set SendGrid username as a label for each metrics. This is for identifying multiple SendGrid users metrics.",
4646
).Default("").Envar("SENDGRID_USER_NAME").String()
47+
location = kingpin.Flag(
48+
"sendgrid.location",
49+
"[Optional] Set a zone name.(e.g. 'Asia/Tokyo') The default is UTC.",
50+
).Default("").Envar("SENDGRID_LOCATION").String()
51+
timeOffset = kingpin.Flag(
52+
"sendgrid.time-offset",
53+
"[Optional] Specify the offset in second from UTC as an integer.(e.g. '32400') This needs to be set along with location.",
54+
).Default("0").Envar("SENDGRID_TIME_OFFSET").Int()
4755
)
4856

4957
func main() {

0 commit comments

Comments
 (0)