Skip to content
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

[VANotify] - Update VANotify::DefaultCallback to handle hash or array statsd_tags #20235

Merged
merged 8 commits into from
Jan 16, 2025

Conversation

coope93
Copy link
Contributor

@coope93 coope93 commented Jan 10, 2025

Summary

  • This work is behind a feature toggle (flipper): YES
  • Updated VANotify::DefaultCallback to handle receiving the statsd_tags in the callback_metadata as either a hash or an array. Currently, it only supports a hash. When calling the StatsD.increment('stats_d_metric_name', tags:), statsD expects the tags as an array of 'key:value' strings, and this PR adds the ability to pass the statsd_tags in the same format while keeping the existing hash functionality. It also allows for passing any tags that will be added to the statsd zero silent failure metrics, and not just the function and service tag. If that is not desired I can update this PR, but it seemed to add value.
  • Validates that the function and service keys are provided in the metadata, as well as validates that the metadata is either a hash or array.
  • I updated this as a result of adding the callback_metadata to our va_notify emails, but in adding them I was passing the tags in the statsd format of an array, as opposed to a hash.
  • 1010 Health Apps
  • This new functionality is behind the va_notify_metadata_statsd_tags flipper toggle

Related issue(s)

Testing done

  • New code is covered by unit tests

Screenshots

Note: Optional

What areas of the site does it impact?

VANotify callbacks and anywhere they are currently being used

Acceptance criteria

  • I fixed|updated|added unit tests and integration tests for each feature (if applicable).
  • No error nor warning in the console.
  • Events are being sent to the appropriate logging solution
  • Documentation has been updated (link to documentation)
  • No sensitive information (i.e. PII/credentials/internal URLs/etc.) is captured in logging, hardcoded, or specs
  • Feature/bug has a monitor built into Datadog (if applicable)
  • If app impacted requires authentication, did you login to a local build and verify all authenticated routes work as expected
  • I added a screenshot of the developed feature

Requested Feedback

Would you prefer I add this behind a flipper toggle, and is it alright that now all tags are able to be passed as part of the metadata.

'function:function description']
end

context 'metadata is provided with statsd_tags as hash' do
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I debated trying to DRY up some of these specs a bit by reusing the notification variable or something similar, but kept it a little more separate for now to keep some of the existing patterns.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I like specs to be clear to read and also clear when they fail - so I'm good with the duplication.

tags = ["service:#{service}", "function:#{function}"]

tags = if statsd_tags.is_a?(Hash)
statsd_tags.map { |key, value| "#{key}:#{value}" }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should allow any key:value pair in the same format as we use when incrementing statsd metrics. This does allow for other tags, as well as not forcing the service and function tags. If we need to require those tags I can update it to validate that those are present.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think it would be good to make it more obvious that we need both the service and function tags.

Copy link
Contributor Author

@coope93 coope93 Jan 13, 2025

Choose a reason for hiding this comment

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

Yeah, that makes sense. I'll take a look at this tomorrow and see if I can make a nice way to show the two required tags. Thanks for taking a look!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nathanbwright when you have some time, I updated the default_callbacks to require the service and function keys, as well as raise an exception when the metadata type is invalid.

JoshingYou1
JoshingYou1 previously approved these changes Jan 13, 2025
Copy link
Contributor

@JoshingYou1 JoshingYou1 left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work Brandon 😃

@LindseySaari
Copy link
Contributor

I will wait until VA Notify has a chance to look. The changes look straightforward to me, but want to make sure this has some eyes on it from the VA Notify team

nathanbwright
nathanbwright previously approved these changes Jan 14, 2025
LindseySaari
LindseySaari previously approved these changes Jan 14, 2025
@coope93 coope93 dismissed stale reviews from LindseySaari and nathanbwright via 40bef0f January 14, 2025 18:21
Copy link

1 Warning
⚠️ This PR changes 304 LoC (not counting whitespace/newlines).

In order to ensure each PR receives the proper attention it deserves, we recommend not exceeding
200. Expect some delays getting reviews.

File Summary

Files

  • config/features.yml (+3/-0)

  • modules/va_notify/lib/va_notify/default_callback.rb (+30/-4)

  • modules/va_notify/spec/lib/default_callback_spec.rb (+220/-47)

    Note: We exclude files matching the following when considering PR size:

    *.csv, *.json, *.tsv, *.txt, *.md, Gemfile.lock, app/swagger, modules/mobile/docs, spec/fixtures/, spec/support/vcr_cassettes/, modules/mobile/spec/support/vcr_cassettes/, db/seeds, modules/vaos/app/docs, modules/meb_api/app/docs, modules/appeals_api/app/swagger/, *.bru, *.pdf
    

Big PRs are difficult to review, often become stale, and cause delays.

Generated by 🚫 Danger

@@ -1434,6 +1434,9 @@ features:
va_notify_custom_errors:
actor_type: user
description: Custom error classes instead of the generic Common::Exceptions::BackendServiceException
va_notify_metadata_statsd_tags:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I realized I wanted this behind a flipper toggle, so I added a new one. The spec diff is larger since I have a context for on/off, and we'll be able to delete the off side after we validate everything is fine in prod for it.

@coope93 coope93 requested a review from a team January 15, 2025 13:43
@coope93 coope93 self-assigned this Jan 15, 2025
@coope93 coope93 requested review from LindseySaari and removed request for LindseySaari January 15, 2025 17:16
@coope93 coope93 merged commit 3d73d00 into master Jan 16, 2025
41 of 44 checks passed
@coope93 coope93 deleted the coope93-va-notify-default-callbacks-statsd-tags branch January 16, 2025 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants