-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): Wizard - OTLP Test connection (#3540)
- Loading branch information
Showing
24 changed files
with
205 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
web/src/components/TestConnectionStatus/hooks/useTestConnnectionStatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import {Form} from 'antd'; | ||
import {useEffect, useMemo} from 'react'; | ||
import {useDataStore} from 'providers/DataStore/DataStore.provider'; | ||
import {TDraftDataStore} from 'types/DataStore.types'; | ||
import TracetestAPI from 'redux/apis/Tracetest/Tracetest.api'; | ||
import DataStoreService from 'services/DataStore.service'; | ||
|
||
export type TConnectionStatus = 'loading' | 'success' | 'error' | 'idle'; | ||
|
||
const useTestConnectionStatus = () => { | ||
// had to do this at this level because of this issue | ||
// https://github.com/reduxjs/redux-toolkit/issues/2055 | ||
const {useLazyTestOtlpConnectionQuery, useResetTestOtlpConnectionMutation} = TracetestAPI.instance; | ||
const [resetOtlpCount] = useResetTestOtlpConnectionMutation(); | ||
|
||
const {isTestConnectionLoading, resetTestConnection} = useDataStore(); | ||
const form = Form.useFormInstance<TDraftDataStore>(); | ||
const [testOtlpConnection, {isLoading, data: otlpResponse, isError}] = useLazyTestOtlpConnectionQuery({ | ||
pollingInterval: 1000, | ||
}); | ||
|
||
const status = useMemo<TConnectionStatus>(() => { | ||
if (isTestConnectionLoading || !otlpResponse?.spanCount) return 'loading'; | ||
if (!otlpResponse) return 'idle'; | ||
if (isError) return 'error'; | ||
|
||
return 'success'; | ||
}, [isError, isTestConnectionLoading, otlpResponse]); | ||
|
||
// listens to all form changes | ||
const data = Form.useWatch([], form); | ||
const isOtlpBased = useMemo(() => DataStoreService.getIsOtlpBased(form.getFieldsValue()), [data]); | ||
|
||
useEffect(() => { | ||
if (isOtlpBased) testOtlpConnection(undefined); | ||
}, [isOtlpBased]); | ||
|
||
useEffect(() => { | ||
return () => { | ||
resetOtlpCount(undefined); | ||
resetTestConnection(); | ||
}; | ||
}, []); | ||
Check warning on line 43 in web/src/components/TestConnectionStatus/hooks/useTestConnnectionStatus.ts GitHub Actions / WebUI unit tests
|
||
|
||
return {status, isOtlpBased, otlpResponse, isLoading: isLoading || isTestConnectionLoading}; | ||
}; | ||
|
||
export default useTestConnectionStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Model, TConfigSchemas} from 'types/Common.types'; | ||
|
||
export type TRawOTLPTestConnectionResponse = TConfigSchemas['OTLPTestConnectionResponse']; | ||
type OTLPTestConnectionResponse = Model<TRawOTLPTestConnectionResponse, {}>; | ||
|
||
const defaultOTLPTestConnectionResponse: TRawOTLPTestConnectionResponse = { | ||
spanCount: 0, | ||
lastSpanTimestamp: '', | ||
}; | ||
|
||
function OTLPTestConnectionResponse({ | ||
spanCount = 0, | ||
lastSpanTimestamp = '', | ||
} = defaultOTLPTestConnectionResponse): OTLPTestConnectionResponse { | ||
return { | ||
spanCount, | ||
lastSpanTimestamp, | ||
}; | ||
} | ||
|
||
export default OTLPTestConnectionResponse; |
Oops, something went wrong.