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

[No Ticket] resilience against api errors when retrieving endpoint version #1051

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# FOSSA CLI Changelog

## Unreleased
- FOSSA API: Adds resiliency against API errors occurring when retrieving endpoint versioning information. ([#1051](https://github.com/fossas/fossa-cli/pull/1051))

## v3.4.4
- Fix a bug in the v1 installers for Windows (install-v1.ps1 and install.ps1) ([#1052](https://github.com/fossas/fossa-cli/pull/1052))

Expand Down
5 changes: 4 additions & 1 deletion src/App/Fossa/Analyze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import Control.Carrier.TaskPool (
withTaskPool,
)
import Control.Concurrent (getNumCapabilities)
import Control.Effect.Diagnostics (recover)
import Control.Effect.Exception (Lift)
import Control.Effect.FossaApiClient (FossaApiClient, getEndpointVersion)
import Control.Effect.Git (Git)
Expand Down Expand Up @@ -312,7 +313,9 @@ analyze cfg = Diag.context "fossa-analyze" $ do

maybeEndpointAppVersion <- case destination of
UploadScan apiOpts _ -> runFossaApiClient apiOpts $ do
version <- getEndpointVersion
-- Using 'recovery' as API corresponding to 'getEndpointVersion',
-- seems to be not stable and we sometimes see TimeoutError in telemetry
version <- recover getEndpointVersion
Copy link
Contributor Author

Choose a reason for hiding this comment

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

refer to datadog / events cmd+f "ConnectionTimeout"

debugMetadata "FossaEndpointCoreVersion" version
pure version
_ -> pure Nothing
Expand Down
2 changes: 1 addition & 1 deletion src/Control/Carrier/FossaApiClient/Internal/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ getEndpointVersion ::
, Has Diagnostics sig m
, Has (Reader ApiOpts) sig m
) =>
m (Maybe Text)
m Text
getEndpointVersion = do
apiOpts <- ask
API.getEndpointVersion apiOpts
8 changes: 4 additions & 4 deletions src/Control/Carrier/FossaApiClient/Internal/FossaAPIV1.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import Container.Errors (EndpointDoesNotSupportNativeContainerScan (EndpointDoes
import Container.Types qualified as NativeContainer
import Control.Algebra (Algebra, Has, type (:+:))
import Control.Carrier.Empty.Maybe (Empty, EmptyC, runEmpty)
import Control.Effect.Diagnostics (Diagnostics, ToDiagnostic (..), context, fatal, fromMaybeText, warn)
import Control.Effect.Diagnostics (Diagnostics, ToDiagnostic (..), context, fatal, fatalText, fromMaybeText)
import Control.Effect.Empty (empty)
import Control.Effect.Lift (Lift, sendIO)
import Control.Exception (Exception (displayException), SomeException)
Expand Down Expand Up @@ -1221,10 +1221,10 @@ newtype AppManifest = AppManifest {endpointAppVersion :: Text} deriving (Show, E
instance FromXML AppManifest where
parseElement el = AppManifest <$> child "version" el

getEndpointVersion :: (Has (Lift IO) sig m, Has Diagnostics sig m) => ApiOpts -> m (Maybe Text)
getEndpointVersion :: (Has (Lift IO) sig m, Has Diagnostics sig m) => ApiOpts -> m Text
getEndpointVersion apiOpts = fossaReq $ do
(baseUrl, baseOpts) <- useApiOpts apiOpts
body <- responseBody <$> req GET (endpointAppManifest baseUrl) NoReqBody bsResponse baseOpts
case parseXML (decodeUtf8 body) of
Left err -> warn (xmlErrorPretty err) >> pure Nothing
Right (appManifest :: AppManifest) -> pure $ Just (endpointAppVersion appManifest)
Left err -> fatalText (xmlErrorPretty err)
Right (appManifest :: AppManifest) -> pure $ endpointAppVersion appManifest
4 changes: 2 additions & 2 deletions src/Control/Effect/FossaApiClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ data FossaApiClientF a where
GetApiOpts :: FossaApiClientF ApiOpts
GetAttribution :: ProjectRevision -> ReportOutputFormat -> FossaApiClientF Text
GetIssues :: ProjectRevision -> Maybe DiffRevision -> FossaApiClientF Issues
GetEndpointVersion :: FossaApiClientF (Maybe Text)
GetEndpointVersion :: FossaApiClientF Text
GetLatestBuild :: ProjectRevision -> FossaApiClientF Build
GetLatestScan :: Locator -> ProjectRevision -> FossaApiClientF ScanResponse
GetOrganization :: FossaApiClientF Organization
Expand Down Expand Up @@ -221,5 +221,5 @@ getVsiScanAnalysisStatus = sendSimple . GetVsiScanAnalysisStatus
getVsiInferences :: Has FossaApiClient sig m => VSI.ScanID -> m [Locator]
getVsiInferences = sendSimple . GetVsiInferences

getEndpointVersion :: Has FossaApiClient sig m => m (Maybe Text)
getEndpointVersion :: Has FossaApiClient sig m => m Text
getEndpointVersion = sendSimple GetEndpointVersion