Skip to content

Add extra admin roles #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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 ?= 1.5.3
VERSION ?= 1.5.4
LDFLAGS := -X main.Version=$(VERSION)
GOFLAGS := -ldflags "$(LDFLAGS) -s -w"
BUILD_ARGS = --build-arg VERSION=$(VERSION)
Expand Down
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,31 @@ Contributions are welcome - please see [contributing](CONTRIBUTING.md).

## Release Notes

### Version 1.5.4, February 27, 2025

Our current priorities are support for RAC and mutliple databases (inculding #84 and #89), and intermittent connection issues
with ADB-S when exporter is run in a container (including #169). We expect to address these in an upcoming release.

- Fix malloc error (#177)
- Add support for additional admin roles, exapnding list of options for `DB_ROILE` to `SYSDBA`, `SYSOPER`, `SYSBACKUP`, `SYSDG`, `SYSKM`, `SYSRAC` and `SYSASM` (#180)
- Updated some third-party dependencies.

Thank you to the following people for their suggestions and contributions:

- [@Jman1993](https://github.com/Jman1993)
- [@oey](https://github.com/oey)
- [@jlembeck06](https://github.com/jlembeck06)
- [@Jman1993](https://github.com/Jman1993)
- [@PeterP55P](https://github.com/PeterP55P)
- [@rlagyu0](https://github.com/rlagyu0)

In this release, we also continued some minor code refactoring.

### Version 1.5.3, January 28, 2025

*Known issue*: This release has a known issue that results in the error message `malloc(): unsorted double linked list corrupted`.
We recommend staying on 1.5.2 until a new release with a fix is available. We hope to have a fix by early March.

Our current priorities are support for RAC and mutliple databases (inculding #84 and #89), and intermittent connection issues
with ADB-S when exporter is run in a container (including #169). We expect to address these in an upcoming release.

Expand Down Expand Up @@ -496,7 +519,7 @@ For a simple connection, you will provide the details using these variables:
- `DB_USERNAME` is the database username, e.g., `pdbadmin`
- `DB_PASSWORD` is the password for that user, e.g., `Welcome12345`
- `DB_CONNECT_STRING` is the connection string, e.g., `free23ai:1521/freepdb`
- `DB_ROLE` (Optional) can be set to `SYSDBA` or `SYSOPER` if you want to connect with one of those roles, however Oracle recommends that you connect with the lowest possible privileges and roles necessary for the exporter to run.
- `DB_ROLE` (Optional) can be set to `SYSDBA`, `SYSOPER`, `SYSBACKUP`, `SYSDG`, `SYSKM`, `SYSRAC` or `SYSASM` if you want to connect with one of those roles, however Oracle recommends that you connect with the lowest possible privileges and roles necessary for the exporter to run.

To run the exporter in a container and expose the port, use a command like this, with the appropriate values for the environment variables:

Expand All @@ -506,7 +529,7 @@ docker run -it --rm \
-e DB_PASSWORD=Welcome12345 \
-e DB_CONNECT_STRING=free23ai:1521/freepdb \
-p 9161:9161 \
container-registry.oracle.com/database/observability-exporter:1.5.3
container-registry.oracle.com/database/observability-exporter:1.5.4
```

##### Using a wallet
Expand Down Expand Up @@ -552,7 +575,7 @@ docker run -it --rm \
-e DB_CONNECT_STRING=devdb_tp \
-v ./wallet:/wallet \
-p 9161:9161 \
container-registry.oracle.com/database/observability-exporter:1.5.3
container-registry.oracle.com/database/observability-exporter:1.5.4
```
> **Note:** If you are using `podman` you must specify the `:z` suffix on the volume mount so that the container will be able to access the files in the volume. For example: `-v ./wallet:/wallet:z`

Expand Down Expand Up @@ -842,7 +865,7 @@ An exmaple of [custom metrics for Transacational Event Queues](./custom-metrics-
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:

```Dockerfile
FROM container-registry.oracle.com/database/observability-exporter:1.5.3
FROM container-registry.oracle.com/database/observability-exporter:1.5.4
COPY custom-metrics.toml /
ENTRYPOINT ["/oracledb_exporter", "--custom.metrics", "/custom-metrics.toml"]
```
Expand Down
26 changes: 19 additions & 7 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/godror/godror"
"github.com/godror/godror/dsn"
"github.com/prometheus/client_golang/prometheus"
)

Expand Down Expand Up @@ -54,7 +55,7 @@ type Config struct {
User string
Password string
ConnectString string
DbRole string
DbRole dsn.AdminRole
ConfigDir string
ExternalAuth bool
MaxIdleConns int
Expand Down Expand Up @@ -401,12 +402,23 @@ func (e *Exporter) connect() error {
// if TNS_ADMIN env var is set, set ConfigDir to that location
P.ConfigDir = e.configDir

if strings.ToUpper(e.config.DbRole) == "SYSDBA" {
P.IsSysDBA = true
}

if strings.ToUpper(e.config.DbRole) == "SYSOPER" {
P.IsSysOper = true
switch e.config.DbRole {
case "SYSDBA":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is purely a style recommendation:

  1. Create a new type for this rather than using string literals
  2. switch on the new type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also segregate database role handling code to it's own function/file. gonna suggest database_role.go

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated to use the AdminRole type from godror, which handles parsing the string, deals with unknown values correctly, etc.

P.AdminRole = dsn.SysDBA
case "SYSOPER":
P.AdminRole = dsn.SysOPER
case "SYSBACKUP":
P.AdminRole = dsn.SysBACKUP
case "SYSDG":
P.AdminRole = dsn.SysDG
case "SYSKM":
P.AdminRole = dsn.SysKM
case "SYSRAC":
P.AdminRole = dsn.SysRAC
case "SYSASM":
P.AdminRole = dsn.SysASM
default:
P.AdminRole = dsn.NoRole
}

level.Debug(e.logger).Log("msg", "connection properties: "+fmt.Sprint(P))
Expand Down
2 changes: 1 addition & 1 deletion docker-compose/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ services:
start_period: 30s

exporter:
image: container-registry.oracle.com/database/observability-exporter:1.5.3
image: container-registry.oracle.com/database/observability-exporter:1.5.4
container_name: exporter
ports:
- 9161:9161
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/BurntSushi/toml v1.4.0
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/go-kit/log v0.2.1
github.com/godror/godror v0.46.0
github.com/godror/godror v0.46.1-0.20250226074503-67aeda640090
github.com/oracle/oci-go-sdk/v65 v65.81.1
github.com/prometheus/client_golang v1.20.5
github.com/prometheus/common v0.60.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/godror/godror v0.45.2 h1:rkXxmD+/QdKz0PTOuSfEmWNFCHnKpWS8b8HUl+5V7us=
github.com/godror/godror v0.45.2/go.mod h1:44hxVDzvFSwc+yGyRM+riCLNAY5SwZkUfLzVTh5MXCg=
github.com/godror/godror v0.46.0 h1:/43db84UcoxlooASIsasH8TvZ7E1huwJ64yDtZ2504k=
github.com/godror/godror v0.46.0/go.mod h1:44hxVDzvFSwc+yGyRM+riCLNAY5SwZkUfLzVTh5MXCg=
github.com/godror/godror v0.46.1-0.20250226074503-67aeda640090 h1:9/ZPRz24+4QrrU/xB0I+AAXKzLV2xtG+mn+9zb3cQCg=
github.com/godror/godror v0.46.1-0.20250226074503-67aeda640090/go.mod h1:44hxVDzvFSwc+yGyRM+riCLNAY5SwZkUfLzVTh5MXCg=
github.com/godror/knownpb v0.1.2 h1:icMyYsYVpGmzhoVA01xyd0o4EaubR31JPK1UxQWe4kM=
github.com/godror/knownpb v0.1.2/go.mod h1:zs9hH+lwj7mnPHPnKCcxdOGz38Axa9uT+97Ng+Nnu5s=
github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw=
Expand Down
2 changes: 1 addition & 1 deletion kubernetes/metrics-exporter-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ spec:
spec:
containers:
- name: metrics-exporter
image: container-registry.oracle.com/database/observability-exporter:1.5.3
image: container-registry.oracle.com/database/observability-exporter:1.5.4
imagePullPolicy: Always
env:
# uncomment and customize the next item if you want to provide custom metrics definitions
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/go-kit/log/level"
"github.com/godror/godror/dsn"
"github.com/prometheus/client_golang/prometheus"
cversion "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/client_golang/prometheus/promhttp"
Expand Down Expand Up @@ -87,9 +88,9 @@ func main() {
User: user,
Password: password,
ConnectString: connectString,
DbRole: dbrole,
DbRole: dsn.AdminRole(dbrole),
ConfigDir: tnsadmin,
ExternalAuth: externalAuth,
ExternalAuth: externalAuth,
MaxOpenConns: *maxOpenConns,
MaxIdleConns: *maxIdleConns,
CustomMetrics: *customMetrics,
Expand Down