Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit c4743d6

Browse files
authored
refact: refact debug level logs; bump ununtu image to 20.04; switch to non-root ubuntu container (#204)
Refact debug level logs Bump ubuntu image to 20.04 Switch to non-root ubuntu container
1 parent 94b8778 commit c4743d6

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

Dockerfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,32 +23,36 @@ ENV GOOS linux
2323

2424
RUN go build -v -ldflags "-X main.Version=${VERSION} -s -w"
2525

26-
FROM ubuntu:18.04
26+
FROM ubuntu:20.04
2727
LABEL authors="Seth Miller,Yannig Perré"
2828
LABEL maintainer="Yannig Perré <[email protected]>"
2929

3030
ENV VERSION ${VERSION:-0.1.0}
31+
ENV DEBIAN_FRONTEND=noninteractive
3132

3233
COPY oracle-instantclient*${ORACLE_VERSION}*basic*.rpm /
3334

3435
RUN apt-get -qq update && \
35-
apt-get -qq install --no-install-recommends -qq libaio1 rpm -y && rpm -Uvh --nodeps /oracle*${ORACLE_VERSION}*rpm && \
36+
apt-get -qq install --no-install-recommends tzdata libaio1 rpm -y && rpm -Uvh --nodeps /oracle*${ORACLE_VERSION}*rpm && \
3637
rm -f /oracle*rpm
3738

39+
RUN adduser --system --uid 1000 --group appuser \
40+
&& usermod -a -G 0,appuser appuser
41+
3842
ARG ORACLE_VERSION
3943
ENV ORACLE_VERSION=${ORACLE_VERSION}
4044
ENV LD_LIBRARY_PATH "/usr/lib/oracle/${ORACLE_VERSION}/client64/lib"
4145
RUN echo $LD_LIBRARY_PATH >> /etc/ld.so.conf.d/oracle.conf && ldconfig
4246

4347
ARG LEGACY_TABLESPACE
4448
ENV LEGACY_TABLESPACE=${LEGACY_TABLESPACE}
45-
COPY --from=build /go/src/oracledb_exporter/oracledb_exporter /oracledb_exporter
49+
COPY --chown=appuser:appuser --from=build /go/src/oracledb_exporter/oracledb_exporter /oracledb_exporter
4650
ADD ./default-metrics${LEGACY_TABLESPACE}.toml /default-metrics.toml
4751

4852
ENV DATA_SOURCE_NAME system/oracle@oracle/xe
4953

50-
RUN chmod 755 /oracledb_exporter
51-
5254
EXPOSE 9161
5355

54-
ENTRYPOINT ["/oracledb_exporter"]
56+
USER appuser
57+
58+
ENTRYPOINT ["/oracledb_exporter"]

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
VERSION ?= 0.3.0
2-
ORACLE_VERSION ?= 18.5
1+
VERSION ?= 0.3.2
2+
ORACLE_VERSION ?= 19.10
33
LDFLAGS := -X main.Version=$(VERSION)
44
GOFLAGS := -ldflags "$(LDFLAGS) -s -w"
55
ARCH ?= $(shell uname -m)
66
GOARCH ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(ARCH)))
7-
RPM_VERSION ?= $(ORACLE_VERSION).0.0.0-3
7+
RPM_VERSION ?= $(ORACLE_VERSION).0.0.0-1
88
ORA_RPM = oracle-instantclient$(ORACLE_VERSION)-devel-$(RPM_VERSION).$(ARCH).rpm oracle-instantclient$(ORACLE_VERSION)-basic-$(RPM_VERSION).$(ARCH).rpm
99
LD_LIBRARY_PATH = /usr/lib/oracle/$(ORACLE_VERSION)/client64/lib
1010
BUILD_ARGS = --build-arg VERSION=$(VERSION) --build-arg ORACLE_VERSION=$(ORACLE_VERSION)

main.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,17 @@ func atoi(stringValue string) int {
101101
return intValue
102102
}
103103

104+
func maskDsn(dsn string) string {
105+
parts := strings.Split(dsn, "@")
106+
if len(parts) > 1 {
107+
maskedUrl := "***@" + parts[1]
108+
return maskedUrl
109+
}
110+
return dsn
111+
}
112+
104113
func connect(dsn string) *sql.DB {
105-
log.Debugln("Launching connection: ", dsn)
114+
log.Debugln("Launching connection: ", maskDsn(dsn))
106115
db, err := sql.Open("oci8", dsn)
107116
if err != nil {
108117
log.Errorln("Error while connecting to", dsn)
@@ -112,7 +121,7 @@ func connect(dsn string) *sql.DB {
112121
db.SetMaxIdleConns(*maxIdleConns)
113122
log.Debugln("set max open connections to ", *maxOpenConns)
114123
db.SetMaxOpenConns(*maxOpenConns)
115-
log.Debugln("Successfully connected to: ", dsn)
124+
log.Debugln("Successfully connected to: ", maskDsn(dsn))
116125
return db
117126
}
118127

@@ -217,7 +226,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
217226
e.up.Set(0)
218227
return
219228
} else {
220-
log.Debugln("Successfully pinged Oracle database: ")
229+
log.Debugln("Successfully pinged Oracle database: ", maskDsn(e.dsn))
221230
e.up.Set(1)
222231
}
223232

@@ -266,7 +275,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
266275

267276
scrapeStart := time.Now()
268277
if err = ScrapeMetric(e.db, ch, metric); err != nil {
269-
log.Errorln("Error scraping for", metric.Context, "_", metric.MetricsDesc, ":", err)
278+
log.Errorln("Error scraping for", metric.Context, "_", metric.MetricsDesc, time.Since(scrapeStart), ":", err)
270279
e.scrapeErrors.WithLabelValues(metric.Context).Inc()
271280
} else {
272281
log.Debugln("Successfully scraped metric: ", metric.Context, metric.MetricsDesc, time.Since(scrapeStart))
@@ -396,6 +405,7 @@ func ScrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric, context string
396405
}
397406
return nil
398407
}
408+
log.Debugln("Calling function GeneratePrometheusMetrics()")
399409
err := GeneratePrometheusMetrics(db, genericParser, request)
400410
log.Debugln("ScrapeGenericValues() - metricsCount: ", metricsCount)
401411
if err != nil {

0 commit comments

Comments
 (0)