You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2026-10-23 12:08:57 +03:00
* Add aurora_stat_logical_wal_cache collector for Amazon Aurora PostgreSQL Expose WAL cache hits, misses and read requests of each logical replication slot from aurora_stat_logical_wal_cache(). The function only exists in Aurora PostgreSQL 11.17+, 12.12+, 13.8+, 14.7+ and 15.2+. Checking for Aurora alone would make the collector fail on every scrape on older versions, so it first checks that the function exists with to_regproc, the same way Aurora itself is detected, and returns no data when it doesn't. The check is a small helper that other version-dependent Aurora collectors can reuse. The collector is disabled by default and returns no data on non-Aurora servers. Aurora collector names get their own block in config.go, so gofmt does not realign the main list when longer names are added. Signed-off-by: Pavel K <megativ3@gmail.com> * collector: rename auroraFunctionExists to functionExists The helper isn't Aurora specific, so it could be used by collectors for other types of instances as well. Signed-off-by: Pavel K <megativ3@gmail.com> --------- Signed-off-by: Pavel K <megativ3@gmail.com>
51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
// Copyright The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package collector
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/DATA-DOG/go-sqlmock"
|
|
)
|
|
|
|
func expectFunctionExists(mock sqlmock.Sqlmock, name string, exists bool) {
|
|
mock.ExpectQuery(sanitizeQuery(functionExistsQuery)).
|
|
WithArgs(name).
|
|
WillReturnRows(sqlmock.NewRows([]string{"exists"}).AddRow(exists))
|
|
}
|
|
|
|
func TestFunctionExists(t *testing.T) {
|
|
for _, exists := range []bool{true, false} {
|
|
db, mock, err := sqlmock.New()
|
|
if err != nil {
|
|
t.Fatalf("Error opening a stub db connection: %s", err)
|
|
}
|
|
|
|
expectFunctionExists(mock, "aurora_stat_logical_wal_cache", exists)
|
|
|
|
got, err := functionExists(context.Background(), db, "aurora_stat_logical_wal_cache")
|
|
if err != nil {
|
|
t.Errorf("Error calling functionExists: %s", err)
|
|
}
|
|
if got != exists {
|
|
t.Errorf("Expected %v, got %v", exists, got)
|
|
}
|
|
if err := mock.ExpectationsWereMet(); err != nil {
|
|
t.Errorf("there were unfulfilled exceptions: %s", err)
|
|
}
|
|
db.Close()
|
|
}
|
|
}
|