Skip to content
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

PMM-7806: add compatibility with percona pg exporter #68

Merged
merged 19 commits into from
Sep 6, 2022
Merged
90 changes: 0 additions & 90 deletions .circleci/config.yml

This file was deleted.

47 changes: 0 additions & 47 deletions .github/ISSUE_TEMPLATE/bug_report.md

This file was deleted.

5 changes: 0 additions & 5 deletions .github/ISSUE_TEMPLATE/config.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/ISSUE_TEMPLATE/feature_request.md

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Go

on:
push:
branches:
- main
tags:
- v[0-9]+.[0-9]+.[0-9]+*
pull_request:

jobs:
test:
name: Test
strategy:
matrix:
go-version:
- 1.17
postgresql-image:
- postgres:10
- postgres:11
- postgres:12
- postgres:13
- postgres:14
runs-on: ubuntu-latest
# The environment this job references
environment:
name: CI
steps:
- name: Set up Go release
uses: percona-platform/setup-go@v2
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: percona-platform/checkout@v2
- name: Run checks
run: |
go build -modfile=tools/go.mod -o bin/golangci-lint github.com/golangci/golangci-lint/cmd/golangci-lint
go build -modfile=tools/go.mod -o bin/reviewdog github.com/reviewdog/reviewdog/cmd/reviewdog
bin/golangci-lint run -c=.golangci-required.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-check
bin/golangci-lint run -c=.golangci.yml --out-format=line-number | env REVIEWDOG_GITHUB_API_TOKEN=${{ secrets.GITHUB_TOKEN }} bin/reviewdog -f=golangci-lint -level=error -reporter=github-pr-review
Comment on lines +35 to +40
Copy link
Member

Choose a reason for hiding this comment

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

can we extract running checks to a separate job?

Copy link
Author

Choose a reason for hiding this comment

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

I took it from the original, exporter. We can think about some generic actions in scope of other task and PR, what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

could you create a task for it then, please?

Copy link
Author

Choose a reason for hiding this comment

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

Can you please clarify what exactly this ticket should be about? Create shared GHA for checks (ie linters)?

Copy link
Member

Choose a reason for hiding this comment

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

extracting checks to a separate job.

- name: Run Tests
run: |
sudo chown 999:999 testdata/ssl/server/*
sudo chmod 600 testdata/ssl/server/*
docker-compose up -d
make
make test
env:
POSTGRESQL_IMAGE: ${{ matrix.postgresql-image }}
- name: Run debug commands on failure
if: ${{ failure() }}
run: |
env
go version
go env
pwd
git status
docker --version
docker-compose --version
docker-compose logs
22 changes: 1 addition & 21 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ endif
%: common-% ;

.PHONY: common-all
common-all: precheck style check_license lint yamllint unused build test

Choose a reason for hiding this comment

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

Why we removed these two targets?

Copy link
Author

Choose a reason for hiding this comment

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

in original exporter we don't have license headers, and I moved yaml as is.

Copy link
Member

Choose a reason for hiding this comment

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

Did you check if this target was removed explicitly or if it was introduced later by upstream?
What do you mean by moving YAML as is? If we have something failing in our YAML then it's better to fix them.

Copy link
Author

Choose a reason for hiding this comment

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

I moved configs from "old" pg exporter. It is a diff for upstream.

common-all: precheck style lint unused build test

.PHONY: common-style
common-style:
Expand All @@ -136,17 +136,6 @@ common-style:
exit 1; \
fi

.PHONY: common-check_license
common-check_license:
@echo ">> checking license header"
@licRes=$$(for file in $$(find . -type f -iname '*.go' ! -path './vendor/*') ; do \
awk 'NR<=3' $$file | grep -Eq "(Copyright|generated|GENERATED)" || echo $$file; \
done); \
if [ -n "$${licRes}" ]; then \
echo "license header checking failed:"; echo "$${licRes}"; \
exit 1; \
fi

.PHONY: common-deps
common-deps:
@echo ">> getting dependencies"
Expand Down Expand Up @@ -204,15 +193,6 @@ else
endif
endif

.PHONY: common-yamllint
common-yamllint:
@echo ">> running yamllint on all YAML files in the repository"
ifeq (, $(shell which yamllint))
@echo "yamllint not installed so skipping"
else
yamllint .
endif

# For backward-compatibility.
.PHONY: common-staticcheck
common-staticcheck: lint
Expand Down
2 changes: 1 addition & 1 deletion cmd/postgres_exporter/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (e *Exporter) discoverDatabaseDSNs() []string {
var dsnURI *url.URL
var dsnConnstring string

if strings.HasPrefix(dsn, "postgresql://") {
if strings.HasPrefix(dsn, "postgresql://") || strings.HasPrefix(dsn, "postgres://") {
var err error
dsnURI, err = url.Parse(dsn)
if err != nil {
Expand Down
23 changes: 18 additions & 5 deletions cmd/postgres_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ import (
)

var (
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
webConfig = webflag.AddFlags(kingpin.CommandLine)
listenAddress = kingpin.Flag("web.listen-address", "Address to listen on for web interface and telemetry.").Default(":9187").Envar("PG_EXPORTER_WEB_LISTEN_ADDRESS").String()
webConfig = webflag.AddFlags(kingpin.CommandLine)
webConfigFile = kingpin.Flag(
"web.config",
"[EXPERIMENTAL] Path to config yaml file that can enable TLS or authentication.",
).Default("").String()
metricPath = kingpin.Flag("web.telemetry-path", "Path under which to expose metrics.").Default("/metrics").Envar("PG_EXPORTER_WEB_TELEMETRY_PATH").String()
disableDefaultMetrics = kingpin.Flag("disable-default-metrics", "Do not include default metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_DEFAULT_METRICS").Bool()
disableSettingsMetrics = kingpin.Flag("disable-settings-metrics", "Do not include pg_settings metrics.").Default("false").Envar("PG_EXPORTER_DISABLE_SETTINGS_METRICS").Bool()
autoDiscoverDatabases = kingpin.Flag("auto-discover-databases", "Whether to discover the databases on a server dynamically.").Default("false").Envar("PG_EXPORTER_AUTO_DISCOVER_DATABASES").Bool()
queriesPath = kingpin.Flag("extend.query-path", "Path to custom queries to run.").Default("").Envar("PG_EXPORTER_EXTEND_QUERY_PATH").String()
onlyDumpMaps = kingpin.Flag("dumpmaps", "Do not run, simply dump the maps.").Bool()
constantLabelsList = kingpin.Flag("constantLabels", "A list of label=value separated by comma(,).").Default("").Envar("PG_EXPORTER_CONSTANT_LABELS").String()
excludeDatabases = kingpin.Flag("exclude-databases", "A list of databases to remove when autoDiscoverDatabases is enabled").Default("").Envar("PG_EXPORTER_EXCLUDE_DATABASES").String()
Expand Down Expand Up @@ -100,7 +103,6 @@ func main() {
DisableDefaultMetrics(*disableDefaultMetrics),
DisableSettingsMetrics(*disableSettingsMetrics),
AutoDiscoverDatabases(*autoDiscoverDatabases),
WithUserQueriesPath(*queriesPath),
WithConstantLabels(*constantLabelsList),
ExcludeDatabases(*excludeDatabases),
IncludeDatabases(*includeDatabases),
Expand All @@ -115,6 +117,9 @@ func main() {

prometheus.MustRegister(exporter)

cleanup := initializePerconaExporters(dsn, opts)
defer cleanup()

pe, err := collector.NewPostgresCollector(
logger,
dsn,
Expand All @@ -132,9 +137,17 @@ func main() {
w.Write(landingPage) // nolint: errcheck
})

var webCfg string
if *webConfigFile != "" {
webCfg = *webConfigFile
}
if *webConfig != "" {
webCfg = *webConfig
}

level.Info(logger).Log("msg", "Listening on address", "address", *listenAddress)
srv := &http.Server{Addr: *listenAddress}
if err := web.ListenAndServe(srv, *webConfig, logger); err != nil {
if err := web.ListenAndServe(srv, webCfg, logger); err != nil {
level.Error(logger).Log("msg", "Error running HTTP server", "err", err)
os.Exit(1)
}
Expand Down
Loading