Skip to content

Commit e49fedf

Browse files
authored
Spring cleaning and 1.3.1 release (#112)
* add ability to disable alert log * update prom common, stop querying alert log after 3 failures * give up after 3 consecutive failures to read alert log * updated godror * update toml * fixes #111 - update readme --------- Signed-off-by: Mark Nelson <mark.x.nelson@oracle.com>
1 parent ffe7916 commit e49fedf

File tree

7 files changed

+92
-29
lines changed

7 files changed

+92
-29
lines changed

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ OS_TYPE ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
33
ARCH_TYPE ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(ARCH)))
44
GOOS ?= $(shell go env GOOS)
55
GOARCH ?= $(shell go env GOARCH)
6-
VERSION ?= 1.3.0
6+
VERSION ?= 1.3.1
77
LDFLAGS := -X main.Version=$(VERSION)
88
GOFLAGS := -ldflags "$(LDFLAGS) -s -w"
99
BUILD_ARGS = --build-arg VERSION=$(VERSION)

Diff for: README.md

+25-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,20 @@ Contributions are welcome - please see [contributing](CONTRIBUTING.md).
2828

2929
## Release Notes
3030

31+
### Version 1.3.1, July 22, 2024
32+
33+
This release includes the following changes:
34+
35+
- Alert logs can be disabled by setting parameter `log.disable` to `1`.
36+
- Alert log exporter will stop if it gets three consecutive failures.
37+
- Updated the list of required permissions.
38+
- Updated the TxEventQ sample dashboard.
39+
- Updated some third-party dependencies.
40+
41+
Thank you to the following people for their suggestions and contributions:
42+
43+
- [@tux-jochen](https://github.com/tux-jochen)
44+
3145
### Version 1.3.0, June 7, 2024
3246

3347
This release includes the following changes:
@@ -305,7 +319,7 @@ oracledb_wait_time_user_io 24.5
305319

306320
## Database permissions required
307321

308-
For the built-in default metrics, the database user that the exporter uses to connect to the Oracle Database instance must have the `SELECT_CATALOG_ROLE` privilege and/or `SELECT` permission on the following tables.
322+
For the built-in default metrics, the database user that the exporter uses to connect to the Oracle Database instance must have the `SELECT_CATALOG_ROLE` privilege and/or `SELECT` permission on the following objects:
309323

310324
- dba_tablespace_usage_metrics
311325
- dba_tablespaces
@@ -317,6 +331,11 @@ For the built-in default metrics, the database user that the exporter uses to co
317331
- v$waitclassmetric
318332
- v$session
319333
- v$resource_limit
334+
- v$parameter
335+
- v$database
336+
- v$sqlstats
337+
- v$sysmetric
338+
- v$diag_alert_ext (for alert logs only)
320339

321340
## Alert logs
322341

@@ -353,6 +372,8 @@ Here is an example of the output:
353372
{"timestamp":"2023-09-02T05:40:43.644Z","moduleId":"","ecid":"","message":" 2048K 0 766 0 NONE"}
354373
```
355374

375+
You may disable alert logs by setting the parameter `log.disable` to `1`.
376+
356377
## Installation
357378

358379
There are a number of ways to run the exporter. In this section you will find information on running the exporter:
@@ -422,7 +443,7 @@ docker run -it --rm \
422443
-e DB_PASSWORD=Welcome12345 \
423444
-e DB_CONNECT_STRING=free23c:1521/freepdb \
424445
-p 9161:9161 \
425-
container-registry.oracle.com/database/observability-exporter:1.3.0
446+
container-registry.oracle.com/database/observability-exporter:1.3.1
426447
```
427448

428449
##### Using a wallet
@@ -449,7 +470,7 @@ docker run -it --rm \
449470
-e DB_CONNECT_STRING=devdb_tp \
450471
-v ./wallet:/wallet \
451472
-p 9161:9161 \
452-
container-registry.oracle.com/database/observability-exporter:1.3.0
473+
container-registry.oracle.com/database/observability-exporter:1.3.1
453474
```
454475

455476

@@ -712,7 +733,7 @@ An exmaple of [custom metrics for Transacational Event Queues](./custom-metrics-
712733
If you run the exporter as a container image and want to include your custom metrics in the image itself, you can use the following example `Dockerfile` to create a new image:
713734

714735
```Dockerfile
715-
FROM container-registry.oracle.com/database/observability-exporter:1.3.0
736+
FROM container-registry.oracle.com/database/observability-exporter:1.3.1
716737
COPY custom-metrics.toml /
717738
ENTRYPOINT ["/oracledb_exporter", "--custom.metrics", "/custom-metrics.toml"]
718739
```

Diff for: alertlog/alertlog.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,20 @@ type LogRecord struct {
2323
Message string `json:"message"`
2424
}
2525

26+
var queryFailures int = 0
27+
2628
func UpdateLog(logDestination string, logger log.Logger, db *sql.DB) {
2729

30+
if queryFailures == 3 {
31+
level.Info(logger).Log("msg", "Failed to query the alert log three consecutive times, so will not try any more")
32+
queryFailures++
33+
return
34+
}
35+
36+
if queryFailures > 3 {
37+
return
38+
}
39+
2840
// check if the log file exists, and if not, create it
2941
if _, err := os.Stat(logDestination); errors.Is(err, os.ErrNotExist) {
3042
level.Info(logger).Log("msg", "Log destination file does not exist, will try to create it: "+logDestination)
@@ -101,6 +113,7 @@ func UpdateLog(logDestination string, logger log.Logger, db *sql.DB) {
101113
rows, err := db.Query(stmt)
102114
if err != nil {
103115
level.Error(logger).Log("msg", "Error querying the alert logs")
116+
queryFailures++
104117
return
105118
}
106119
defer rows.Close()
@@ -111,9 +124,9 @@ func UpdateLog(logDestination string, logger log.Logger, db *sql.DB) {
111124
level.Error(logger).Log("msg", "Could not open log file for writing: "+logDestination)
112125
return
113126
}
114-
115127
defer outfile.Close()
116128

129+
queryFailures = 0
117130
for rows.Next() {
118131
var newRecord LogRecord
119132
if err := rows.Scan(&newRecord.Timestamp, &newRecord.ModuleId, &newRecord.ECID, &newRecord.Message); err != nil {
@@ -138,5 +151,6 @@ func UpdateLog(logDestination string, logger log.Logger, db *sql.DB) {
138151

139152
if err = rows.Err(); err != nil {
140153
level.Error(logger).Log("msg", "Error querying the alert logs")
154+
queryFailures++
141155
}
142156
}

Diff for: docker-compose/compose.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ services:
4343
start_period: 30s
4444

4545
exporter:
46-
image: container-registry.oracle.com/database/observability-exporter:1.3.0
46+
image: container-registry.oracle.com/database/observability-exporter:1.3.1
4747
container_name: exporter
4848
ports:
4949
- 9161:9161

Diff for: go.mod

+11-11
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ go 1.21
55
toolchain go1.21.4
66

77
require (
8-
github.com/BurntSushi/toml v1.3.2
8+
github.com/BurntSushi/toml v1.4.0
99
github.com/alecthomas/kingpin/v2 v2.4.0
1010
github.com/go-kit/log v0.2.1
11-
github.com/godror/godror v0.44.0
12-
github.com/oracle/oci-go-sdk/v65 v65.67.0
11+
github.com/godror/godror v0.44.1
12+
github.com/oracle/oci-go-sdk/v65 v65.69.1
1313
github.com/prometheus/client_golang v1.19.1
14-
github.com/prometheus/common v0.54.0
14+
github.com/prometheus/common v0.55.0
1515
github.com/prometheus/exporter-toolkit v0.11.0
1616
)
1717

@@ -28,17 +28,17 @@ require (
2828
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
2929
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
3030
github.com/prometheus/client_model v0.6.1 // indirect
31-
github.com/prometheus/procfs v0.12.0 // indirect
31+
github.com/prometheus/procfs v0.15.1 // indirect
3232
github.com/sony/gobreaker v0.5.0 // indirect
3333
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
34-
golang.org/x/crypto v0.22.0 // indirect
34+
golang.org/x/crypto v0.24.0 // indirect
3535
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
36-
golang.org/x/net v0.24.0 // indirect
37-
golang.org/x/oauth2 v0.19.0 // indirect
36+
golang.org/x/net v0.26.0 // indirect
37+
golang.org/x/oauth2 v0.21.0 // indirect
3838
golang.org/x/sync v0.7.0 // indirect
39-
golang.org/x/sys v0.19.0 // indirect
40-
golang.org/x/text v0.14.0 // indirect
39+
golang.org/x/sys v0.21.0 // indirect
40+
golang.org/x/text v0.16.0 // indirect
4141
google.golang.org/appengine v1.6.7 // indirect
42-
google.golang.org/protobuf v1.34.1 // indirect
42+
google.golang.org/protobuf v1.34.2 // indirect
4343
gopkg.in/yaml.v2 v2.4.0 // indirect
4444
)

Diff for: go.sum

+22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8=
22
github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
3+
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
4+
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
35
github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY=
46
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
57
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
@@ -24,6 +26,8 @@ github.com/godror/godror v0.41.1 h1:W4cLk0SOy3PYpzfRkEgdEa1TRZt2fRZTzgMP901SX80=
2426
github.com/godror/godror v0.41.1/go.mod h1:i8YtVTHUJKfFT3wTat4A9UoqScUtZXiYB9Rf3SVARgc=
2527
github.com/godror/godror v0.44.0 h1:tW0oDotJDoC5GTl5saOAwxmlozDy15ImjsbC7UVKEVA=
2628
github.com/godror/godror v0.44.0/go.mod h1:oRlxogABC1Tr5u/zYF3EjHE1fYvAeNBS9MJ8bq1hVkU=
29+
github.com/godror/godror v0.44.1 h1:jeit85/5RGu9qaMh3Oj6EqvIr6Ppl08fbUROjxf+YYs=
30+
github.com/godror/godror v0.44.1/go.mod h1:oRlxogABC1Tr5u/zYF3EjHE1fYvAeNBS9MJ8bq1hVkU=
2731
github.com/godror/knownpb v0.1.1 h1:A4J7jdx7jWBhJm18NntafzSC//iZDHkDi1+juwQ5pTI=
2832
github.com/godror/knownpb v0.1.1/go.mod h1:4nRFbQo1dDuwKnblRXDxrfCFYeT4hjg3GjMqef58eRE=
2933
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
@@ -51,6 +55,8 @@ github.com/oracle/oci-go-sdk/v65 v65.60.0 h1:r0fFFGc7PFbj9MAAJkUY/SU+IWS7HVx7Nii
5155
github.com/oracle/oci-go-sdk/v65 v65.60.0/go.mod h1:IBEV9l1qBzUpo7zgGaRUhbB05BVfcDGYRFBCPlTcPp0=
5256
github.com/oracle/oci-go-sdk/v65 v65.67.0 h1:bKcbNQyWUDiDgyE4crer3hZmiwpZ3rQnMi03jdKta/w=
5357
github.com/oracle/oci-go-sdk/v65 v65.67.0/go.mod h1:IBEV9l1qBzUpo7zgGaRUhbB05BVfcDGYRFBCPlTcPp0=
58+
github.com/oracle/oci-go-sdk/v65 v65.69.1 h1:X3vNSw9tXOxML96L3wBxrK7cwESgP/H1IgR8rTH5Ab4=
59+
github.com/oracle/oci-go-sdk/v65 v65.69.1/go.mod h1:IBEV9l1qBzUpo7zgGaRUhbB05BVfcDGYRFBCPlTcPp0=
5460
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
5561
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5662
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
@@ -71,10 +77,14 @@ github.com/prometheus/common v0.49.0 h1:ToNTdK4zSnPVJmh698mGFkDor9wBI/iGaJy5dbH1
7177
github.com/prometheus/common v0.49.0/go.mod h1:Kxm+EULxRbUkjGU6WFsQqo3ORzB4tyKvlWFOE9mB2sE=
7278
github.com/prometheus/common v0.54.0 h1:ZlZy0BgJhTwVZUn7dLOkwCZHUkrAqd3WYtcFCWnM1D8=
7379
github.com/prometheus/common v0.54.0/go.mod h1:/TQgMJP5CuVYveyT7n/0Ix8yLNNXy9yRSkhnLTHPDIQ=
80+
github.com/prometheus/common v0.55.0 h1:KEi6DK7lXW/m7Ig5i47x0vRzuBsHuvJdi5ee6Y3G1dc=
81+
github.com/prometheus/common v0.55.0/go.mod h1:2SECS4xJG1kd8XF9IcM1gMX6510RAEL65zxzNImwdc8=
7482
github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g=
7583
github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q=
7684
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
7785
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
86+
github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc=
87+
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
7888
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
7989
github.com/sony/gobreaker v0.5.0 h1:dRCvqm0P490vZPmy7ppEk2qCnCieBooFJ+YoXGYB+yg=
8090
github.com/sony/gobreaker v0.5.0/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJOjmxWY=
@@ -88,6 +98,7 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
8898
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
8999
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
90100
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
101+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
91102
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
92103
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
93104
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -97,6 +108,8 @@ golang.org/x/crypto v0.19.0 h1:ENy+Az/9Y1vSrlrvBSyna3PITt4tiZLf7sgCjZBX7Wo=
97108
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
98109
golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
99110
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
111+
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
112+
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
100113
golang.org/x/exp v0.0.0-20231127185646-65229373498e h1:Gvh4YaCaXNs6dKTlfgismwWZKyjVZXwOPfIyUaqU3No=
101114
golang.org/x/exp v0.0.0-20231127185646-65229373498e/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
102115
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM=
@@ -108,12 +121,16 @@ golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
108121
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
109122
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
110123
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
124+
golang.org/x/net v0.26.0 h1:soB7SVo0PWrY4vPW/+ay0jKDNScG2X9wFeYlXIvJsOQ=
125+
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
111126
golang.org/x/oauth2 v0.12.0 h1:smVPGxink+n1ZI5pkQa8y6fZT0RW0MgCO5bFpepy4B4=
112127
golang.org/x/oauth2 v0.12.0/go.mod h1:A74bZ3aGXgCY0qaIC9Ahg6Lglin4AMAco8cIv9baba4=
113128
golang.org/x/oauth2 v0.17.0 h1:6m3ZPmLEFdVxKKWnKq4VqZ60gutO35zm+zrAHVmHyDQ=
114129
golang.org/x/oauth2 v0.17.0/go.mod h1:OzPDGQiuQMguemayvdylqddI7qcD9lnSDb+1FiwQ5HA=
115130
golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg=
116131
golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8=
132+
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
133+
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
117134
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
118135
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
119136
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
@@ -126,10 +143,13 @@ golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
126143
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
127144
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
128145
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
146+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
147+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
129148
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
130149
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
131150
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
132151
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
152+
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
133153
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
134154
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
135155
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
@@ -142,6 +162,8 @@ google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7
142162
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
143163
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
144164
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
165+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
166+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
145167
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
146168
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
147169
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

Diff for: main.go

+17-11
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ var (
4242
maxIdleConns = kingpin.Flag("database.maxIdleConns", "Number of maximum idle connections in the connection pool. (env: DATABASE_MAXIDLECONNS)").Default(getEnv("DATABASE_MAXIDLECONNS", "0")).Int()
4343
maxOpenConns = kingpin.Flag("database.maxOpenConns", "Number of maximum open connections in the connection pool. (env: DATABASE_MAXOPENCONNS)").Default(getEnv("DATABASE_MAXOPENCONNS", "10")).Int()
4444
scrapeInterval = kingpin.Flag("scrape.interval", "Interval between each scrape. Default is to scrape on collect requests").Default("0s").Duration()
45+
logDisable = kingpin.Flag("log.disable", "Set to 1 to disable alert logs").Default("0").Int()
4546
logInterval = kingpin.Flag("log.interval", "Interval between log updates (e.g. 5s).").Default("15s").Duration()
4647
logDestination = kingpin.Flag("log.destination", "File to output the alert log to. (env: LOG_DESTINATION)").Default(getEnv("LOG_DESTINATION", "/log/alert.log")).String()
4748
toolkitFlags = webflag.AddFlags(kingpin.CommandLine, ":9161")
@@ -156,24 +157,29 @@ func main() {
156157
}
157158

158159
// start the log exporter
159-
level.Info(logger).Log("msg", "Exporting alert logs to "+*logDestination)
160-
logTicker := time.NewTicker(*logInterval)
161-
defer logTicker.Stop()
162-
163-
go func() {
164-
for {
165-
<-logTicker.C
166-
level.Debug(logger).Log("msg", "updating alert log")
167-
alertlog.UpdateLog(*logDestination, logger, exporter.GetDB())
168-
}
169-
}()
160+
if *logDisable == 1 {
161+
level.Info(logger).Log("msg", "log.disable set to 1, so will not export the alert logs")
162+
} else {
163+
level.Info(logger).Log("msg", "Exporting alert logs to "+*logDestination)
164+
logTicker := time.NewTicker(*logInterval)
165+
defer logTicker.Stop()
166+
167+
go func() {
168+
for {
169+
<-logTicker.C
170+
level.Debug(logger).Log("msg", "updating alert log")
171+
alertlog.UpdateLog(*logDestination, logger, exporter.GetDB())
172+
}
173+
}()
174+
}
170175

171176
// start the main server thread
172177
server := &http.Server{}
173178
if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil {
174179
level.Error(logger).Log("msg", "Listening error", "error", err)
175180
os.Exit(1)
176181
}
182+
177183
}
178184

179185
// getEnv returns the value of an environment variable, or returns the provided fallback value

0 commit comments

Comments
 (0)