Skip to content

Commit

Permalink
👷 Merge docker build + push step (#380)
Browse files Browse the repository at this point in the history
* 👷 Merge docker build + push step

* ✏️ Fix ide warning

* 🔖 Bump to 0.5.2

* 👷 Handle build with podman

* 🚨 Fix linter warning
  • Loading branch information
Yannig authored Nov 22, 2023
1 parent 814c959 commit 929e27b
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 89 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ jobs:
with:
ref: ${{ env.PULL_REQUEST_HEAD }}

- name: Log in to registry
if: ${{ env.FORKED == 'false' }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.REGISTRY }} -u $ --password-stdin

- name: Build image
id: docker-meta
env:
Expand All @@ -200,16 +204,6 @@ jobs:
TAG_SUFFIX=$(echo "-${{ matrix.name }}" | sed s/-ubuntu//)
echo "image-id=$IMAGE_NAME" >> $GITHUB_OUTPUT
echo "image-version=${VERSION}${TAG_SUFFIX}" >> $GITHUB_OUTPUT
- name: Log in to registry
if: ${{ env.FORKED == 'false' }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.REGISTRY }} -u $ --password-stdin

- name: Push image
if: ${{ env.FORKED == 'false' }}
env:
VERSION: "${{ needs.release.outputs.version }}"
run: |
make push-${{ matrix.name }}-image
- name: Format current time
Expand Down
15 changes: 5 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Set releasw version
- name: Set release version
id: version
run: echo "version=${{ needs.build.outputs.version }}" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -173,6 +173,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.REGISTRY }} -u $ --password-stdin

- name: Build image
id: docker-meta
env:
Expand All @@ -182,14 +185,6 @@ jobs:
TAG_SUFFIX=$(echo "-${{ matrix.name }}" | sed s/-ubuntu//)
echo "image-id=$IMAGE_NAME" >> $GITHUB_OUTPUT
echo "image-version=${VERSION}${TAG_SUFFIX}" >> $GITHUB_OUTPUT
- name: Log in to registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ${{ env.REGISTRY }} -u $ --password-stdin

- name: Push image
env:
VERSION: "${{ needs.release.outputs.version }}"
run: |
make push-${{ matrix.name }}-image
- name: Setup cosign
Expand All @@ -210,7 +205,7 @@ jobs:
run: make sign-${{ matrix.name }}-image

- name: Container scan
uses: aquasecurity/trivy-action@0.8.0
uses: aquasecurity/trivy-action@0.14.0
env:
image-ref: "${{ steps.docker-meta.outputs.image-id }}:${{ steps.docker-meta.outputs.image-version }}"
with:
Expand Down
54 changes: 32 additions & 22 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ OS_TYPE ?= $(shell uname -s | tr '[:upper:]' '[:lower:]')
ARCH_TYPE ?= $(subst x86_64,amd64,$(patsubst i%86,386,$(ARCH)))
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
VERSION ?= 0.5.1
VERSION ?= 0.5.2
LDFLAGS := -X main.Version=$(VERSION)
GOFLAGS := -ldflags "$(LDFLAGS) -s -w"
BUILD_ARGS = --build-arg VERSION=$(VERSION)
LEGACY_TABLESPACE = --build-arg LEGACY_TABLESPACE=.legacy-tablespace
OUTDIR = ./dist
LINTER_VERSION ?= v1.55.2
LINTER_IMAGE ?= docker.io/golangci/golangci-lint:$(LINTER_VERSION)

ifeq ($(shell command -v podman 2> /dev/null),)
DOCKER_CMD = docker
else
DOCKER_CMD = podman
endif

IMAGE_NAME ?= iamseth/oracledb_exporter
IMAGE_ID ?= $(IMAGE_NAME):$(VERSION)
Expand Down Expand Up @@ -64,7 +72,9 @@ go-build-windows-x86:

go-lint:
@echo "Linting codebase"
docker run --rm -v $(shell pwd):/app -v ~/.cache/golangci-lint/v1.50.1:/root/.cache -w /app golangci/golangci-lint:v1.50.1 golangci-lint run -v
mkdir -p ~/.cache/golangci-lint/$(LINTER_VERSION)
$(DOCKER_CMD) run --rm -v $$PWD:/app -v ~/.cache/golangci-lint/$(LINTER_VERSION):/root/.cache -w /app \
$(LINTER_IMAGE) golangci-lint run -v

local-build: go-build
@true
Expand All @@ -90,19 +100,19 @@ push-images:
@make --no-print-directory push-alpine-image

oraclelinux-image:
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "$(IMAGE_ID)-oraclelinux" > /dev/null; then \
if DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER_CMD) manifest inspect "$(IMAGE_ID)-oraclelinux" > /dev/null; then \
echo "Image \"$(IMAGE_ID)-oraclelinux\" already exists on ghcr.io"; \
else \
docker build --progress=plain $(BUILD_ARGS) -t "$(IMAGE_ID)-oraclelinux" --build-arg BASE_IMAGE=$(ORACLE_LINUX_BASE_IMAGE) . && \
docker build --progress=plain $(BUILD_ARGS) $(LEGACY_TABLESPACE) -t "$(IMAGE_ID)-oraclelinux_legacy-tablespace" --build-arg BASE_IMAGE=$(ORACLE_LINUX_BASE_IMAGE) . && \
docker tag "$(IMAGE_ID)-oraclelinux" "$(IMAGE_NAME):oraclelinux"; \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) -t "$(IMAGE_ID)-oraclelinux" --build-arg BASE_IMAGE=$(ORACLE_LINUX_BASE_IMAGE) . && \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) $(LEGACY_TABLESPACE) -t "$(IMAGE_ID)-oraclelinux_legacy-tablespace" --build-arg BASE_IMAGE=$(ORACLE_LINUX_BASE_IMAGE) . && \
$(DOCKER_CMD) tag "$(IMAGE_ID)-oraclelinux" "$(IMAGE_NAME):oraclelinux"; \
fi

push-oraclelinux-image:
docker push $(IMAGE_ID)-oraclelinux
$(DOCKER_CMD) push $(IMAGE_ID)-oraclelinux
ifeq ("$(RELEASE)", "true")
docker push "$(IMAGE_NAME):oraclelinux"
docker push "$(IMAGE_ID)-oraclelinux_legacy-tablespace"
$(DOCKER_CMD) push "$(IMAGE_NAME):oraclelinux"
$(DOCKER_CMD) push "$(IMAGE_ID)-oraclelinux_legacy-tablespace"
endif

sign-oraclelinux-image:
Expand All @@ -113,19 +123,19 @@ else
endif

ubuntu-image:
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "$(IMAGE_ID)" > /dev/null; then \
if DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER_CMD) manifest inspect "$(IMAGE_ID)" > /dev/null; then \
echo "Image \"$(IMAGE_ID)\" already exists on ghcr.io"; \
else \
docker build --progress=plain $(BUILD_ARGS) --build-arg BASE_IMAGE=$(UBUNTU_BASE_IMAGE) -t "$(IMAGE_ID)" . && \
docker build --progress=plain $(BUILD_ARGS) --build-arg BASE_IMAGE=$(UBUNTU_BASE_IMAGE) $(LEGACY_TABLESPACE) -t "$(IMAGE_ID)_legacy-tablespace" . && \
docker tag "$(IMAGE_ID)" "$(IMAGE_ID_LATEST)"; \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) --build-arg BASE_IMAGE=$(UBUNTU_BASE_IMAGE) -t "$(IMAGE_ID)" . && \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) --build-arg BASE_IMAGE=$(UBUNTU_BASE_IMAGE) $(LEGACY_TABLESPACE) -t "$(IMAGE_ID)_legacy-tablespace" . && \
$(DOCKER_CMD) tag "$(IMAGE_ID)" "$(IMAGE_ID_LATEST)"; \
fi

push-ubuntu-image:
docker push $(IMAGE_ID)
$(DOCKER_CMD) push $(IMAGE_ID)
ifeq ("$(RELEASE)", "true")
docker push "$(IMAGE_ID_LATEST)"
docker push "$(IMAGE_ID)_legacy-tablespace"
$(DOCKER_CMD) push "$(IMAGE_ID_LATEST)"
$(DOCKER_CMD) push "$(IMAGE_ID)_legacy-tablespace"
endif

sign-ubuntu-image:
Expand All @@ -137,18 +147,18 @@ else
endif

alpine-image:
if DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect "$(IMAGE_ID)-alpine" > /dev/null; then \
if DOCKER_CLI_EXPERIMENTAL=enabled $(DOCKER_CMD) manifest inspect "$(IMAGE_ID)-alpine" > /dev/null; then \
echo "Image \"$(IMAGE_ID)-alpine\" already exists on ghcr.io"; \
else \
docker build --progress=plain $(BUILD_ARGS) -t "$(IMAGE_ID)-alpine" --build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) . && \
docker build --progress=plain $(BUILD_ARGS) $(LEGACY_TABLESPACE) --build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) -t "$(IMAGE_ID)-alpine_legacy-tablespace" . && \
docker tag "$(IMAGE_ID)-alpine" "$(IMAGE_NAME):alpine"; \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) -t "$(IMAGE_ID)-alpine" --build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) . && \
$(DOCKER_CMD) build --progress=plain $(BUILD_ARGS) $(LEGACY_TABLESPACE) --build-arg BASE_IMAGE=$(ALPINE_BASE_IMAGE) -t "$(IMAGE_ID)-alpine_legacy-tablespace" . && \
$(DOCKER_CMD) tag "$(IMAGE_ID)-alpine" "$(IMAGE_NAME):alpine"; \
fi

push-alpine-image:
docker push $(IMAGE_ID)-alpine
$(DOCKER_CMD) push $(IMAGE_ID)-alpine
ifeq ("$(RELEASE)", "true")
docker push "$(IMAGE_NAME):alpine"
$(DOCKER_CMD) push "$(IMAGE_NAME):alpine"
endif

sign-alpine-image:
Expand Down
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[Troubleshooting](#troubleshooting)
[Operating principles](operating-principles.md)

# Description
## Description

A [Prometheus](https://prometheus.io/) exporter for Oracle modeled after the MySQL exporter. I'm not a DBA or seasoned Go developer so PRs definitely welcomed.

Expand Down Expand Up @@ -45,11 +45,11 @@ The following metrics are exposed currently.
- oracledb_resource_current_utilization
- oracledb_resource_limit_value

# Installation
## Installation

## Docker
### Docker / Podman

You can run via Docker using an existing image. Since version 0.4, the images are available on the github registry.
You can run via Docker/Podman using an existing image. Since version 0.4, the images are available on the github registry.

Here an example to retrieve the version 0.5.0:

Expand Down Expand Up @@ -94,14 +94,14 @@ Manager. See https://github.com/iamseth/oracledb_exporter/issues/153 for
details. The versions above should have a more useful tablespace utilization
calculation going forward.

## Binary Release
### Binary Release

Pre-compiled versions for Linux 64 bit and Mac OSX 64 bit can be found under [releases](https://github.com/iamseth/oracledb_exporter/releases).

In order to run, you'll need the [Oracle Instant Client Basic](http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html)
for your operating system. Only the basic version is required for execution.

## Running
#### Running
Ensure that the environment variable DATA_SOURCE_NAME is set correctly before starting.
DATA_SOURCE_NAME should be in Oracle Database connection string format:

Expand Down Expand Up @@ -154,7 +154,7 @@ v$session
v$resource_limit
```

# Integration with System D
#### Integration with System D

Create `oracledb_exporter` user with disabled login and `oracledb_exporter` group then run the following commands:

Expand Down Expand Up @@ -222,12 +222,12 @@ Usage of oracledb_exporter:
Path to configuration file that can enable TLS or authentication.
```

# Default metrics
## Default metrics

This exporter comes with a set of default metrics defined in **default-metrics.toml**. You can modify this file or
provide a different one using `default.metrics` option.

# Custom metrics
### Custom metrics

> NOTE: Do not put a `;` at the end of your SQL queries as this will **NOT** work.
Expand Down Expand Up @@ -331,7 +331,7 @@ COPY custom-metrics.toml /
ENTRYPOINT ["/oracledb_exporter", "--custom.metrics", "/custom-metrics.toml"]
```

# Using a multiple host data source name
## Using a multiple host data source name

> NOTE: This has been tested with v0.2.6a and will most probably work on versions above.
Expand Down Expand Up @@ -369,7 +369,7 @@ database =
- `TNS_ADMIN`: Path you choose for the tns admin folder (`/path/to/tns_admin` in the example file above)
- `DATA_SOURCE_NAME`: Datasource pointing to the `TNS_ENTRY` (`user:password@database` in the example file above)

# TLS connection to database
## TLS connection to database

First, set the following variables:

Expand Down Expand Up @@ -400,13 +400,13 @@ Here a complete example of string connection:

For more details, have a look at the following location: https://github.com/iamseth/oracledb_exporter/issues/84

# Integration with Grafana
## Integration with Grafana

An example Grafana dashboard is available [here](https://grafana.com/grafana/dashboards/3333-oracledb/).

# Build
## Build

## Docker build
### Docker/Podman build

To build Ubuntu and Alpine image, run the following command:

Expand All @@ -420,7 +420,7 @@ Or Alpine:

make alpine-image

## Building Binaries
### Building Binaries

Run build:

Expand Down Expand Up @@ -472,9 +472,9 @@ Here is a small snippet of an example usage of the exporter in code:

```

# FAQ/Troubleshooting
## FAQ/Troubleshooting

## Unable to convert current value to float (metric=par,metri...in.go:285
### Unable to convert current value to float (metric=par,metri...in.go:285

Oracle is trying to send a value that we cannot convert to float. This could be anything like 'UNLIMITED' or 'UNDEFINED' or 'WHATEVER'.

Expand All @@ -492,11 +492,11 @@ If the value of limite_value is 'UNLIMITED', the request send back the value -1.

You can increase the log level (`--log.level debug`) in order to get the statement generating this error.

## error while loading shared libraries: libclntsh.so.xx.x: cannot open shared object file: No such file or directory
### error while loading shared libraries: libclntsh.so.xx.x: cannot open shared object file: No such file or directory

Version before 0.5 use libs from Oracle in order to connect to Oracle Database. After 0.5 release, the oracle exporter use an pure Go DB driver and don't need binaries from Oracle anymore.

Please switch to version 0.5.
**Please switch to version 0.5.**

For older version, you must install the Oracle binaries somewhere on your machine and **you must install the good version number**. If the
error talk about the version 18.3, you **must** install 18.3 binary version. If it's 12.2, you **must** install 12.2.
Expand All @@ -508,7 +508,7 @@ Here an example to run this exporter (to scrap metrics from system/oracle@//host

`docker run -it --rm -p 9161:9161 -e DATA_SOURCE_NAME=oracle://system/oracle@//host:1521/service-or-sid iamseth/oracledb_exporter:0.2.6a`

## Error scraping for wait_time
### Error scraping for wait_time

If you experience an error `Error scraping for wait_time: sql: Scan error on column index 1: converting driver.Value type string (",01") to a float64: invalid syntax source="main.go:144"` you may need to set the NLS_LANG variable.

Expand All @@ -521,7 +521,7 @@ export DATA_SOURCE_NAME=system/oracle@myhost

If using Docker, set the same variable using the -e flag.

## An Oracle instance generates a lot of trace files being monitored by exporter
### An Oracle instance generates a lot of trace files being monitored by exporter

As being said, Oracle instance may (and probably does) generate a lot of trace files alongside its alert log file, one trace file per scraping event. The trace file contains the following lines

Expand All @@ -539,7 +539,7 @@ The root cause is Oracle's reaction of quering ASM-related views without ASM use
$ find $ORACLE_BASE/diag/rdbms -name '*.tr[cm]' -mtime +14 -delete
```

## TLS and basic authentication
### TLS and basic authentication

Apache Exporter supports TLS and basic authentication. This enables better
control of the various HTTP endpoints.
Expand All @@ -552,7 +552,7 @@ Note that the TLS and basic authentication settings affect all HTTP endpoints:
/metrics for scraping, /probe for probing, and the web UI.


## Multi-target support
### Multi-target support

This exporter supports the multi-target pattern. This allows running a single instance of this exporter for multiple Oracle targets.

Expand Down
Loading

0 comments on commit 929e27b

Please sign in to comment.