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

Nr 280084 add support for postgre sql v17 #176

Merged
merged 17 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
88 changes: 75 additions & 13 deletions src/metrics/instance_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,52 @@ import (
"github.com/blang/semver/v4"
)

func generateInstanceDefinitions(version *semver.Version) []*QueryDefinition {
queryDefinitions := make([]*QueryDefinition, 1, 3)
v91 := semver.MustParse("9.1.0")
v92 := semver.MustParse("9.2.0")

queryDefinitions[0] = instanceDefinitionBase
type VersionDefinition struct {
minVersion semver.Version
queryDefinitions []*QueryDefinition
}

if version.GE(v91) {
queryDefinitions = append(queryDefinitions, instanceDefinition91)
}
var versionDefinitions = []VersionDefinition{
{
minVersion: semver.MustParse("17.0.0"),
queryDefinitions: []*QueryDefinition{
instanceDefinitionBase170,
instanceDefinition170,
},
},
{
minVersion: semver.MustParse("9.2.0"),
queryDefinitions: []*QueryDefinition{
instanceDefinitionBase,
instanceDefinition91,
instanceDefinition92,
},
},
{
minVersion: semver.MustParse("9.1.0"),
queryDefinitions: []*QueryDefinition{
instanceDefinitionBase,
instanceDefinition91,
},
},
{
minVersion: semver.MustParse("0.0.0"),
queryDefinitions: []*QueryDefinition{
instanceDefinitionBase,
},
},
}

if version.GE(v92) {
queryDefinitions = append(queryDefinitions, instanceDefinition92)
func generateInstanceDefinitions(version *semver.Version) []*QueryDefinition {
// Find the first version definition that's applicable
for _, versionDef := range versionDefinitions {
if version.GE(versionDef.minVersion) {
return versionDef.queryDefinitions
}
}

return queryDefinitions
// This should never happen due to the "0.0.0" fallback version,
return []*QueryDefinition{instanceDefinitionBase}
rahulreddy15 marked this conversation as resolved.
Show resolved Hide resolved
rahulreddy15 marked this conversation as resolved.
Show resolved Hide resolved
}

var instanceDefinitionBase = &QueryDefinition{
Expand Down Expand Up @@ -62,6 +92,38 @@ var instanceDefinition92 = &QueryDefinition{

dataModels: []struct {
CheckpointWriteTime *int64 `db:"time_writing_checkpoint_files_to_disk" metric_name:"bgwriter.checkpointWriteTimeInMillisecondsPerSecond" source_type:"rate"`
CheckpointSynTime *int64 `db:"time_synchronizing_checkpoint_files_to_disk" metric_name:"bgwriter.checkpointSyncTimeInMillisecondsPerSecond" source_type:"rate"`
CheckpointSyncTime *int64 `db:"time_synchronizing_checkpoint_files_to_disk" metric_name:"bgwriter.checkpointSyncTimeInMillisecondsPerSecond" source_type:"rate"`
}{},
}

var instanceDefinitionBase170 = &QueryDefinition{
query: `SELECT
BG.buffers_clean AS buffers_written_by_background_writer,
BG.maxwritten_clean AS background_writer_stops,
BG.buffers_alloc AS buffers_allocated
FROM pg_stat_bgwriter BG;`,

dataModels: []struct {
BuffersWrittenByBackgroundWriter *int64 `db:"buffers_written_by_background_writer" metric_name:"bgwriter.buffersWrittenByBackgroundWriterPerSecond" source_type:"rate"`
BackgroundWriterStops *int64 `db:"background_writer_stops" metric_name:"bgwriter.backgroundWriterStopsPerSecond" source_type:"rate"`
BuffersAllocated *int64 `db:"buffers_allocated" metric_name:"bgwriter.buffersAllocatedPerSecond" source_type:"rate"`
}{},
}

var instanceDefinition170 = &QueryDefinition{
query: `SELECT
BG.num_timed AS scheduled_checkpoints_performed,
BG.num_requested AS requested_checkpoints_performed,
BG.buffers_written AS buffers_written_during_checkpoint,
cast(BG.write_time AS bigint) AS time_writing_checkpoint_files_to_disk,
cast(BG.sync_time AS bigint) AS time_synchronizing_checkpoint_files_to_disk
FROM pg_stat_checkpointer BG;`,

dataModels: []struct {
ScheduledCheckpointsPerformed *int64 `db:"scheduled_checkpoints_performed" metric_name:"checkpointer.checkpointsScheduledPerSecond" source_type:"rate"`
RequestedCheckpointsPerformed *int64 `db:"requested_checkpoints_performed" metric_name:"checkpointer.checkpointsRequestedPerSecond" source_type:"rate"`
BuffersWrittenDuringCheckpoint *int64 `db:"buffers_written_during_checkpoint" metric_name:"checkpointer.buffersWrittenForCheckpointsPerSecond" source_type:"rate"`
CheckpointWriteTime *int64 `db:"time_writing_checkpoint_files_to_disk" metric_name:"checkpointer.checkpointWriteTimeInMillisecondsPerSecond" source_type:"rate"`
CheckpointSyncTime *int64 `db:"time_synchronizing_checkpoint_files_to_disk" metric_name:"checkpointer.checkpointSyncTimeInMillisecondsPerSecond" source_type:"rate"`
}{},
}
14 changes: 14 additions & 0 deletions src/metrics/instance_definitions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,17 @@ func Test_generateInstanceDefinitions10(t *testing.T) {

assert.Equal(t, 3, len(queryDefinitions))
}

func Test_generateInstanceDefinitions170(t *testing.T) {
v := semver.MustParse("17.0.0")
queryDefinitions := generateInstanceDefinitions(&v)

assert.Equal(t, 2, len(queryDefinitions))
}

func Test_generateInstanceDefinitions175(t *testing.T) {
v := semver.MustParse("17.5.0")
queryDefinitions := generateInstanceDefinitions(&v)

assert.Equal(t, 2, len(queryDefinitions))
}
rahulreddy15 marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion tests/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ services:
POSTGRES_DB: demo

postgres-latest-supported:
image: postgres:16
image: postgres:17.0
restart: always
environment:
POSTGRES_USER: postgres
Expand Down
Loading
Loading