-
Notifications
You must be signed in to change notification settings - Fork 9
[OSDEV-1335] Moderation. Deploy new moderation events Logstash pipeline #387
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
Merged
vladsha-dev
merged 16 commits into
main
from
OSDEV-1335-deploy-new-moderation-events-logstash-pipeline
Nov 1, 2024
Merged
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
855a17e
Introduced infra for the mod. events pipeline
vladsha-dev d18c3cd
Updated clear_opensearch.sh.tpl file
vladsha-dev ab7e818
Create index mapping and SQL script for the moderation events pipeline
vladsha-dev af8c7ad
Create empty contributor_name Ruby filter
vladsha-dev 2b66ba6
Merge branch 'main' into OSDEV-1335-deploy-new-moderation-events-logs…
vladsha-dev 43d2105
Create Ruby filters for particular fields, update mapping
vladsha-dev b867ed8
Delete mock generator
vladsha-dev 6ea8a90
Create test for country filter of the moderation events pipeline
vladsha-dev 321d98a
Merge branch 'main' into OSDEV-1335-deploy-new-moderation-events-logs…
vladsha-dev 52134bc
Write tests for moderation event filters and update the country filte…
vladsha-dev 35c4bbd
Merge branch 'main' into OSDEV-1335-deploy-new-moderation-events-logs…
vladsha-dev 6f4ede5
update release notes
vladsha-dev 876ddfe
Optimize SQL, add empty lines, define settings for indexes
vladsha-dev 39707f0
Merge branch 'main' into OSDEV-1335-deploy-new-moderation-events-logs…
vladsha-dev 1c6db46
Update release notes
vladsha-dev a877a06
Add empty line
vladsha-dev 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| #!/bin/bash | ||
| echo -e "\nDelete OpenSearch indexes\n" | ||
| curl -X DELETE https://$OPENSEARCH_DOMAIN/production-locations --aws-sigv4 "aws:amz:eu-west-1:es" --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" | ||
| echo -e "\nRemove lock file\n" | ||
| curl -X DELETE https://$OPENSEARCH_DOMAIN/moderation-events --aws-sigv4 "aws:amz:eu-west-1:es" --user "$AWS_ACCESS_KEY_ID:$AWS_SECRET_ACCESS_KEY" | ||
|
|
||
| echo -e "\nRemove the JDBC input lock files from the EFS connected to Logstash\n" | ||
| sudo mount -t efs -o tls,accesspoint=$EFS_AP_ID $EFS_ID:/ /mnt | ||
| sudo rm /mnt/logstash_jdbc_last_run | ||
| sudo rm /mnt/production_locations_jdbc_last_run | ||
| sudo rm /mnt/moderation_events_jdbc_last_run | ||
vladsha-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sudo umount /mnt | ||
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
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
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
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
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
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
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 @@ | ||
| api.enabled: false |
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,8 @@ | ||
| # This file is where pipelines are defined. | ||
| # For more information on multiple pipelines, see the documentation: | ||
| # https://www.elastic.co/guide/en/logstash/8.15/multiple-pipelines.html | ||
|
|
||
| - pipeline.id: production_locations | ||
| path.config: "/usr/share/logstash/pipeline/sync_production_locations.conf" | ||
| - pipeline.id: moderation_events | ||
| path.config: "/usr/share/logstash/pipeline/sync_moderation_events.conf" |
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,68 @@ | ||
| { | ||
| "index_patterns": [ | ||
| "moderation-events*" | ||
| ], | ||
roman-stolar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "template": { | ||
| "settings": { | ||
| "number_of_shards": 1, | ||
| "number_of_replicas": 1 | ||
| }, | ||
| "mappings": { | ||
| "properties": { | ||
| "moderation_id": { | ||
| "type": "keyword" | ||
| }, | ||
| "os_id": { | ||
| "type": "keyword" | ||
| }, | ||
| "contributor_id": { | ||
| "type": "keyword" | ||
| }, | ||
| "contributor_name": { | ||
| "type": "keyword" | ||
| }, | ||
| "claim_id": { | ||
| "type": "keyword" | ||
| }, | ||
| "request_type": { | ||
VadimKovalenkoSNF marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "type": "keyword" | ||
| }, | ||
| "source": { | ||
| "type": "keyword" | ||
| }, | ||
| "status": { | ||
| "type": "keyword" | ||
| }, | ||
| "status_change_date": { | ||
| "type": "date" | ||
| }, | ||
| "created_at": { | ||
| "type": "date" | ||
| }, | ||
| "updated_at": { | ||
| "type": "date" | ||
| }, | ||
vladsha-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "cleaned_data": { | ||
| "properties": { | ||
| "country": { | ||
| "properties": { | ||
| "name": { | ||
| "type": "keyword" | ||
| }, | ||
| "alpha_2": { | ||
| "type": "keyword" | ||
| }, | ||
| "alpha_3": { | ||
| "type": "keyword" | ||
| }, | ||
| "numeric": { | ||
| "type": "keyword" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
vladsha-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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
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,64 @@ | ||
| input{ | ||
| jdbc{ | ||
| jdbc_connection_string => "jdbc:postgresql://${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}" | ||
| jdbc_user => "${POSTGRES_USER}" | ||
| jdbc_password => "${POSTGRES_PASSWORD}" | ||
| jdbc_driver_class => "org.postgresql.Driver" | ||
| jdbc_paging_enabled => true | ||
| use_column_value => true | ||
| tracking_column => "updated_at" | ||
| tracking_column_type => "timestamp" | ||
| last_run_metadata_path => "/usr/share/logstash/data/plugins/inputs/jdbc/moderation_events_jdbc_last_run" | ||
| schedule => "*/${MODERATION_EVENTS_PIPELINE_UPDATE_INTERVAL_MINUTES} * * * *" | ||
| statement_filepath => "/usr/share/logstash/sql/sync_moderation_events.sql" | ||
| } | ||
| } | ||
| filter { | ||
| json { | ||
| source => "cleaned_data_value" | ||
| target => "cleaned_data_value" | ||
| } | ||
| ruby { | ||
| path => "/usr/share/logstash/scripts/moderation_events/country.rb" | ||
| } | ||
| ruby { | ||
| path => "/usr/share/logstash/scripts/moderation_events/os_id.rb" | ||
| } | ||
| ruby { | ||
| path => "/usr/share/logstash/scripts/moderation_events/claim_id.rb" | ||
| } | ||
| ruby { | ||
| path => "/usr/share/logstash/scripts/moderation_events/source.rb" | ||
| } | ||
| ruby { | ||
| path => "/usr/share/logstash/scripts/moderation_events/status_change_date.rb" | ||
| } | ||
| mutate { | ||
| copy => { "moderation_id" => "[@metadata][_id]" } | ||
| remove_field => [ | ||
| "@version", | ||
| "@timestamp", | ||
vladsha-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "cleaned_data_value", | ||
| "os_id_value", | ||
| "claim_id_value", | ||
| "source_value", | ||
| "status_change_date_value" | ||
| ] | ||
| } | ||
| } | ||
| output { | ||
| opensearch { | ||
| hosts => ["${OPENSEARCH_HOST}:${OPENSEARCH_PORT}"] | ||
| auth_type => { | ||
| type => "${OPENSEARCH_AUTH_TYPE}" | ||
| region => "${AWS_REGION}" | ||
| } | ||
vladsha-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ssl => "${OPENSEARCH_SSL}" | ||
| ssl_certificate_verification => "${OPENSEARCH_SSL_CERT_VERIFICATION}" | ||
| index => "moderation-events" | ||
| document_id => "%{[@metadata][_id]}" | ||
| template_name => "moderation_events_template" | ||
| template => "/usr/share/logstash/indexes/moderation_events.json" | ||
| legacy_template => false | ||
| } | ||
| } | ||
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
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,42 @@ | ||
| def filter(event) | ||
| claim_id_value = event.get('claim_id_value') | ||
|
|
||
| is_claim_id_value_valid = !claim_id_value.nil? | ||
| event.set('claim_id', claim_id_value) if is_claim_id_value_valid | ||
|
|
||
| return [event] | ||
| end | ||
|
|
||
| test 'claim_id filter with valid claim_id_value' do | ||
| in_event { | ||
| { | ||
| 'claim_id_value' => 12, | ||
| 'status' => 'PENDING' | ||
| } | ||
| } | ||
|
|
||
| expect('returns an object with claim_id set') do |events| | ||
| is_claim_id_value_present = events[0].get('claim_id_value') == 12 | ||
| is_status_present = events[0].get('status') == 'PENDING' | ||
| is_claim_id_present = events[0].get('claim_id') == 12 | ||
|
|
||
| is_claim_id_value_present && is_status_present && is_claim_id_present | ||
| end | ||
| end | ||
vladsha-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test 'claim_id filter with nil claim_id_value' do | ||
| in_event { | ||
| { | ||
| 'claim_id_value' => nil, | ||
| 'status' => 'PENDING' | ||
| } | ||
| } | ||
|
|
||
| expect('returns the same object') do |events| | ||
| is_claim_id_value_nil = events[0].get('claim_id_value').nil? | ||
| is_status_present = events[0].get('status') == 'PENDING' | ||
| is_claim_id_present = events[0].to_hash.key?('claim_id') | ||
|
|
||
| is_claim_id_value_nil && is_status_present && !is_claim_id_present | ||
| end | ||
| end | ||
vladsha-dev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.