Skip to content

feat(module): add module for tracing SQL queries created by jackc/pgx#1301

Merged
axw merged 44 commits intoelastic:mainfrom
EpicStep:main
Oct 24, 2022
Merged

feat(module): add module for tracing SQL queries created by jackc/pgx#1301
axw merged 44 commits intoelastic:mainfrom
EpicStep:main

Conversation

@gvencadze
Copy link
Contributor

@gvencadze gvencadze commented Aug 20, 2022

This module provide enhanced support of jackc/pgx library and it's features such as COPY FROM and BATCH statements

Closes #854

@cla-checker-service
Copy link

cla-checker-service bot commented Aug 20, 2022

💚 CLA has been signed

@ghost
Copy link

ghost commented Aug 20, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-10-24T08:42:28.137+0000

  • Duration: 58 min 44 sec

Test stats 🧪

Test Results
Failed 0
Passed 8688
Skipped 215
Total 8903

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • run benchmark tests : Run the benchmark test.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@axw
Copy link
Member

axw commented Sep 8, 2022

@gvencadze sorry for the silence, this slipped my attention.

Can you please sign the CLA? As there are commits from multiple authors, both you and @EpicStep will need to do this.

@gvencadze
Copy link
Contributor Author

gvencadze commented Sep 13, 2022

@axw hey, I've signed CLA (tried with both of emails that's linked to account), but nothing changed. Do I need to restart pipeline or something else?

UPD: merge latest changes and CLA check re-runs, now it's ok

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

This looks great, thanks for the PR! I've left some comments, and in addition to those:

…cepts pgx.ConnConfig. Move duplicate code to separate func called startSpan to make ...Trace functions small and simple. Add type casting checks to avoid instrument runtime panics.
@gvencadze
Copy link
Contributor Author

gvencadze commented Sep 15, 2022

@axw hey, I've done what you've write about above:

  1. integration tests are already presented in tracer_test.go, they're located under TestLog
  2. make update-licenses update-modules fmt scripts/Dockerfile-testing - done, but I've seen 400 bad request in stdout (What am I doing wrong?)
  3. vanity import - done

that's stdout after make call:

=== RUN   TestHTTPTransportOptionsEmptyURL
    http_test.go:707: 
        	Error Trace:	http_test.go:707
        	Error:      	Received unexpected error:
        	            	request failed with 400 Bad Request: {"accepted":0,"errors":[{"message":"unexpected EOF"}]}
        	Test:       	TestHTTPTransportOptionsEmptyURL
    http_test.go:708: 
        	Error Trace:	http_test.go:708
        	Error:      	"[]" should have 1 item(s), but has 0
        	Test:       	TestHTTPTransportOptionsEmptyURL
@gvencadze
Copy link
Contributor Author

@axw I've added e2e tests for Query and Copy tracing, only the batch trace remain. Can you take a look? Maybe you will find something else that should be changed/discussed

Copy link
Member

@axw axw left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you, this looks great.

@axw
Copy link
Member

axw commented Sep 27, 2022

/test

@axw
Copy link
Member

axw commented Sep 28, 2022

@gvencadze there's an issue with formatting, CI is failing with this error:

[2022-09-27T17:20:32.075Z] goimports differs:
[2022-09-27T17:20:32.076Z]  - module/apmpgx/e2e_test.go

Can you please make sure make check-full passes locally?

@gvencadze
Copy link
Contributor Author

gvencadze commented Sep 28, 2022

@gvencadze there's an issue with formatting, CI is failing with this error:

[2022-09-27T17:20:32.075Z] goimports differs:
[2022-09-27T17:20:32.076Z]  - module/apmpgx/e2e_test.go

Can you please make sure make check-full passes locally?

Sure, I’ll take a look

UPD: @axw, I've run make check, and got 400 bad request in http modules tests

Comment on lines +90 to +99
statement, ok := data["sql"].(string)
if !ok {
apm.CaptureError(ctx,
fmt.Errorf("%w: expect string, got: %T",
ErrInvalidType,
data["sql"],
),
).Send()
return
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@axw one more question - should I capture and send type casting errors into APM? I didn't find something like this in other modules, but I think it will be good for understanding that something inside module (or its dependency) is broken

Copy link
Member

Choose a reason for hiding this comment

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

There's no precedent and I'm a bit on the fence about it, but I think it's fine to keep it for now at least. There's not really a good alternative at the moment. Generally errors are about the service, rather than about the instrumentation. I suppose ideally there would be some way to log errors about the instrumentation - we can revise it later.

@ghost
Copy link

ghost commented Oct 23, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (59/59) 💚
Files 99.346% (152/153) 👍
Classes 96.275% (336/349) 👍
Methods 90.49% (961/1062) 👍
Lines 82.269% (11224/13643) 👎 -0.015
Conditionals 100.0% (0/0) 💚
@axw
Copy link
Member

axw commented Oct 24, 2022

@gvencadze I see you've sorted out the last of the tests 🎉

One last thing before I merge it: would you please add an entry to CHANGELOG.asciidoc, to the "Unreleased" section?

@gvencadze
Copy link
Contributor Author

gvencadze commented Oct 24, 2022

@axw done

Also, If we want to create another one module for pgx (but for v5 version), should we open issue and link it with MR or not?
Current module have support of both versions, but I think we can make it better using v5 built-in changes

I'm talking about this new method:
https://pkg.go.dev/github.com/jackc/pgx/v5#CopyFromTracer

They aren't available in V4 version, so I think we should make another one module, something called apmpgxv5 for example

@axw
Copy link
Member

axw commented Oct 24, 2022

run elasticsearch-ci/docs

@axw
Copy link
Member

axw commented Oct 24, 2022

They aren't available in V4 version, so I think we should make another one module, something called apmpgxv5 for example

I agree, that sounds like the way to go. Yes, please do open a separate issue and reference this PR.

@axw axw enabled auto-merge (squash) October 24, 2022 10:14
@axw axw merged commit 4d07ba8 into elastic:main Oct 24, 2022
@axw
Copy link
Member

axw commented Oct 24, 2022

Thank you very much for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 participants