-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Faro - Point to 3 separate apps instead of just 1 for all environments (
#1110) # What this PR does - App will now send traces to either of the Faro configured apps: `grafana-oncall-dev`, `grafana-oncall-ops` or `grafana-oncall-prod` instead of just `grafana-oncall` for all of 3. - Added tests to reflect latest changes
- Loading branch information
Showing
4 changed files
with
108 additions
and
119 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
import plugin from '../../package.json'; // eslint-disable-line | ||
|
||
// Navbar | ||
export const APP_TITLE = 'Grafana OnCall'; | ||
export const APP_SUBTITLE = `Developer-friendly incident response (${plugin?.version})`; | ||
|
||
// License | ||
export const GRAFANA_LICENSE_OSS = 'OpenSource'; | ||
|
||
// Reusable breakpoint sizes | ||
export const BREAKPOINT_TABS = 1024; | ||
|
||
// Default redirect page | ||
export const DEFAULT_PAGE = 'incidents'; | ||
|
||
// Environment options list for onCallApiUrl | ||
export const ONCALL_PROD = 'https://oncall-prod-us-central-0.grafana.net/oncall'; | ||
export const ONCALL_OPS = 'https://oncall-ops-us-east-0.grafana.net/oncall'; | ||
export const ONCALL_DEV = 'https://oncall-dev-us-central-0.grafana.net/oncall'; | ||
|
||
// Faro | ||
export const FARO_ENDPOINT_DEV = | ||
'https://faro-collector-prod-us-central-0.grafana.net/collect/fb03e474a96cf867f4a34590c002984c'; | ||
export const FARO_ENDPOINT_OPS = | ||
'https://faro-collector-prod-us-central-0.grafana.net/collect/40ccaafad6b71aa90fc53c3b0a1adb31'; | ||
export const FARO_ENDPOINT_PROD = | ||
'https://faro-collector-prod-us-central-0.grafana.net/collect/03a11ed03c3af04dcfc3be9755f2b053'; |
This file was deleted.
Oops, something went wrong.
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,65 @@ | ||
import 'jest/matchMedia.ts'; | ||
import { describe, test } from '@jest/globals'; | ||
|
||
import FaroHelper from 'utils/faro'; | ||
|
||
import '@testing-library/jest-dom'; | ||
import { ONCALL_DEV, ONCALL_OPS, ONCALL_PROD } from './consts'; | ||
|
||
const ErrorMock = jest.spyOn(window, 'Error'); | ||
|
||
jest.mock('@grafana/faro-web-sdk', () => ({ | ||
initializeFaro: jest.fn().mockReturnValue({ | ||
api: { | ||
pushLog: jest.fn(), | ||
}, | ||
}), | ||
getWebInstrumentations: () => [], | ||
})); | ||
|
||
jest.mock('@grafana/faro-web-tracing', () => ({ | ||
TracingInstrumentation: jest.fn(), | ||
})); | ||
jest.mock('@opentelemetry/instrumentation-document-load', () => ({ | ||
DocumentLoadInstrumentation: jest.fn(), | ||
})); | ||
jest.mock('@opentelemetry/instrumentation-fetch', () => ({ | ||
FetchInstrumentation: jest.fn(), | ||
})); | ||
|
||
describe('Faro', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
FaroHelper.faro = undefined; | ||
}); | ||
|
||
test.each([ONCALL_DEV, ONCALL_OPS, ONCALL_PROD])('It initializes faro for environment %s', (onCallApiUrl) => { | ||
const faro = FaroHelper.initializeFaro(onCallApiUrl); | ||
expect(faro).toBeDefined(); | ||
expect(ErrorMock).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test.each(['https://test.com', 'http://localhost:3000'])( | ||
'It fails initializing for dummy environment values', | ||
(onCallApiUrl) => { | ||
const faro = FaroHelper.initializeFaro(onCallApiUrl); | ||
expect(faro).toBeUndefined(); | ||
} | ||
); | ||
|
||
test('It does not reinitialize faro instance if already initialized', () => { | ||
const instance = FaroHelper.initializeFaro(ONCALL_DEV); | ||
expect(instance).toBeDefined(); | ||
|
||
const result = FaroHelper.initializeFaro(ONCALL_PROD); | ||
expect(result).toBeUndefined(); | ||
expect(FaroHelper.faro).toBe(instance); | ||
}); | ||
|
||
test('Initializer throws error for wrong env value', () => { | ||
const faro = FaroHelper.initializeFaro('https://test.com'); | ||
expect(ErrorMock).toHaveBeenCalledWith(`No match found for given onCallApiUrl = https://test.com`); | ||
expect(faro).toBeUndefined(); | ||
}); | ||
}); |
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