DataDog / orchestrion

Automatic compile-time instrumentation of Go code
http://datadoghq.dev/orchestrion/
Apache License 2.0
159 stars 5 forks source link

refactor(injector): new API with better performance #234

Closed RomainMuller closed 2 months ago

RomainMuller commented 2 months ago

Create a new injector.Injector API that does not rely on decorator.Load (internally using packages.Load), instead using the basic go/types API to type-check the AST nodes in order to obtain the Uses map that is sufficient to build an import-managing decorator.Decorator instance.

The package name resolution is done by parsing type information from the archives mentioned in the importcfg file.

This change removes unnecessary compilation of un-instrumented archives which are not useful, and hence saves time and disk space.


The new API also does not consider PreserveLineInfo to be optional (this was never exposed to end-users anyway), so a bunch of test reference files have changed to now include line directives.

codecov[bot] commented 2 months ago

Codecov Report

Attention: Patch coverage is 69.85915% with 107 lines in your changes missing coverage. Please review.

Project coverage is 62.57%. Comparing base (741f717) to head (a5eaa59). Report is 2 commits behind head on main.

Files Patch % Lines
internal/injector/parse.go 61.53% 26 Missing and 9 partials :warning:
internal/injector/injector.go 75.64% 12 Missing and 7 partials :warning:
internal/injector/write.go 44.44% 10 Missing and 5 partials :warning:
internal/injector/imports.go 81.69% 11 Missing and 2 partials :warning:
internal/injector/restorer.go 74.28% 6 Missing and 3 partials :warning:
internal/toolexec/aspect/oncompile.go 69.56% 4 Missing and 3 partials :warning:
internal/toolexec/importcfg/lookup.go 53.84% 5 Missing and 1 partial :warning:
internal/injector/check.go 78.57% 2 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #234 +/- ## ========================================== - Coverage 63.63% 62.57% -1.06% ========================================== Files 95 101 +6 Lines 5095 5259 +164 ========================================== + Hits 3242 3291 +49 - Misses 1505 1627 +122 + Partials 348 341 -7 ``` | [Components](https://app.codecov.io/gh/DataDog/orchestrion/pull/234/components?src=pr&el=components&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | Coverage Δ | | |---|---|---| | [Instruments](https://app.codecov.io/gh/DataDog/orchestrion/pull/234/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | `34.56% <ø> (ø)` | | | [Go Driver](https://app.codecov.io/gh/DataDog/orchestrion/pull/234/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | `62.92% <ø> (-0.85%)` | :arrow_down: | | [Toolexec Driver](https://app.codecov.io/gh/DataDog/orchestrion/pull/234/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | `65.83% <66.66%> (-0.69%)` | :arrow_down: | | [Aspects](https://app.codecov.io/gh/DataDog/orchestrion/pull/234/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | `69.97% <ø> (-0.30%)` | :arrow_down: | | [Injector](https://app.codecov.io/gh/DataDog/orchestrion/pull/234/components?src=pr&el=component&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | `71.65% <70.25%> (-0.45%)` | :arrow_down: | | [Files](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog) | Coverage Δ | | |---|---|---| | [internal/toolexec/proxy/compile.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Ftoolexec%2Fproxy%2Fcompile.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvdG9vbGV4ZWMvcHJveHkvY29tcGlsZS5nbw==) | `88.46% <100.00%> (+7.90%)` | :arrow_up: | | [internal/injector/check.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Finjector%2Fcheck.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvaW5qZWN0b3IvY2hlY2suZ28=) | `78.57% <78.57%> (ø)` | | | [internal/toolexec/importcfg/lookup.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Ftoolexec%2Fimportcfg%2Flookup.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvdG9vbGV4ZWMvaW1wb3J0Y2ZnL2xvb2t1cC5nbw==) | `53.84% <53.84%> (ø)` | | | [internal/toolexec/aspect/oncompile.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Ftoolexec%2Faspect%2Foncompile.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvdG9vbGV4ZWMvYXNwZWN0L29uY29tcGlsZS5nbw==) | `70.31% <69.56%> (+0.45%)` | :arrow_up: | | [internal/injector/restorer.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Finjector%2Frestorer.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvaW5qZWN0b3IvcmVzdG9yZXIuZ28=) | `74.28% <74.28%> (ø)` | | | [internal/injector/imports.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Finjector%2Fimports.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvaW5qZWN0b3IvaW1wb3J0cy5nbw==) | `81.69% <81.69%> (ø)` | | | [internal/injector/write.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Finjector%2Fwrite.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvaW5qZWN0b3Ivd3JpdGUuZ28=) | `44.44% <44.44%> (ø)` | | | [internal/injector/injector.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Finjector%2Finjector.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvaW5qZWN0b3IvaW5qZWN0b3IuZ28=) | `72.22% <75.64%> (+1.60%)` | :arrow_up: | | [internal/injector/parse.go](https://app.codecov.io/gh/DataDog/orchestrion/pull/234?src=pr&el=tree&filepath=internal%2Finjector%2Fparse.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog#diff-aW50ZXJuYWwvaW5qZWN0b3IvcGFyc2UuZ28=) | `61.53% <61.53%> (ø)` | | ... and [7 files with indirect coverage changes](https://app.codecov.io/gh/DataDog/orchestrion/pull/234/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=DataDog)