Skip to content

Commit

Permalink
grafana improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
dvalleri committed Aug 9, 2024
1 parent a38ae7c commit a1180b4
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
2 changes: 2 additions & 0 deletions ui/src/api/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { grafanaTracking } from '@Src/main';
import axios from 'axios';

export const customBaseQuery = () => async ({
Expand All @@ -23,6 +24,7 @@ export const customBaseQuery = () => async ({
return { data: result.data };
} catch (axiosError) {
const err = axiosError;
grafanaTracking?.api.pushError(axiosError);

return {
error: { status: err.response?.status, data: err.response?.data },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Select,
Tooltip,
} from '@radicalbit/radicalbit-design-system';
import { grafanaTracking } from '@Src/main';
import { useModalContext } from '../modal-context-provider';

function Target() {
Expand All @@ -28,6 +29,7 @@ function Target() {
write('target', JSON.parse(val));
} catch (e) {
console.error('Error in parsing Select.Option value: ', e);
grafanaTracking?.api.pushError(e);
}
};

Expand Down Expand Up @@ -124,6 +126,7 @@ function Timestamp() {
write('timestamp', JSON.parse(val));
} catch (e) {
console.error('Error in parsing Select.Option value: ', e);
grafanaTracking?.api.pushError(e);
}
};

Expand Down Expand Up @@ -220,6 +223,7 @@ function Prediction() {
write('prediction', JSON.parse(val));
} catch (e) {
console.error('Error in parsing Select.Option value: ', e);
grafanaTracking?.api.pushError(e);
}
};

Expand Down Expand Up @@ -319,6 +323,7 @@ function Probability() {
write('predictionProba', JSON.parse(val));
} catch (e) {
console.error('Error in parsing Select.Option value: ', e);
grafanaTracking?.api.pushError(e);
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { modelsApiSlice } from '@State/models/api';
import { useCallback } from 'react';
import { grafanaTracking } from '@Src/main';
import { useModalContext } from '../modal-context-provider';

const { useInferSchemaMutation } = modelsApiSlice;
Expand Down Expand Up @@ -66,6 +67,7 @@ export default () => {
} catch (e) {
const parsedErrorMessage = parseErrorMessage(e);
console.error(e);
grafanaTracking?.api.pushError(e);

setError('silent.backend', parsedErrorMessage);
write('file', { ...form.file, status: 'error', response: parsedErrorMessage });
Expand Down
3 changes: 3 additions & 0 deletions ui/src/helpers/queryParams.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { grafanaTracking } from '@Src/main';

const qs = (param) => new URLSearchParams(window.location.search).get(param);

const qsContextConfiguration = () => {
Expand Down Expand Up @@ -26,6 +28,7 @@ const qsEncode64JSON = (search, param) => {
return JSON.parse(qsAtob);
} catch (e) {
console.warn('Error in parsing qsEncode64JSON: ', e);
grafanaTracking?.api.pushError(e);
return {};
}
};
Expand Down
34 changes: 21 additions & 13 deletions ui/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,28 @@ import App from './container/app';
import { modelsRoutes } from './container/models/routes';
import { store } from './store/configureStore';

const getGrafanaTracking = (enableGrafanaTracking) => {
let tracking;

if (enableGrafanaTracking === 'true') {
if (tracking === undefined) {
tracking = initializeFaro({
url: 'https://telemetry.oss.radicalbit.ai',
apiKey: 'rbitoss-JpIYMVC677edETUbJN9Me3iLS7ngGaE2RYLzQWCOYVljUJh5JJk5o2FE',
app: { name: 'radicalbit-ai-monitoring' },
sessionTracking: {
enabled: true,
persistent: true,
maxSessionPersistenceTime: 31540000000, // 1 year
},
});
}
}
return tracking;
};

const enableGrafanaTracking = getCookieConsentValue('rbit-tracking');
export const grafanaTracking = getGrafanaTracking(enableGrafanaTracking);

const router = createBrowserRouter([
{
Expand All @@ -22,19 +43,6 @@ const router = createBrowserRouter([
},
]);

if (enableGrafanaTracking === 'true') {
initializeFaro({
// required: the URL of the Grafana collector
url: 'https://telemetry.oss.radicalbit.ai',
apiKey: 'rbitoss-JpIYMVC677edETUbJN9Me3iLS7ngGaE2RYLzQWCOYVljUJh5JJk5o2FE',

// required: the identification label of your application
app: {
name: 'radicalbit-ai-monitoring',
},
});
}

const browserRouter = (enableGrafanaTracking === 'true') ? withFaroRouterInstrumentation(router) : router;

ReactDOM.createRoot(document.getElementById('root')).render(
Expand Down
2 changes: 2 additions & 0 deletions ui/src/store/state/context-configuration/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { qsSetEncode64JSON } from '@Helpers/queryParams';
import { actions as notificationActions } from '@State/notification';
import { createAsyncThunk } from '@reduxjs/toolkit';
import { isEqual } from 'lodash';
import { grafanaTracking } from '@Src/main';
import contextConfigurationSelectors from './selectors';

const { selectContextConfiguration } = contextConfigurationSelectors;
Expand Down Expand Up @@ -42,6 +43,7 @@ const changeContextConfiguration = createAsyncThunk(
return fulfillWithValue(newConfiguration);
} catch (e) {
console.error(e);
grafanaTracking?.api.pushError(e);
const notificationMessage = notificationErrorJson(e);
dispatch(setNotificationMessage(notificationMessage));

Expand Down

0 comments on commit a1180b4

Please sign in to comment.