Skip to content

Commit 29614a0

Browse files
authored
Ficus debug logs (#1610)
When you pass the `--debug` flag into `fossa analyze`, `fossa container analyze` or `fossa sbom analyze`, the debug bundle is not created in a file called `fossa.debug.zip`. This zip file contains `fossa.debug.json` and `fossa.telemetry.json`. If you are doing snippet scanning, then it will also contain debug logs from Ficus.
1 parent 68710c9 commit 29614a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+392
-186
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Steps to reproduce the behavior:
2121
A clear and concise description of what you expected to happen.
2222

2323
**Debug bundle**
24-
Please run `fossa` with the `--debug` flag and attach the resulting `fossa.debug.json.gz` file here.
24+
Please run `fossa` with the `--debug` flag and attach the resulting `fossa.debug.zip` file here.
2525

2626
**Additional context**
2727
Add any other context you think is relevant about the problem here.

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ sandbox/
2525
fossa.debug.json
2626
fossa.debug.json.gz
2727
fossa.telemetry.json
28+
fossa.debug.zip
2829

2930
# Integration Tests
3031
integration-test/artifacts/
@@ -42,4 +43,4 @@ target/
4243

4344
# Include targets in test
4445
!test/reachability/testdata/maven-default/target
45-
!test/reachability/testdata/maven-build-config/dist
46+
!test/reachability/testdata/maven-build-config/dist

Changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# FOSSA CLI Changelog
22

3+
## 3.13.0
4+
- Change how debug logs are generated. They are now generated in a file called fossa.debug.zip, which can contain multiple files. For the common case of `fossa analyze --debug`, it will now contain the debug bundle (fossa.debug.json) and the telemetry json (fossa.telemetry.json). It will also contain Ficus logs if Ficus is run via --x-snippet-scan ([#1610](https://github.com/fossas/fossa-cli/pull/1610))
5+
36
## 3.12.3
47
- Licensing: applies a fix for proprietary license detection ([#1616](https://github.com/fossas/fossa-cli/pull/1616))
58

docs/contributing/telemetry.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
## Overview
44

5-
The telemetry lifecycle is implemented via `bracket`. We provision `TelemetryCtx`
6-
during setup and during teardown and we perform sink Telemetry records. We do
5+
The telemetry lifecycle is implemented via `bracket`. We provision `TelemetryCtx`
6+
during setup and during teardown and we perform sink Telemetry records. We do
77
not use (producer-consumer threaded) pattern for emitting logs. This is to preserve
8-
simplicity and limit network requests to a minimum. The current telemetry requirements
9-
allow us to ship a reasonably small payload (<200kb).
8+
simplicity and limit network requests to a minimum. The current telemetry requirements
9+
allow us to ship a reasonably small payload (<200kb).
1010

11-
Within TelemetryCtx,
11+
Within TelemetryCtx,
1212

1313
- We use `TBMQueue` for listed logs, results, and measures.
1414
- We use `STM` for atomic counters and data containers.
1515
- We use `TMVar` for setting a one-time sink or command information.
1616

1717
## Telemetry Scope and User Interface
1818

19-
Telemetry scope is configurable by the user. Telemetry scope can be
20-
configured via the following options in order of precedence:
19+
Telemetry scope is configurable by the user. Telemetry scope can be
20+
configured via the following options in order of precedence:
2121

2222
1. Command line option (`--with-telemetry-scope=off|full`)
2323
2. Environment variable (`FOSSA_TELEMETRY_SCOPE=off|full`)
@@ -32,18 +32,20 @@ telemetry:
3232
```
3333
3434
For instance, if both the command-line option and the environment variable are provided
35-
the telemetry scope provided via the command line will be used.
36-
35+
the telemetry scope provided via the command line will be used.
36+
3737
Supported telemetry scopes:
38-
- `off` - telemetry results are not captured or emitted.
38+
- `off` - telemetry results are not captured or emitted.
3939
- `full` - telemetry results are uploaded to the default or specified endpoint.
40-
40+
4141
When we do not have `ApiOpts` (e.g. API Key), we do not emit telemetry to an endpoint.
4242

4343
## Telemetry Sinks
4444

45-
When the environment variable `FOSSA_TELEMETRY_DEBUG=1` or `--debug` flag is provided,
46-
the telemetry sink is set to file. This will generate the file `fossa.telemetry.json` in the current working directory.
45+
When the environment variable `FOSSA_TELEMETRY_DEBUG=1` or `--debug` flag is provided,
46+
the telemetry sink is set to file. The `--debug` flag will generate a file called `fossa.debug.zip` in the current working directory, which will contain a file called `fossa.telemetry.json`.
47+
48+
The `FOSSA_TELEMETERY_DEBUG` variable is set to 1 and the `--debug` flag is not passed in, then we will write `fossa.telemetry.json` in the current working directory.
4749

4850
Telemetry is sunk to the same server as the analysis.
4951

@@ -65,15 +67,15 @@ experimental (SomeProject manifestDir manifestFile) = do
6567

6668
2. Captured system and CLI version information
6769

68-
This is automatically done at teardown. If we do not have version identifier,
69-
we consider CLI environment to be development. CLI version is set as git tag,
70+
This is automatically done at teardown. If we do not have version identifier,
71+
we consider CLI environment to be development. CLI version is set as git tag,
7072
or branch name. This information is exact as data collected in debug bundle.
7173

7274
3. Capturing errors and warnings
7375

7476
## teleRunDiagnosticsIO
7577

76-
```haskell
78+
```haskell
7779
-- >> :t trackResult
7880
-- trackResult :: Has Telemetry sig m => Result a -> m ()
7981
@@ -86,7 +88,7 @@ bar = do
8688
4. Capturing cpu time of a computation
8789

8890
```haskell
89-
-- >> :t trackTimeSpent
91+
-- >> :t trackTimeSpent
9092
-- trackTimeSpent :: Has Telemetry sig m => Text -> m a -> m a
9193
9294
someComplexComputation :: Has Telemetry sig m => m ()
@@ -97,7 +99,7 @@ someComplexComputation = do
9799

98100
5. Tracking raw telemetry messages
99101

100-
Avoid using this interface as much as possible. It produces type-free telemetry data and
102+
Avoid using this interface as much as possible. It produces type-free telemetry data and
101103
we want to capture telemetry data that has explicit/strict data shape.
102104

103105
```haskell
@@ -111,8 +113,8 @@ foo = do
111113

112114
### Future
113115

114-
We can implement `span` and `trace`s to provide capability to continuous profiling, this
115-
can be done by modifying `trackTimeSpent` to `trackSpan`.
116+
We can implement `span` and `trace`s to provide capability to continuous profiling, this
117+
can be done by modifying `trackTimeSpent` to `trackSpan`.
116118

117119
```
118120
<---------------------------------> ~ Trace
@@ -122,5 +124,5 @@ can be done by modifying `trackTimeSpent` to `trackSpan`.
122124
```
123125
124126
Ideally, we can leverage existing sdk from apm provider, or open telemetry instead of
125-
building this capability in-house.
127+
building this capability in-house.
126128

docs/differences-from-v1.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ FOSSA 3.x supports following new build managers and languages:
6464

6565
FOSSA CLI 3.x now does automatic analysis target discovery when you run `fossa analyze`. This means that `fossa init` is no longer required. `fossa init` is now a no-op that emits a warning, and will be removed in a future release.
6666

67-
In 1.x, modules could be manually configured with "strategies" that specified _how_ a module should be analyzed. While `fossa init` attempted to choose the best strategy, manual intervention was sometimes required depending on the project's setup.
67+
In 1.x, modules could be manually configured with "strategies" that specified _how_ a module should be analyzed. While `fossa init` attempted to choose the best strategy, manual intervention was sometimes required depending on the project's setup.
6868

6969
In 3.x, the CLI now automatically selects the optimal strategy for analysis targets given the current environment (e.g. whether a build tool is available). This is possible because discovery and analysis are now one step, so we can check the suitability of analysis strategies while discovering targets.
7070

7171
### New fossa-deps configuration support
7272

7373
With [`fossa-deps.{yml,json}` file](features/manual-dependencies.md), 3.x supports:
7474

75-
- License scanning vendor dependencies
75+
- License scanning vendor dependencies
7676
<!-- markdown-link-check-disable-next-line -->
7777
- Analyzing archives that are located at a specific web address (e.g. https://my-deps-source/v1.zip)
7878
- Manually specifying dependency by it's name and license (e.g. my-custom-dep with MIT license)
@@ -123,9 +123,9 @@ Following CLI commands are not supported with 3.x:
123123
### Language Specific Changes
124124

125125
#### Gradle
126-
- 3.x uses a new plugin-based strategy to perform discovery and analysis, it analyses all resolvable Gradle configurations.
126+
- 3.x uses a new plugin-based strategy to perform discovery and analysis, it analyses all resolvable Gradle configurations.
127127
- 3.x does not accept any options: `cmd`, `task`, `timeout`, `all-configurations`, `configuration`, `retries`, `online`, `all-submodules`, and any other option supported in 1.x for Gradle analysis.
128-
- In 3.x,
128+
- In 3.x,
129129
- There is no timeout (analysis may run for a long time)
130130
- All resolvable configurations are analyzed
131131
- There are no retries (CLI will attempt to analyze the project once)
@@ -134,7 +134,7 @@ Following CLI commands are not supported with 3.x:
134134
- Refer to [FOSSA 3.x gradle docs](references/strategies/languages/gradle/gradle.md) for more information for gradle.
135135

136136
#### Clojure
137-
- 3.x performs the `lein deps :tree` strategy by default.
137+
- 3.x performs the `lein deps :tree` strategy by default.
138138
- 3.x does not support any options - `strategy`, and `lien` for Clojure analysis.
139139
- Refer to [FOSSA 3.x clojure docs](references/strategies/languages/clojure/clojure.md) for more information on how 3.x performs analysis for clojure.
140140

@@ -175,11 +175,11 @@ Following CLI commands are not supported with 3.x:
175175
#### Python
176176
- 3.x automatically selects the application strategy which yields the highest fidelity of dependency information.
177177
- 3.x uses attempts to infer requirements.txt for any file with prefix `req` in its name, and `txt` extension.
178-
- 3.x does not support the `strategy` or `requirement` option for Python analysis.
178+
- 3.x does not support the `strategy` or `requirement` option for Python analysis.
179179
- Refer to [FOSSA 3.x python docs](references/strategies/languages/python/python.md) for more information on how 3.x performs analysis for python.
180180

181181
#### Gem
182-
- 3.x attempts to use the `bundle show` command (`bundle` must be accessible from `$PATH`), and if it fails, it attempts to analyze dependencies from `Gemfile.lock` file.
182+
- 3.x attempts to use the `bundle show` command (`bundle` must be accessible from `$PATH`), and if it fails, it attempts to analyze dependencies from `Gemfile.lock` file.
183183
- 3.x does not support `strategy` or `gemfile-lock-path` option for Gem Analysis.
184184
- Refer to [FOSSA 3.x gem docs](references/strategies/languages/ruby/ruby.md) for more information on how 3.x performs analysis for gem.
185185

@@ -199,7 +199,7 @@ Since analysis targets are now automatically discovered during analysis, `fossa
199199

200200
### Migrate your .fossa.yml file
201201

202-
We've made major breaking changes in the `.fossa.yml` file format for CLI 3.x to improve clarity. You'll need to migrate your 1.x `.fossa.yml` to the new 3.x format for their configurations to apply. `.fossa.yml` for 1.x will be ignored when running cli with version greater than 1.x. We determine whether a configuration file is compatible by examining its `version` field.
202+
We've made major breaking changes in the `.fossa.yml` file format for CLI 3.x to improve clarity. You'll need to migrate your 1.x `.fossa.yml` to the new 3.x format for their configurations to apply. `.fossa.yml` for 1.x will be ignored when running cli with version greater than 1.x. We determine whether a configuration file is compatible by examining its `version` field.
203203

204204
- .fossa.yml with version field value of `1` and `2` are for 1.x.
205205
- .fossa.yml with version field value of `3` are for 3.x, and 2.x.
@@ -234,7 +234,7 @@ For more information, including usage information, see [FOSSAv1 report compatibi
234234

235235
FOSSA 1.x CLI is available and can be used indefinitely. We intend to make 3.x the default target for our installation scripts (as previously described in our documentation) in July 2022. If you wish to continue using 1.x, please migrate to using `install-v1` scripts.
236236

237-
FOSSA will only patch 1.x for security fixes. Any feature and patch development work will occur in 3.x moving forth.
237+
FOSSA will only patch 1.x for security fixes. Any feature and patch development work will occur in 3.x moving forth.
238238

239239
#### I'm getting a poor result with latest version compared 1.x.
240240

@@ -252,7 +252,7 @@ You can identify your cli version by performing `fossa --version` command.
252252

253253
#### I'm running into an error - how do I debug?
254254

255-
You can add `--debug` argument to your fossa commands (e.g. `fossa analyze --debug`), this will emit debug logs to stdout, and create `fossa.debug.json` in working directory.
255+
You can add a `--debug` argument to your fossa commands (e.g. `fossa analyze --debug`), this will emit debug logs to stdout, and create a file called `fossa.debug.zip` in the working directory that contains a debug bundle (fossa.debug.json).
256256

257257
#### What's the difference between FOSSA CLI 1.x, 2.x, and 3.x?
258258

@@ -268,7 +268,7 @@ You can add `--debug` argument to your fossa commands (e.g. `fossa analyze --deb
268268

269269
3.x will be released on November 12, 2021.
270270

271-
> Note: There are no breaking changes from 2.x to 3.x. The 3.x version in functional sense, continuation of 2.x version. The 3.x version was released to (1) match the `version` field of the fossa configuration file with the major release version of cli, (2) mark migration of CLI 2.x source code back into the fossa-cli repository, and (3) mark 3.x now the default target for installation for all fossa users moving forwards.
271+
> Note: There are no breaking changes from 2.x to 3.x. The 3.x version in functional sense, continuation of 2.x version. The 3.x version was released to (1) match the `version` field of the fossa configuration file with the major release version of cli, (2) mark migration of CLI 2.x source code back into the fossa-cli repository, and (3) mark 3.x now the default target for installation for all fossa users moving forwards.
272272
273273

274274
If you were previously using the installation script provided at [fossas/spectrometer](https://github.com/fossas/spectrometer/), it is now recommended to use the installation latest script provided at [fossas/fossa-cli](https://github.com/fossas/fossa-cli/).

docs/features/vuln_reachability.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ With this configuration, when FOSSA CLI analyzes a Maven or Gradle project at th
7272
```bash
7373
fossa analyze --debug
7474
75-
cat fossa.debug.json | jq '.bundleReachabilityRaw'
75+
unzip -p fossa.debug.zip fossa.debug.json | jq '.bundleReachabilityRaw'
7676
[
7777
{
7878
"callGraphAnalysis": {
@@ -113,7 +113,7 @@ cat fossa.debug.json | jq '.bundleReachabilityRaw'
113113
]
114114
115115
116-
cat fossa.debug.json | jq '.bundleReachabilityEndpoint'
116+
unzip -p fossa.debug.zip fossa.debug.json | jq '.bundleReachabilityEndpoint'
117117
{
118118
# content uploaded to endpoint
119119
}
@@ -129,7 +129,8 @@ the your target jar. If you are running into issues with reachability, please co
129129

130130
```bash
131131
# get what we sent to endpoint
132-
cat fossa.debug.json | jq '.bundleReachabilityEndpoint' > rawReachabilityJob.json
132+
133+
unzip -p fossa.debug.zip fossa.debug.json | jq '.bundleReachabilityEndpoint' > rawReachabilityJob.json
133134
134135
# run job in dry mode
135136
>> yarn repl
@@ -183,7 +184,7 @@ You can inspect the data by running:
183184

184185
```bash
185186
; fossa analyze --output --debug # --output to not communicate with endpoint
186-
; gunzip fossa.debug.json.gz # extract produced debug bundle
187+
; unzip fossa.debug.zip fossa.debug.json # extract produced debug bundle
187188

188189
# content in .bundleReachabilityRaw is uploaded
189190
# to endpoint for reachability analysis.

docs/references/debugging/README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ This reference describes how to debug it and in what situations you may want to.
66
The intended audience for this reference is both FOSSA employees and any users
77
who want to debug FOSSA CLI themselves.
88

9-
If you are a reader inside or outside the FOSSA organization and see anything
10-
that could be improved in this document, please open a pull request or
9+
If you are a reader inside or outside the FOSSA organization and see anything
10+
that could be improved in this document, please open a pull request or
1111
drop us a note on [support.fossa.com](https://support.fossa.com)!
1212

1313
## Using this reference
@@ -93,21 +93,29 @@ fossa analyze --debug
9393

9494
After this has run, a new file is created in the current
9595
working directory (the directory from which you launched `fossa`).
96-
This file is titled `fossa.debug.json.gz`.
96+
This file is titled `fossa.debug.zip`. Its contents can vary depending on the exact command you are running.
97+
But it will almost always contain the debug bundle in fossa.debug.json.
9798

9899
### Extracting a debug bundle
99100

100-
The FOSSA CLI debug bundle is a gzipped JSON file,
101-
so can be extracted with just `gzip`:
101+
The FOSSA CLI debug bundle is a JSON file inside of fossa.debug.zip,
102+
103+
If you want to extract every file in the zip:
104+
105+
```
106+
; unzip fossa.debug.zip
107+
```
108+
109+
110+
If you only want the debug bundle, you can use
102111
```
103-
; gunzip fossa.debug.json.gz
112+
; unzip fossa.debug.zip fossa.debug.json
104113
```
105114

106-
If you also want the JSON to be formatted,
107-
you can do this in a single line
115+
If you also want the JSON to be formatted, you can do this in a single line
108116
(if you have `jq` installed):
109117
```
110-
; gunzip fossa.debug.json.gz --to-stdout | jq > fossa.debug.json
118+
; unzip -p fossa.debug.zip fossa.debug.json | jq > fossa.debug.json
111119
```
112120

113121
### Reading a debug bundle

integration-test/Analysis/FicusSpec.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ spec = do
5151
testDataExists <- PIO.doesDirExist testDataDir
5252
testDataExists `shouldBe` True
5353

54-
result <- runStack . runDiagnostics . ignoreStickyLogger . ignoreLogger . runExecIO . runReadFSIO $ analyzeWithFicus testDataDir apiOpts revision Nothing (Just 10)
54+
result <- runStack . runDiagnostics . ignoreStickyLogger . ignoreLogger . runExecIO . runReadFSIO $ analyzeWithFicus testDataDir apiOpts revision Nothing (Just 10) Nothing
5555

5656
case result of
5757
Success _warnings analysisResult -> do

integration-test/Container/AnalysisSpec.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import Container.Types (
1414
)
1515
import Data.Flag (toFlag')
1616
import Diag.Result (Result (..))
17-
import Effect.Logger (Severity (SevInfo))
1817
import Test.Hspec (Spec, aroundAll, describe, it, shouldBe, shouldSatisfy)
1918

2019
spec :: Spec
@@ -30,10 +29,10 @@ registrySourceCfg =
3029
, usesExperimentalScanner = True
3130
, dockerHost = ""
3231
, arch = "amd64"
33-
, severity = SevInfo
3432
, onlySystemDeps = False
3533
, filterSet = mempty
3634
, withoutDefaultFilters = toFlag' False
35+
, debugDir = Nothing
3736
}
3837

3938
runAnalyze :: ContainerAnalyzeConfig -> (ContainerScan -> IO ()) -> IO ()

spectrometer.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ library
243243
App.Fossa.Container.Sources.Podman
244244
App.Fossa.Container.Sources.Registry
245245
App.Fossa.Container.Test
246+
App.Fossa.DebugDir
246247
App.Fossa.DependencyMetadata
247248
App.Fossa.DumpBinaries
248249
App.Fossa.EmbeddedBinary

0 commit comments

Comments
 (0)