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

discovery: add rails service name detector #30091

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

Yumasi
Copy link
Member

@Yumasi Yumasi commented Oct 14, 2024

What does this PR do?

Port the service naming logic for RubyOnRails application. from our injector. It should behave in the same way. This new detector is called when the command name extracted from the command line is puma (the command line of the application gets replaced when starting a RoR server).

Motivation

USMON-1233

Describe how to test/QA your changes

Handled by E2E test.

Possible Drawbacks / Trade-offs

Additional Notes

@Yumasi Yumasi force-pushed the guillaume.pagnoux/USMON-1233-ruby-service-name-generation branch from 0254171 to 3eee457 Compare October 14, 2024 13:09
@Yumasi Yumasi added team/usm The USM team changelog/no-changelog qa/done Skip QA week as QA was done before merge and regressions are covered by tests labels Oct 14, 2024
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Oct 14, 2024

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

inv create-vm --pipeline-id=47154650 --os-family=ubuntu

Note: This applies to commit bf02b55

Copy link

Regression Detector

@Yumasi Yumasi force-pushed the guillaume.pagnoux/USMON-1233-ruby-service-name-generation branch 2 times, most recently from c2e1b5f to 535027d Compare October 15, 2024 09:54
@Yumasi Yumasi force-pushed the guillaume.pagnoux/USMON-1233-ruby-service-name-generation branch from 535027d to eb3ca59 Compare October 15, 2024 13:32
@Yumasi Yumasi marked this pull request as ready for review October 16, 2024 08:32
@Yumasi Yumasi requested a review from a team as a code owner October 16, 2024 08:32
reader, err := SizeVerifiedReader(file)
if err != nil {
log.Debugf("skipping application.rb (%q): %v", filename, err)
return "", true
Copy link
Contributor

Choose a reason for hiding this comment

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

we will have a service without name, it does not make sense to me

Copy link
Member Author

Choose a reason for hiding this comment

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

While I totally agree with your comment, I do not think it should be the role of the rails detector (or any detectors) to handle that case.
This is also an issue for other detectors (e.g the Gunicorn one) we have and, IMO, should be handled in ExtractServiceMetadata to call a fallback mechanism (simpleDetector?).

Copy link
Contributor

@guyarb guyarb Oct 22, 2024

Choose a reason for hiding this comment

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

It might be the responsibility of the caller, as long as we guarantee when we zoom out that we won't have services without names, I'm fine with any implementation

bytes, err := io.ReadAll(reader)
if err != nil {
log.Debugf("unable to read application.rb (%q): %v", filename, err)
return "", true
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +93 to +94
snake := matchFirstCap.ReplaceAllString(pascalCasedWord, "${1}_${2}")
snake = matchAllCap.ReplaceAllString(snake, "${1}_${2}")
Copy link
Contributor

Choose a reason for hiding this comment

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

operations on strings are expensive, especially when regex is involved
can't we make a single call to ReplaceAllString?

Copy link
Member Author

@Yumasi Yumasi Oct 22, 2024

Choose a reason for hiding this comment

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

I looked a bit into this, and AFAICT, doing it in one call to ReplaceAllString would require lookahead (to find the next word first upper case letter, without actually matching it), which Go's regexp does not support.
So if we want to avoid doing that it looks like we need to make our own Pascal->Snake case converter.

Comment on lines 24 to 33
{
name: "name is found",
path: "./testdata/application.rb",
expected: "rails_hello",
},
{
name: "name not found",
path: "./testdata/application_invalid.rb",
expected: "",
},
Copy link
Contributor

Choose a reason for hiding this comment

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

as my other comment suggested, let's work on the test cases to gain full coverage of the function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/no-changelog component/system-probe qa/done Skip QA week as QA was done before merge and regressions are covered by tests team/usm The USM team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants