-
Notifications
You must be signed in to change notification settings - Fork 570
[PostgreSQL] Add checkpointer data stream #18428
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
Open
giorgi-imerlishvili-elastic
wants to merge
2
commits into
elastic:main
Choose a base branch
from
giorgi-imerlishvili-elastic:postgresql-checkpointer-datastream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/postgresql/data_stream/checkpointer/_dev/deploy/docker/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| ARG SERVICE_VERSION=${SERVICE_VERSION:-9.5.25} | ||
| FROM postgres:${SERVICE_VERSION} | ||
|
|
||
| COPY docker-entrypoint-initdb.d /docker-entrypoint-initdb.d | ||
|
|
||
| # Runtime fix for host-mounted /var/log/postgresql permissions. | ||
| # Runs before the official entrypoint drops privileges to the postgres user. | ||
| COPY docker-entrypoint-wrapper.sh /usr/local/bin/docker-entrypoint-wrapper.sh | ||
| ENTRYPOINT ["/usr/local/bin/docker-entrypoint-wrapper.sh"] | ||
|
|
||
| HEALTHCHECK --interval=10s --retries=6 CMD pg_isready -U postgres |
16 changes: 16 additions & 0 deletions
16
packages/postgresql/data_stream/checkpointer/_dev/deploy/docker/docker-compose.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| services: | ||
| postgresql: | ||
| build: | ||
| context: . | ||
| args: | ||
| SERVICE_VERSION: ${SERVICE_VERSION} | ||
| environment: | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres | ||
| POSTGRES_DB: postgres | ||
| # Enable logging | ||
| POSTGRES_INITDB_ARGS: "--data-checksums" | ||
| ports: | ||
| - 5432 | ||
| volumes: | ||
| - ${SERVICE_LOGS_DIR}:/var/log/postgresql |
21 changes: 21 additions & 0 deletions
21
...ata_stream/checkpointer/_dev/deploy/docker/docker-entrypoint-initdb.d/0-enable-logging.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| cat <<-EOF >> $PGDATA/postgresql.conf | ||
| # Enable some log facilities. | ||
| log_duration = 'on' | ||
| log_connections = 'on' | ||
| log_disconnections = 'on' | ||
|
|
||
| # Ensure that statements are logged, with their durations. | ||
| log_statement = 'none' | ||
| log_min_duration_statement = 0 | ||
|
|
||
| # Give agent read permissions. In NO case for production usage. | ||
| log_file_mode = '0666' | ||
|
|
||
| # Try to imitate logging behaviour in Debian/Ubuntu, but there the logging collector | ||
| # is not used. | ||
| logging_collector = 'on' | ||
| log_directory = '/var/log/postgresql' | ||
| log_line_prefix = '%m [%p] %q%u@%d ' | ||
| EOF | ||
6 changes: 6 additions & 0 deletions
6
...checkpointer/_dev/deploy/docker/docker-entrypoint-initdb.d/1-enable-pg_stat_statements.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env bash | ||
| cat <<-EOF >> $PGDATA/postgresql.conf | ||
| shared_preload_libraries = 'pg_stat_statements' | ||
| pg_stat_statements.max = 10000 | ||
| pg_stat_statements.track = all | ||
| EOF |
1 change: 1 addition & 0 deletions
1
...r/_dev/deploy/docker/docker-entrypoint-initdb.d/2-create-extension-pg_stat_statements.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| create extension pg_stat_statements; |
32 changes: 32 additions & 0 deletions
32
packages/postgresql/data_stream/checkpointer/_dev/deploy/docker/docker-entrypoint-wrapper.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # The official Postgres image entrypoint will drop privileges to the `postgres` user | ||
| # before starting the server. If /var/log/postgresql is a host bind-mount, the | ||
| # permissions from the host win over whatever we set at build time. | ||
| # | ||
| # We try a best-effort fix from inside the container: | ||
| # - ensure the directory exists | ||
| # - if it's not writable, loosen permissions (works for many bind-mount setups) | ||
| # | ||
| # If the host mount is root-squashed or has restrictive ACLs, no container-side fix | ||
| # can override that; in that case you must adjust host perms or mount options. | ||
|
|
||
| LOG_DIR="/var/log/postgresql" | ||
|
|
||
| mkdir -p "${LOG_DIR}" || true | ||
|
|
||
| # If the directory isn't writable, try to make it writable for postgres. | ||
| # We avoid chown to a fixed uid/gid (varies across distros / image versions). | ||
| # Making it world-writable is acceptable for dev containers (this is under _dev/). | ||
| if ! su -s /bin/sh -c "test -w '${LOG_DIR}'" postgres 2>/dev/null; then | ||
| chmod 0777 "${LOG_DIR}" 2>/dev/null || true | ||
| fi | ||
|
|
||
| # Preserve the original image behavior: when no args are provided, run `postgres`. | ||
| if [ "$#" -eq 0 ]; then | ||
| set -- postgres | ||
| fi | ||
|
|
||
| # Use the original entrypoint and preserve its init logic. | ||
| exec /usr/local/bin/docker-entrypoint.sh "$@" |
4 changes: 4 additions & 0 deletions
4
packages/postgresql/data_stream/checkpointer/_dev/deploy/variants.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| variants: | ||
| v18: | ||
| SERVICE_VERSION: 18.1 | ||
| default: v18 |
5 changes: 5 additions & 0 deletions
5
packages/postgresql/data_stream/checkpointer/_dev/test/system/test-default-config.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| vars: | ||
| hosts: | ||
| - postgres://postgres:postgres@{{Hostname}}:{{Port}}?sslmode=disable | ||
| data_stream: | ||
| vars: ~ |
21 changes: 21 additions & 0 deletions
21
packages/postgresql/data_stream/checkpointer/agent/stream/stream.yml.hbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| metricsets: ["query"] | ||
| period: {{period}} | ||
| hosts: | ||
| {{#each hosts}} | ||
| - {{this}} | ||
| {{/each}} | ||
| tags: | ||
| {{#each tags as |tag|}} | ||
| - {{tag}} | ||
| {{/each}} | ||
| {{#if processors}} | ||
| processors: | ||
| {{processors}} | ||
| {{/if}} | ||
| {{#if ssl}} | ||
| {{ssl}} | ||
| {{/if}} | ||
| driver: "postgres" | ||
| sql_queries: | ||
| - query: "SELECT * FROM pg_stat_checkpointer;" | ||
| response_format: "table" |
94 changes: 94 additions & 0 deletions
94
packages/postgresql/data_stream/checkpointer/fields/agent.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| - name: cloud | ||
| title: Cloud | ||
| group: 2 | ||
| description: Fields related to the cloud or infrastructure the events are coming from. | ||
| footnote: 'Examples: If Metricbeat is running on an EC2 host and fetches data from its host, the cloud info contains the data about this machine. If Metricbeat runs on a remote machine outside the cloud and fetches data from a service running in the cloud, the field contains cloud data from the machine the service is running on.' | ||
| type: group | ||
| fields: | ||
| - name: account.id | ||
| level: extended | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| dimension: true | ||
| description: 'The cloud account or organization id used to identify different entities in a multi-tenant environment. Examples: AWS account id, Google Cloud ORG Id, or other unique identifier.' | ||
| example: 666777888999 | ||
| - name: availability_zone | ||
| level: extended | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| dimension: true | ||
| description: Availability zone in which this host is running. | ||
| example: us-east-1c | ||
| - name: instance.id | ||
| level: extended | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| description: Instance ID of the host machine. | ||
| example: i-1234567890abcdef0 | ||
| dimension: true | ||
| - name: provider | ||
| level: extended | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| description: Name of the cloud provider. Example values are aws, azure, gcp, or digitalocean. | ||
| example: aws | ||
| dimension: true | ||
| - name: region | ||
| level: extended | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| dimension: true | ||
| description: Region in which this host is running. | ||
| example: us-east-1 | ||
| - name: image.id | ||
| type: keyword | ||
| description: Image ID for the cloud instance. | ||
| - name: container | ||
| title: Container | ||
| group: 2 | ||
| description: 'Container fields are used for meta information about the specific container that is the source of information. These fields help correlate data based containers from any runtime.' | ||
| type: group | ||
| fields: | ||
| - name: id | ||
| level: core | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| description: Unique container id. | ||
| dimension: true | ||
| - name: host | ||
| title: Host | ||
| group: 2 | ||
| description: 'A host is defined as a general computing instance. ECS host.* fields should be populated with details about the host on which the event happened, or from which the measurement was taken. Host types include hardware, virtual machines, Docker containers, and Kubernetes nodes.' | ||
| type: group | ||
| fields: | ||
| - name: name | ||
| level: core | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| dimension: true | ||
| description: 'Name of the host. It can contain what `hostname` returns on Unix systems, the fully qualified domain name, or a name specified by the user. The sender decides which value to use.' | ||
| - name: containerized | ||
| type: boolean | ||
| description: > | ||
| If the host is a container. | ||
|
|
||
| - name: os.build | ||
| type: keyword | ||
| example: "18D109" | ||
| description: > | ||
| OS build information. | ||
|
|
||
| - name: os.codename | ||
| type: keyword | ||
| example: "stretch" | ||
| description: > | ||
| OS codename, if any. | ||
|
|
||
| - name: agent | ||
| title: Agent | ||
| type: group | ||
| fields: | ||
| - name: id | ||
| type: keyword | ||
| ignore_above: 1024 | ||
| dimension: true |
16 changes: 16 additions & 0 deletions
16
packages/postgresql/data_stream/checkpointer/fields/base-fields.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| - name: data_stream.type | ||
| type: constant_keyword | ||
| description: Data stream type. | ||
| - name: data_stream.dataset | ||
| type: constant_keyword | ||
| description: Data stream dataset. | ||
| - name: data_stream.namespace | ||
| type: constant_keyword | ||
| description: Data stream namespace. | ||
| - name: event.dataset | ||
| type: constant_keyword | ||
| description: Event dataset | ||
| value: postgresql.checkpointer | ||
| - name: '@timestamp' | ||
| type: date | ||
| description: Event timestamp. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - external: ecs | ||
| name: service.address | ||
| dimension: true |
87 changes: 87 additions & 0 deletions
87
packages/postgresql/data_stream/checkpointer/fields/fields.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| - name: sql | ||
| type: group | ||
| description: > | ||
| SQL-related fields. | ||
|
|
||
| fields: | ||
| - name: driver | ||
| type: keyword | ||
| description: > | ||
| The SQL driver used (e.g., postgres, mysql, sqlite). | ||
|
|
||
| - name: metrics | ||
| type: group | ||
| description: > | ||
| SQL metrics and performance counters. | ||
|
|
||
| fields: | ||
| - name: string.stats_reset | ||
| type: keyword | ||
| description: > | ||
| Time at which these statistics were last reset | ||
|
|
||
| - name: numeric | ||
| type: group | ||
| description: > | ||
| SQL metrics and performance counters. | ||
|
|
||
| fields: | ||
| - name: buffers_written | ||
| type: long | ||
| description: > | ||
| Number of buffers written to disk. | ||
|
|
||
| - name: num_requested | ||
| type: long | ||
| description: > | ||
| Number of requests made. | ||
|
|
||
| - name: num_timed | ||
| type: long | ||
| description: > | ||
| Number of timed operations. | ||
|
|
||
| - name: restartpoints_done | ||
| type: long | ||
| description: > | ||
| Number of completed restart points. | ||
|
|
||
| - name: restartpoints_req | ||
| type: long | ||
| description: > | ||
| Number of requested restart points. | ||
|
|
||
| - name: restartpoints_timed | ||
| type: long | ||
| description: > | ||
| Number of timed restart points. | ||
|
|
||
| - name: stats_reset | ||
| type: date | ||
| description: > | ||
| Timestamp when statistics were last reset. | ||
|
|
||
| - name: sync_time | ||
| type: double | ||
| description: > | ||
| Time spent in synchronization operations (in milliseconds). | ||
|
|
||
| - name: write_time | ||
| type: double | ||
| description: > | ||
| Time spent writing data to disk (in milliseconds). | ||
|
|
||
| - name: num_done | ||
| type: double | ||
| description: > | ||
| Number of checkpoints that have been performed | ||
|
|
||
| - name: slru_written | ||
| type: double | ||
| description: > | ||
| Number of SLRU buffers written during checkpoints and restartpoints | ||
|
|
||
| - name: query | ||
| type: text | ||
| description: >- | ||
| The SQL query string. |
2 changes: 2 additions & 0 deletions
2
packages/postgresql/data_stream/checkpointer/fields/package-fields.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| - name: postgresql | ||
| type: group |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| title: SQL checkpointer metrics | ||
| type: metrics | ||
| streams: | ||
| - input: sql/metrics | ||
| title: PostgreSQL checkpointer metrics | ||
| description: Collect PostgreSQL checkpointer metrics | ||
| vars: | ||
| - name: period | ||
| type: text | ||
| title: Period | ||
| default: 10s | ||
| - name: processors | ||
| type: yaml | ||
| title: Processors | ||
| multi: false | ||
| required: false | ||
| show_user: false | ||
| description: >- | ||
| Processors are used to reduce the number of fields in the exported event or to enhance the event with metadata. This executes in the agent before the events are shipped. See [Processors](https://www.elastic.co/guide/en/fleet/current/elastic-agent-processor-configuration.html) for details. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟢 Low
docker-entrypoint-initdb.d/0-enable-logging.sh:21The script sets
log_directory = '/var/log/postgresql'andlogging_collector = 'on'but does not ensure the directory is writable by PostgreSQL. The parent-level script atpackages/postgresql/_dev/deploy/docker/docker-entrypoint-initdb.d/0-enable-logging.shincludeschmod a+wx /var/log/postgresqlfor this purpose. Without this, the logging collector fails to write and PostgreSQL may crash or run without logs, breaking the checkpointer test environment.🤖 Copy this AI Prompt to have your agent fix this: