-
Notifications
You must be signed in to change notification settings - Fork 19
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
Report RequestIssue stats to DataDog #13770
Conversation
Code Climate has analyzed commit 8285642 and detected 0 issues on this pull request. View more on Code Climate. |
stats[METRIC_NAME_PREFIX] = req_issues.count | ||
|
||
req_issues.group(:closed_status).count.each do |ben_type, count| | ||
stats["#{METRIC_NAME_PREFIX}.st.#{ben_type || 'nil'}"] = count | ||
end | ||
|
||
req_issues.group(:benefit_type).count.each do |ben_type, count| | ||
stats["#{METRIC_NAME_PREFIX}.ben.#{ben_type}"] = count | ||
end | ||
|
||
dr_counts_by_type = req_issues.group(:decision_review_type).count | ||
dr_counts_by_type.each do |dr_type, count| | ||
stats["#{METRIC_NAME_PREFIX}.dr.#{dr_type}"] = count | ||
end | ||
|
||
# Could use `req_issues.group(:veteran_participant_id).count.count` but there's a count discrepancy | ||
stats["#{METRIC_NAME_PREFIX}.vet_count"] = req_issues.map(&:decision_review).map(&:veteran_file_number).uniq.count |
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.
Populate stats
hash with desire metrics.
|
||
# :reek:FeatureEnvy | ||
def collect_stats | ||
start_of_month = Time.zone.now.prev_month.beginning_of_month |
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.
This collector reports on statistics about last month.
RequestIssue.where.not(contention_reference_id: nil) | ||
.where(is_unidentified: true) | ||
.where("created_at >= ?", start_date) | ||
.where("created_at < ?", end_date) |
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.
All Rails queries have been tested in the production environment.
def emit(name, value, attrs: {}) | ||
DataDogService.emit_gauge( | ||
metric_group: METRIC_GROUP_NAME, | ||
metric_name: name, | ||
metric_value: value, | ||
app_name: APP_NAME, | ||
attrs: attrs | ||
) | ||
end |
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.
Note the attributes passed to DataDog:
app_name: "caseflow_job"
- mapped to aapp:caseflow_job
tag in DataDogmetric_group: YOUR_JOB_NAME_job
metric_name: YOUR_METRIC_NAME
- can have multiplemetric_name
s per jobmetric_value: YOUR_METRIC_VALUE
- value to log in DataDogattrs: { YOUR_ATTR_KEY: YOUR_ATTR_VALUE }
- each hash entry is mapped to aYOUR_ATTR_KEY:YOUR_ATTR_VALUE
tag in DataDog for selecting subsets of your metric or sets of different metrics
The metric label in DataDog will be dsva_appeals.YOUR_JOB_NAME_job.YOUR_METRIC_NAME
as defined in DataDogService.get_stat_name
app/jobs/stats_collector_job.rb
Outdated
DAILY_COLLECTORS = { | ||
"unidentified_request_issues_with_contention" => Collectors::RequestIssuesStatsCollector | ||
}.freeze | ||
WEEKLY_COLLECTORS = { | ||
}.freeze | ||
MONTHLY_COLLECTORS = { | ||
}.freeze |
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.
Add new collectors here.
|
||
metric_name_prefix = described_class::METRIC_NAME_PREFIX | ||
expect(stats[metric_name_prefix]).to eq(9) | ||
expect(stats["#{metric_name_prefix}.vet_count"]).to be_between(1, 9) |
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.
There should be at least 1 unique veteran but no more than 9 (total number relevant request issues).
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.
I generally like this approach of a single job where we can register various collectors. It's similar to data integrity checker in that respect.
I would move the collector classes outside the app/jobs
space since they are not jobs, but POROs.
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.
Awesome code! GTG!
Resolves #13769
Description
Provides initial capability to run a new job that reports RequestIssues stats to DataDog. This PR will be an example for future metrics, which can be added to this job (if it's related) or implemented as a new job.
A StatsCollectorJob has been implemented to simplify sending metrics to DataDog and to minimize the cost of running jobs as AWS Lambdas. StatsCollectorJob holds sets of Collectors that run daily, weekly, and monthly.
The StatsCollectorJob is scheduled to run in a Lambda in https://github.com/department-of-veterans-affairs/appeals-lambdas/pull/51.
Acceptance Criteria
Collector
s.Testing Plan (after merge)
RequestIssuesStatsCollector
to run monthly.