Commit Graph
36 Commits
Author SHA1 Message Date
meredith 31d1b136ce [SCAN-81] Report ChunkUnit Panics (#4367)
* Add common.RecoverWithHandler

Allows panic recovery that still reports to Sentry, with caller-defined
handling afterward, so there's no confusion about chained recover() or
re-panicking.

* Catch ChunkUnit panics and include them in report

Keeps panics showing in Sentry, and includes panics in existing
first-fatal-error behavior, but does not propagate panics further
upward any longer.

* Test SourceManager ChunkUnit panic reporting
2025-08-06 10:33:45 -05:00
Miccah ab1b459b2b [fix] Report the unit in a single scan job (#4209)
* [fix] Report the unit in a single scan job

* Eliminate divide by 0 possibility
2025-06-05 09:17:26 -07:00
Dustin Decker 9a483c9169 Enumeration jobs should not consume concurrency slots (#3952) 2025-03-04 08:58:36 -08:00
0x1 3ee9c2f1af [SCAN-165] Use Err Reporting (#3862)
* nit

* update rate limit handler to use reporter

* update process repos to use rate limit handler with unit reporter

* update getReposByOrgOrUser to report err

* update dedupreporter to report err

* add errReporter interface to handle both types of reporters

* convert to error reporter types

* update handleRateLimit signature

* use reporters for all rate limit handlers in github

* get repo url before err check

* use iterator

* remove err log

* nit

* pluralize

* remove err log

* update tests

* make linter happy
2025-02-04 13:44:37 -05:00
1e5aac4495 Add Scan method to SourceManager to scan a single SourceUnit (#3650)
* renaming to enumeration

* update enumeration

* comments

* remove commented out func

* Add Scan method to SourceManager to scan a single SourceUnit

* Add tests for each Enumerate and Scan

* add source name to log

* rename scanWithUnits

* updating comments to be more clear

---------

Co-authored-by: ahmed <ahmed.zahran@trufflesec.com>
Co-authored-by: 0x1 <13666360+0x1@users.noreply.github.com>
2024-11-25 14:26:11 -05:00
0x1andMiccah Castorina 1276d262f2 [scan-9] Update enumeration logic (#3626)
* renaming to enumeration

* update enumeration

* comments

* remove commented out func

---------

Co-authored-by: Miccah Castorina <m.castorina93@gmail.com>
2024-11-25 14:13:03 -05:00
Bob Idleandahrav 409beeb18b golangci-lint: replace exportloopref with copyloopvar and remove the copy of the 'for' variables (#3591)
* fix: replace golangci-lint exportloopref with copyloopvar

* fix: remove copy of the 'for' variables

---------

Co-authored-by: ahrav <ahravdutta02@gmail.com>
2024-11-13 12:52:04 -08:00
Richard Gomez 06e37caa04 chore: re-order log context fields (#3430) 2024-10-23 10:53:15 -04:00
shangchenglumetro c4aab3fb51 chore: fix some comments (#3098) 2024-07-25 10:37:13 -07:00
ahrav 3c659a2144 set default buffer size to 64 (#2778) 2024-05-03 08:42:18 -07:00
Miccah c60443891b Add Display method to SourceUnit and Kind member to the CommonSourceUnit (#2450)
* Add Display method to SourceUnit and Kind member to the CommonSourceUnit

* Make SourceUnitID return the ID and a kind

These two values together uniquely represent a unit.
2024-02-20 11:24:13 -08:00
Miccah 216a29d7cf [chore] Add some doc comments to source manager (#2434) 2024-02-13 07:54:48 -08:00
Miccah 74f1553e06 [fix] Add unit information to error returned by ChunkUnit (#2410) 2024-02-12 08:24:31 -08:00
Miccah dd4d4a8a96 Refactor UnitHook to block the scan if finished metrics aren't handled (#2309)
* Refactor UnitHook to block the scan if finished metrics aren't handled

* Log once when back-pressure is detected

* Add hook channel size metric

* Use plural "metrics" for consistency

* Replace LRU cache with map
2024-02-08 14:50:58 -08:00
ahrav f209b04d5d add priority semaphore (#2336) 2024-01-24 16:43:56 -08:00
Cody Rose 9c8674777c Dedupe some source log keys (#2250)
The source manager attaches some context keys, but in certain circumstances, they're already present, resulting in duplicate keys. This PR changes the attachment to be conditional. It also adds some new log messages to track source startup progress.
2023-12-21 10:11:52 -08:00
Miccah f6bbc59bf6 Check for SourceUnit support dynamically in the SourceManager (#2205)
* Check for SourceUnit support dynamically in the SourceManager

* Only call the function if we can use source units
2023-12-14 11:48:15 -08:00
ahrav 0595a3baac allow targets for the source manager (#2182)
* allow targets to the source manager

* use targets
2023-12-06 16:38:35 -08:00
Miccah 7ecd43ab1e [chore] Minor cleanup of source_manager.go (#2134) 2023-11-29 11:08:25 -08:00
Miccah 78219a27b3 Call Finish in SourceManager after the semaphore is released (#2121) 2023-11-24 13:22:08 -08:00
Miccah efa404942a Add ability to dynamically scale concurrently running sources (#1790)
* Add ability to dynamically scale concurrently running sources

Refactor SourceManager to use a counting semaphore to allow for
dymanically changing limits. This complicated `Wait() error` which needs
to return the first error encountered. We previously got that for free
using `errgroup.Group`, however now we need to handle that ourselves.
`Wait()` needs to return an error for use in the engine to set the
correct exit code.

* Group third party imports together
2023-09-20 16:49:56 -07:00
Miccah dbcb888063 Update Source interface to use SourceID and JobID types (#1774)
The previous implementation used int64 for both, which can be mixed up
easily. Using distinct types adds a layer of type safety checked by the
compiler.
2023-09-14 11:28:24 -07:00
Miccah be4d0bcb41 Refactor SourceManager to remove Enrollment (#1740)
* Refactor SourceManager to remove Enrollment

Initializing the Source will be the responsibility of the caller. The
SourceManager exposes a GetIDs method for getting a source and job ID.

* Update tests

* Update engine usage

* Update apiClient interface to have one GetIDs method

* Update SourceManager usage in engine
2023-09-12 16:58:38 -07:00
Miccah 522b2fab29 Add a cancel cause to job cancellation (#1728) 2023-08-30 12:00:44 -07:00
Miccah 7ba880f47a Add AvailableCapacity method to SourceManager (#1665) 2023-08-29 12:36:44 -07:00
Miccah 5eb776cd61 Support cancelling a run from a JobProgressRef (#1663) 2023-08-25 10:43:33 -07:00
Miccah 61977412df Add SourceName to JobProgressRef (#1664) 2023-08-25 07:48:25 -07:00
Miccah f2bfcc7ac6 Capture source-reported progress in JobProgress snapshot (#1661) 2023-08-24 11:28:50 -07:00
ahrav 9ae72308be Include the job ID in a chunk (#1652)
* Include the job ID in a source's chunk.

* address comments.

* address comments.
2023-08-22 14:00:27 -07:00
Miccah 5cfbde783f Fix reversed ordering of arguments (#1648)
The source manager initialization function was defined as `sourceID`
followed by `jobID`, while the source initialization function is the
reverse. This is confusing and easy to mix up since the parameters are
the same type.

This commit adds a test to make sure the source manager initializes in
the correct order, but it doesn't prevent the library user to make the
same mistake. We may want to consider using different types.
2023-08-22 07:55:56 -07:00
Miccah fae54c7ffa Add ScanChunk to allow injecting Chunks into the SourceManager's channel (#1634)
With the introduction of the SourceManager, the chunks channel became
private and read-only. This provides a method to write chunks into the
channel as we transition away from needing to do that.
2023-08-16 16:09:23 -07:00
Miccah 1cd600f70f Use SourceManager in engine (#1586)
* Add SourceManager to Engine struct

* Update Engine methods to use the SourceManager

* Fix GCS test

The original was testing that `Init()` errors weren't surfaced in
`Finish()`, but the `SourceManager` changed that behavior.

* JobProgress race fixes

* Add contextual values

* Remove unused code

* Add debug logs

* Rename WithConcurrency to WithConcurrentSources

* Always forward chunks to the output chunks channel
2023-08-03 13:36:30 -05:00
Miccah a07b6664f8 Support fatal errors in job reports (#1562)
* Support fatal errors in job reports

* WIP: JobReporter and JobInspector

* WIP: JobReportHook and JobReportRef

* Add ChunkError type and asyncRun helper method

* Rename JobReport to JobProgress

* Return a closed channel from Done when the JobProgress is nil

* Comment catchFirstFatal function
2023-07-31 11:28:30 -05:00
Miccah e391e89f3e Initial implementation of JobReport with SourceManager usage (#1557)
* Initial implementation of JobReport with SourceManager usage

* Limit concurrent units

* Only save the last JobReport per handle
2023-07-27 10:49:56 -05:00
Miccah 10f0963bc9 Add SourceManager tests for Run and Wait methods (#1530)
* Miscellaneous SourceManager updates

* Own the chunks channel instead of accepting it as an input
* Add Chunks and Wait methods
* Fix bug in Enroll so it actually returns the handle
* Add context.Context parameter to the SourceInitFunc type

* Add SourceManager tests for Run and Wait methods

* Rename man variables to mgr
2023-07-26 00:48:28 -05:00
Miccah 91c5472876 Implement SourceManager basics (#1515)
* Implement SourceManager basics

* Rename identifiers and add a default headlessAPI implementation

* Rewrite to use SourceInitFunc

* Update variable name to accurately reflect its value
2023-07-21 15:20:25 -05:00