-
Notifications
You must be signed in to change notification settings - Fork 6
Swap to rails_semantic_logger #984
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,12 +5,18 @@ class ApplicationController < ActionController::Base | |
|
|
||
| private | ||
|
|
||
| # Appends additional information to the log payload that are not Controller specific | ||
| def append_info_to_payload(payload) | ||
| super | ||
| payload[:host] = request.host | ||
| end | ||
|
|
||
| # redirects herokuapp domains and old domains to preferred domains | ||
| def ensure_domain | ||
| return unless ENV['PREFERRED_DOMAIN'] | ||
| return if request.host == ENV['PREFERRED_DOMAIN'] | ||
|
|
||
| Rails.logger.info("Handling Domain Redirect: #{request.host}") | ||
| redirect_to "https://#{ENV['PREFERRED_DOMAIN']}", status: :moved_permanently, allow_other_host: true | ||
| redirect_to "https://#{ENV.fetch('PREFERRED_DOMAIN', nil)}", status: :moved_permanently, allow_other_host: true | ||
|
Comment on lines
19
to
+20
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW I agree, but the linters auto-fix it to this so it's pointless to fight the bots on it. |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| # TimdexFieldUsageAnalyzer largely overrides some methods from the inherited FieldUsage | ||
| # We to log data in a format we can work with and return it to be used along with Tracers | ||
| # to determine which fields are being requested so we can modify our OpenSearch query. | ||
| # TimdexFieldUsageAnalyzer overrides FieldUsage so we can collect query usage data | ||
| # (including deprecated fields and arguments) and place it directly on GraphQL context. | ||
| # Resolvers then read this context data to shape OpenSearch query behavior and logging. | ||
| # https://graphql-ruby.org/queries/ast_analysis.html | ||
| class TimdexFieldUsageAnalyzer < GraphQL::Analysis::AST::FieldUsage | ||
| # This overrides a GraphQL::Analysis::AST::FieldUsage method | ||
| def result | ||
| Rails.logger.debug("GraphQL used fields: #{@used_fields.to_a}") | ||
| Rails.logger.info("GraphQL used deprecated fields: #{@used_deprecated_fields.to_a}") | ||
| Rails.logger.info("GraphQL used deprecated arguments: #{@used_deprecated_arguments.to_a}") | ||
| { | ||
| analysis_data = { | ||
| used_fields: @used_fields.to_a, | ||
| used_deprecated_fields: @used_deprecated_fields.to_a, | ||
| used_deprecated_arguments: @used_deprecated_arguments.to_a | ||
| } | ||
|
|
||
| query.context[:graphql_analysis] = analysis_data | ||
| analysis_data | ||
| end | ||
| end |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,7 +115,7 @@ def record_id(id:, index:) | |
| def search(searchterm:, citation:, contributors:, funding_information:, geodistance:, geobox:, identifiers:, | ||
| locations:, subjects:, title:, index:, source:, from:, boolean_type:, fulltext:, per_page: 20, | ||
| query_mode: 'keyword', use_global_scoring: false, tuning_parameters_input: nil, **filters) | ||
| Rails.logger.info("Searchterm: #{format_searchterm_for_log(searchterm)}") | ||
| analyzer_data = context[:graphql_analysis] || {} | ||
|
|
||
| query = construct_query(searchterm, citation, contributors, funding_information, geodistance, geobox, identifiers, | ||
| locations, subjects, title, source, boolean_type, filters, per_page, query_mode) | ||
|
|
@@ -132,11 +132,21 @@ def search(searchterm:, citation:, contributors:, funding_information:, geodista | |
| response[:hits] = results['hits']['total']['value'] | ||
| response[:records] = inject_hits_fields_into_source(results['hits']['hits']) | ||
| response[:aggregations] = collapse_buckets(results['aggregations']) | ||
|
|
||
| context[:graphql_search_events]&.push( | ||
| searchterm: format_searchterm_for_log(searchterm), | ||
| query_mode: query_mode, | ||
| timdex_result_count: response[:hits], | ||
| used_deprecated_fields: analyzer_data[:used_deprecated_fields] || [], | ||
| used_deprecated_arguments: analyzer_data[:used_deprecated_arguments] || [] | ||
| ) | ||
|
|
||
| response | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| end | ||
|
|
||
| def highlight_requested? | ||
| context[:tracers].first.log_data[:used_fields].include?('Record.highlight') | ||
| used_fields = context.dig(:graphql_analysis, :used_fields) || [] | ||
| used_fields.include?('Record.highlight') | ||
| end | ||
|
|
||
| # Convert aggregation fields to format expected by aggregations model. | ||
|
|
@@ -150,7 +160,7 @@ def requested_aggregation_field(field_name) | |
| end | ||
|
|
||
| def requested_aggregations | ||
| used_fields = context[:tracers].first.log_data[:used_fields] | ||
| used_fields = context.dig(:graphql_analysis, :used_fields) || [] | ||
| used_fields.select { |field| field.start_with?('Aggregations.') } | ||
| .map { |field| requested_aggregation_field(field.sub('Aggregations.', '')) } | ||
| end | ||
|
|
||
This file was deleted.
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.
Meh
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.
Very French: << les informations >>