-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19325 from department-of-veterans-affairs/uat4.4.…
…2/APPEALS-22218
- Loading branch information
Showing
37 changed files
with
1,090 additions
and
66 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,24 @@ | ||
# frozen_string_literal: true | ||
|
||
class Metrics::DashboardController < ApplicationController | ||
before_action :require_demo | ||
|
||
def show | ||
no_cache | ||
|
||
@metrics = Metric.includes(:user).where("created_at > ?", 1.hour.ago).order(created_at: :desc) | ||
|
||
begin | ||
render :show, layout: "plain_application" | ||
rescue StandardError => error | ||
Rails.logger.error(error.full_message) | ||
raise error.full_message | ||
end | ||
end | ||
|
||
private | ||
|
||
def require_demo | ||
redirect_to "/unauthorized" unless Rails.deploy_env?(:demo) | ||
end | ||
end |
This file contains 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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
class Metrics::V2::LogsController < ApplicationController | ||
skip_before_action :verify_authentication | ||
|
||
def create | ||
metric = Metric.create_metric_from_rest(self, allowed_params, current_user) | ||
failed_metric_info = metric&.errors.inspect || allowed_params[:message] | ||
Rails.logger.info("Failed to create metric #{failed_metric_info}") unless metric&.valid? | ||
|
||
if (metric.metric_type === 'error') | ||
error_info = { | ||
name: metric.metric_name, | ||
class: metric.metric_class, | ||
attrs: metric.metric_attributes, | ||
created_at: metric.created_at, | ||
uuid: metric.uuid, | ||
} | ||
error = StandardError.new(error_info) | ||
Raven.capture_exception(error) | ||
end | ||
|
||
head :ok | ||
end | ||
|
||
def allowed_params | ||
params.require(:metric).permit(:uuid, | ||
:name, | ||
:group, | ||
:message, | ||
:type, | ||
:product, | ||
:app_name, | ||
:metric_attributes, | ||
:additional_info, | ||
:sent_to, | ||
:sent_to_info, | ||
:relevant_tables_info, | ||
:start, | ||
:end, | ||
:duration | ||
) | ||
end | ||
end |
This file contains 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 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 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 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,105 @@ | ||
# frozen_string_literal: true | ||
|
||
class Metric < CaseflowRecord | ||
belongs_to :user | ||
|
||
METRIC_TYPES = { error: "error", log: "log", performance: "performance", info: "info" }.freeze | ||
LOG_SYSTEMS = { datadog: "datadog", rails_console: "rails_console", javascript_console: "javascript_console" } | ||
PRODUCT_TYPES = { | ||
queue: "queue", | ||
hearings: "hearings", | ||
intake: "intake", | ||
vha: "vha", | ||
efolder: "efolder", | ||
reader: "reader", | ||
caseflow: "caseflow", # Default product | ||
# Added below because MetricService has usages of this as a service | ||
vacols: "vacols", | ||
bgs: "bgs", | ||
gov_delivery: "gov_delivery", | ||
mpi: "mpi", | ||
pexip: "pexip", | ||
va_dot_gov: "va_dot_gov", | ||
va_notify: "va_notify", | ||
vbms: "vbms", | ||
}.freeze | ||
APP_NAMES = { caseflow: "caseflow", efolder: "efolder" }.freeze | ||
METRIC_GROUPS = { service: "service" }.freeze | ||
|
||
validates :metric_type, inclusion: { in: METRIC_TYPES.values } | ||
validates :metric_product, inclusion: { in: PRODUCT_TYPES.values } | ||
validates :metric_group, inclusion: { in: METRIC_GROUPS.values } | ||
validates :app_name, inclusion: { in: APP_NAMES.values } | ||
validate :sent_to_in_log_systems | ||
|
||
def self.create_metric(klass, params, user) | ||
create(default_object(klass, params, user)) | ||
end | ||
|
||
def self.create_metric_from_rest(klass, params, user) | ||
params[:metric_attributes] = JSON.parse(params[:metric_attributes]) if params[:metric_attributes] | ||
params[:additional_info] = JSON.parse(params[:additional_info]) if params[:additional_info] | ||
params[:sent_to_info] = JSON.parse(params[:sent_to_info]) if params[:sent_to_info] | ||
params[:relevant_tables_info] = JSON.parse(params[:relevant_tables_info]) if params[:relevant_tables_info] | ||
|
||
create(default_object(klass, params, user)) | ||
end | ||
|
||
def sent_to_in_log_systems | ||
invalid_systems = sent_to - LOG_SYSTEMS.values | ||
msg = "contains invalid log systems. The following are valid log systems #{LOG_SYSTEMS.values}" | ||
errors.add(:sent_to, msg) if !invalid_systems.empty? | ||
end | ||
|
||
def css_id | ||
user.css_id | ||
end | ||
|
||
private | ||
|
||
# Returns an object with defaults set if below symbols are not found in params default object. | ||
# Looks for these symbols in params parameter | ||
# - uuid | ||
# - name | ||
# - group | ||
# - message | ||
# - type | ||
# - product | ||
# - app_name | ||
# - metric_attributes | ||
# - additional_info | ||
# - sent_to | ||
# - sent_to_info | ||
# - relevant_tables_info | ||
# - start | ||
# - end | ||
# - duration | ||
def self.default_object(klass, params, user) | ||
{ | ||
uuid: params[:uuid], | ||
user: user || User.new(full_name: "Stand in user for testing", css_id: SecureRandom.uuid, station_id: 'Metrics'), | ||
metric_name: params[:name] || METRIC_TYPES[:log], | ||
metric_class: klass&.try(:name) || klass&.class.name || self.name, | ||
metric_group: params[:group] || METRIC_GROUPS[:service], | ||
metric_message: params[:message] || METRIC_TYPES[:log], | ||
metric_type: params[:type] || METRIC_TYPES[:log], | ||
metric_product: PRODUCT_TYPES[params[:product]] || PRODUCT_TYPES[:caseflow], | ||
app_name: params[:app_name] || APP_NAMES[:caseflow], | ||
metric_attributes: params[:metric_attributes], | ||
additional_info: params[:additional_info], | ||
sent_to: Array(params[:sent_to]).flatten, | ||
sent_to_info: params[:sent_to_info], | ||
relevant_tables_info: params[:relevant_tables_info], | ||
start: params[:start], | ||
end: params[:end], | ||
duration: calculate_duration(params[:start], params[:end], params[:duration]), | ||
} | ||
end | ||
|
||
def self.calculate_duration(start, end_time, duration) | ||
return duration if duration || !start || !end_time | ||
|
||
end_time - start | ||
end | ||
|
||
end |
This file contains 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 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 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 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 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
Oops, something went wrong.