Skip to content

Commit

Permalink
feat: Rebase on upstream v0.14.0
Browse files Browse the repository at this point in the history
Update go-vault-client
  • Loading branch information
alessio-form3 committed Oct 10, 2023
1 parent 56e9669 commit 939262e
Show file tree
Hide file tree
Showing 5,024 changed files with 551 additions and 1,896,277 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
103 changes: 0 additions & 103 deletions .circleci/config.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI
on:
push:
branches:
- master
tags:
- '**'
pull_request:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- name: Setup Golang
uses: actions/setup-go@4d34df0c2316fe8122ab82dc22947d607c0c91f9 # v4.0.0
with:
go-version-file: go.mod
- name: Test
run: make test
publish:
if: startsWith(github.ref, 'refs/tags')
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0
- name: Publish
run: make publish
env:
DOCKER_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
DOCKER_TAG: ${{ github.ref_name }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
/.metrics.*.added
/.metrics.*.removed
/tools/src
/vendor
/assets
23 changes: 0 additions & 23 deletions .golangci.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ go:
# This must match .circle/config.yml.
version: 1.20
repository:
path: github.com/prometheus-community/postgres_exporter
path: github.com/form3tech-oss/postgres_exporter
build:
binaries:
- name: postgres_exporter
Expand Down
37 changes: 0 additions & 37 deletions .travis.yml

This file was deleted.

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
all::

# Needs to be defined before including Makefile.common to auto-generate targets
DOCKER_ARCHS ?= amd64 armv7 arm64 ppc64le
DOCKER_REPO ?= prometheuscommunity
DOCKER_ARCHS ?= amd64 arm64
DOCKER_REPO ?= form3tech

include Makefile.common

DOCKER_IMAGE_NAME ?= postgres-exporter
DOCKER_IMAGE_NAME ?= postgres-exporter
59 changes: 59 additions & 0 deletions cmd/postgres_exporter/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"regexp"
"strings"

"github.com/form3tech-oss/go-vault-client/v4/pkg/vaultclient"
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"
)
Expand Down Expand Up @@ -149,6 +150,21 @@ func getDataSources() ([]string, error) {
pass = os.Getenv("DATA_SOURCE_PASS")
}

if len(user) == 0 || len(pass) == 0 {
secrets, err := loadSecrets()
if err != nil {
panic(err)
}

if len(user) == 0 {
user = secrets["database-username"].(string)
}

if len(pass) == 0 {
pass = secrets["database-password"].(string)
}
}

ui := url.UserPassword(user, pass).String()
dataSrouceURIFile := os.Getenv("DATA_SOURCE_URI_FILE")
if len(dataSrouceURIFile) != 0 {
Expand All @@ -171,3 +187,46 @@ func getDataSources() ([]string, error) {

return []string{dsn}, nil
}

func loadSecrets() (map[string]interface{}, error) {
result := make(map[string]interface{})
vaultAuth, err := vaultclient.NewVaultAuth(vaultclient.NewDefaultConfig())
if err != nil {
return nil, err
}

client, err := vaultAuth.VaultClient()
if err != nil {
return nil, err
}

secret, err := client.Logical().Read("/secret/application")
if err == nil {
for key, value := range secret.Data {
result[key] = value
}
} else {
level.Warn(logger).Log("error reading vault secrets from /secret/application", err)
}

secret, err = client.Logical().Read("/secret/postgres_exporter")
if err == nil && secret != nil {
for key, value := range secret.Data {
result[key] = value
}
} else {
level.Warn(logger).Log("error reading vault secrets from /secret/postgres_exporter", err)
}

dbCredsPath := os.Getenv("VAULT_DB_CREDENTIALS_PATH")
secret, err = client.Logical().Read(dbCredsPath)
if err == nil {
for key, value := range secret.Data {
result[key] = value
}
} else {
level.Warn(logger).Log("error reading vault secrets from "+dbCredsPath, err)
}

return result, nil
}
4 changes: 2 additions & 2 deletions cmd/postgres_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import (
"strings"

"github.com/alecthomas/kingpin/v2"
"github.com/form3tech-oss/postgres_exporter/collector"
"github.com/form3tech-oss/postgres_exporter/config"
"github.com/go-kit/log"
"github.com/go-kit/log/level"
"github.com/prometheus-community/postgres_exporter/collector"
"github.com/prometheus-community/postgres_exporter/config"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/promlog"
Expand Down
2 changes: 1 addition & 1 deletion cmd/postgres_exporter/pg_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *pgSetting) normaliseUnit() (val float64, unit string, err error) {
case "B", "kB", "MB", "GB", "TB", "4kB", "8kB", "16kB", "32kB", "64kB", "16MB", "32MB", "64MB":
unit = "bytes"
default:
err = fmt.Errorf("Unknown unit for runtime variable: %q", s.unit)
err = fmt.Errorf("unknown unit for runtime variable: %q", s.unit)
return
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/postgres_exporter/pg_setting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ var fixtures = []fixture{
n: normalised{
val: 10,
unit: "",
err: `Unknown unit for runtime variable: "nonexistent"`,
err: `unknown unit for runtime variable: "nonexistent"`,
},
},
}
Expand All @@ -240,7 +240,7 @@ func (s *PgSettingSuite) TestNormaliseUnit(c *C) {
func (s *PgSettingSuite) TestMetric(c *C) {
defer func() {
if r := recover(); r != nil {
if r.(error).Error() != `Unknown unit for runtime variable: "nonexistent"` {
if r.(error).Error() != `unknown unit for runtime variable: "nonexistent"` {
panic(r)
}
}
Expand Down
Loading

0 comments on commit 939262e

Please sign in to comment.