Skip to content

[O11y][Postgresql] Add support for user specific timezone map - #13681

Merged
ishleenk17 merged 5 commits into
elastic:mainfrom
chavdaharnish:postgresql_support_user_timezone
Jun 25, 2025
Merged

[O11y][Postgresql] Add support for user specific timezone map#13681
ishleenk17 merged 5 commits into
elastic:mainfrom
chavdaharnish:postgresql_support_user_timezone

Conversation

@harnish-crest-data

@harnish-crest-data harnish-crest-data commented Apr 25, 2025

Copy link
Copy Markdown
Contributor
  • Enhancement

Proposed commit message

Description:

The original script extends Java's built-in ZoneId.SHORT_IDS map with CUSTOM_ZONE_IDS for additional abbreviations. This limitation makes it difficult for users to handle timezone abbreviations that are not included in the list.

Problem:

When a user encounters a timezone abbreviation that is not in the list, the script is unable to correctly map the timestamp to the corresponding timezone.

Goal:

To make the script more user-friendly by allowing users to specify their own timezone mappings. This can be achieved by:

  • Allowing users to provide a custom timezone mapping as a parameter.
  • Using this mapping to identify the corresponding long timezone ID (e.g. IST -> Asia/Kolkata).
  • Fallback to using the event.timezone value if no mapping is provided for a given timezone abbreviation.

Expected Behavior:

The script should be able to correctly handle timezone abbreviations that are not included in the default list, by using the user-provided mapping or falling back to event.timezone if no mapping is found.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.
  • I have verified that any added dashboard complies with Kibana's Dashboard good practices

Related issues

Screenshots

Specified under the tz_map

image2

Not specified under the tz_map

image

@harnish-crest-data
harnish-crest-data marked this pull request as ready for review April 25, 2025 13:25
@harnish-crest-data
harnish-crest-data requested a review from a team as a code owner April 25, 2025 13:25
@harnish-crest-data harnish-crest-data added enhancement New feature or request Team:Obs-InfraObs Observability Infrastructure Monitoring team [elastic/obs-infraobs-integrations] labels Apr 25, 2025
source: |-
String get_timezone(def ctx) {
if (ctx.event?.timezone != null) {
String tz = ctx.event.timezone.trim().toUpperCase();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not create the map inside script processor's "params" field? I do not think create a separate field is necessary?

See: https://www.elastic.co/docs/explore-analyze/scripting/modules-scripting-using#prefer-params

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also see: #13682 (comment)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Getting

postgresql/log test-postgresql-ubuntu-9-5.log:
[0] field "params" is used as array of objects, expected explicit definition with type group or nested

Also I have referred this script from cisco_ios: https://github.com/elastic/integrations/blob/main/packages/cisco_ios/data_stream/log/elasticsearch/ingest_pipeline/default.yml#L91

return tz;
}

// Handle offset formats (+00:00, -00:00, +00, -00)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, why did we remove the offset handling?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PostgreSQL logs always contains timezone in the log, as well user can have multiple timezones in theirs log file so no need to provide tz_offset to user. Using tz_short, tz_long we can handle the behavior!

default:
- /var/log/postgresql/postgresql-*-*.log*
- /var/log/postgresql/postgresql-*-*.csv*
- name: tz_map

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok this is a good idea I guess.

@agithomas

Copy link
Copy Markdown
Contributor

Suggestion: It will be good to add a section (or a troubleshooting section or both) in the README related to the newly added map, as this is not a mandatory parameter to configure.

@harnish-crest-data

Copy link
Copy Markdown
Contributor Author

Suggestion: It will be good to add a section (or a troubleshooting section or both) in the README related to the newly added map, as this is not a mandatory parameter to configure.

Added Timezone for log (optional) section under log section in readme file. Thanks!

@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@yomduf

yomduf commented May 6, 2025

Copy link
Copy Markdown

Hello, is there any issue blocking this PR ?

@shubhu934

Copy link
Copy Markdown

Hello @shmsr is there any issue blocking this PR ??

@shubhu934

Copy link
Copy Markdown

Hello @shmsr is there anything issue blocking this PR ??

@lucian-ioan
lucian-ioan self-requested a review May 29, 2025 06:39

@lucian-ioan lucian-ioan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes LGTM. Nothing I'd really change.

Can you also take a look @ishleenk17? Looks like there's nothing blocking and it should be merged.

@ishleenk17

Copy link
Copy Markdown
Member

Can you also take a look @ishleenk17? Looks like there's nothing blocking and it should be merged.

The changes were done as per the design I discussed with Harnish.
@lucian-ioan : Can you just test it out once with different timezones as mentioned in the issue for which this PR was created.
If good, I am god to merge this

@lucian-ioan

Copy link
Copy Markdown
Contributor

I've tested a few which were not included in the original list, such as NZDT or NOR and it works fine.

@ishleenk17 ishleenk17 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good!

@ishleenk17

Copy link
Copy Markdown
Member

/test

@elasticmachine

Copy link
Copy Markdown

💚 Build Succeeded

History

cc @lucian-ioan

@ishleenk17
ishleenk17 merged commit 6fa69c5 into elastic:main Jun 25, 2025
@elastic-vault-github-plugin-prod

Copy link
Copy Markdown
Contributor

Package postgresql - 1.29.0 containing this change is available at https://epr.elastic.co/package/postgresql/1.29.0/

shmsr pushed a commit to shmsr/integrations that referenced this pull request Jun 30, 2025
…c#13681)

* Add support for user specific timezone map

* update PR link

* update readme

---------

Co-authored-by: Ishleen Kaur <102962586+ishleenk17@users.noreply.github.com>
@andrewkroh andrewkroh added the documentation Improvements or additions to documentation. Applied to PRs that modify *.md files. label Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation. Applied to PRs that modify *.md files. enhancement New feature or request Integration:postgresql PostgreSQL Team:Obs-InfraObs Observability Infrastructure Monitoring team [elastic/obs-infraobs-integrations]

9 participants