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

Commit

Permalink
refact: refact debug level logs; bump ununtu image to 20.04; switch t…
Browse files Browse the repository at this point in the history
…o non-root ubuntu container (#204)

Refact debug level logs
Bump ubuntu image to 20.04
Switch to non-root ubuntu container
  • Loading branch information
vutkin authored Sep 21, 2021
1 parent 94b8778 commit c4743d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,36 @@ ENV GOOS linux

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

FROM ubuntu:18.04
FROM ubuntu:20.04
LABEL authors="Seth Miller,Yannig Perré"
LABEL maintainer="Yannig Perré <[email protected]>"

ENV VERSION ${VERSION:-0.1.0}
ENV DEBIAN_FRONTEND=noninteractive

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

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

RUN adduser --system --uid 1000 --group appuser \
&& usermod -a -G 0,appuser appuser

ARG ORACLE_VERSION
ENV ORACLE_VERSION=${ORACLE_VERSION}
ENV LD_LIBRARY_PATH "/usr/lib/oracle/${ORACLE_VERSION}/client64/lib"
RUN echo $LD_LIBRARY_PATH >> /etc/ld.so.conf.d/oracle.conf && ldconfig

ARG LEGACY_TABLESPACE
ENV LEGACY_TABLESPACE=${LEGACY_TABLESPACE}
COPY --from=build /go/src/oracledb_exporter/oracledb_exporter /oracledb_exporter
COPY --chown=appuser:appuser --from=build /go/src/oracledb_exporter/oracledb_exporter /oracledb_exporter
ADD ./default-metrics${LEGACY_TABLESPACE}.toml /default-metrics.toml

ENV DATA_SOURCE_NAME system/oracle@oracle/xe

RUN chmod 755 /oracledb_exporter

EXPOSE 9161

ENTRYPOINT ["/oracledb_exporter"]
USER appuser

ENTRYPOINT ["/oracledb_exporter"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VERSION ?= 0.3.0
ORACLE_VERSION ?= 18.5
VERSION ?= 0.3.2
ORACLE_VERSION ?= 19.10
LDFLAGS := -X main.Version=$(VERSION)
GOFLAGS := -ldflags "$(LDFLAGS) -s -w"
ARCH ?= $(shell uname -m)
GOARCH ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(ARCH)))
RPM_VERSION ?= $(ORACLE_VERSION).0.0.0-3
RPM_VERSION ?= $(ORACLE_VERSION).0.0.0-1
ORA_RPM = oracle-instantclient$(ORACLE_VERSION)-devel-$(RPM_VERSION).$(ARCH).rpm oracle-instantclient$(ORACLE_VERSION)-basic-$(RPM_VERSION).$(ARCH).rpm
LD_LIBRARY_PATH = /usr/lib/oracle/$(ORACLE_VERSION)/client64/lib
BUILD_ARGS = --build-arg VERSION=$(VERSION) --build-arg ORACLE_VERSION=$(ORACLE_VERSION)
Expand Down
18 changes: 14 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,17 @@ func atoi(stringValue string) int {
return intValue
}

func maskDsn(dsn string) string {
parts := strings.Split(dsn, "@")
if len(parts) > 1 {
maskedUrl := "***@" + parts[1]
return maskedUrl
}
return dsn
}

func connect(dsn string) *sql.DB {
log.Debugln("Launching connection: ", dsn)
log.Debugln("Launching connection: ", maskDsn(dsn))
db, err := sql.Open("oci8", dsn)
if err != nil {
log.Errorln("Error while connecting to", dsn)
Expand All @@ -112,7 +121,7 @@ func connect(dsn string) *sql.DB {
db.SetMaxIdleConns(*maxIdleConns)
log.Debugln("set max open connections to ", *maxOpenConns)
db.SetMaxOpenConns(*maxOpenConns)
log.Debugln("Successfully connected to: ", dsn)
log.Debugln("Successfully connected to: ", maskDsn(dsn))
return db
}

Expand Down Expand Up @@ -217,7 +226,7 @@ func (e *Exporter) scrape(ch chan<- prometheus.Metric) {
e.up.Set(0)
return
} else {
log.Debugln("Successfully pinged Oracle database: ")
log.Debugln("Successfully pinged Oracle database: ", maskDsn(e.dsn))
e.up.Set(1)
}

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

scrapeStart := time.Now()
if err = ScrapeMetric(e.db, ch, metric); err != nil {
log.Errorln("Error scraping for", metric.Context, "_", metric.MetricsDesc, ":", err)
log.Errorln("Error scraping for", metric.Context, "_", metric.MetricsDesc, time.Since(scrapeStart), ":", err)
e.scrapeErrors.WithLabelValues(metric.Context).Inc()
} else {
log.Debugln("Successfully scraped metric: ", metric.Context, metric.MetricsDesc, time.Since(scrapeStart))
Expand Down Expand Up @@ -396,6 +405,7 @@ func ScrapeGenericValues(db *sql.DB, ch chan<- prometheus.Metric, context string
}
return nil
}
log.Debugln("Calling function GeneratePrometheusMetrics()")
err := GeneratePrometheusMetrics(db, genericParser, request)
log.Debugln("ScrapeGenericValues() - metricsCount: ", metricsCount)
if err != nil {
Expand Down

0 comments on commit c4743d6

Please sign in to comment.