Skip to content

Commit b6fbf30

Browse files
authored
Explore: Add checking for target datasources and add test (grafana#70855)
Add checking for target datasources and add test
1 parent ad5a36e commit b6fbf30

File tree

2 files changed

+85
-2
lines changed

2 files changed

+85
-2
lines changed

public/app/features/correlations/CorrelationsPage.test.tsx

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,82 @@ describe('CorrelationsPage', () => {
555555
});
556556
});
557557

558+
describe('With correlations with datasources the user cannot access', () => {
559+
let queryCellsByColumnName: (columnName: Matcher) => HTMLTableCellElement[];
560+
beforeEach(async () => {
561+
const renderResult = await renderWithContext(
562+
{
563+
loki: mockDataSource(
564+
{
565+
uid: 'loki',
566+
name: 'loki',
567+
readOnly: false,
568+
jsonData: {},
569+
access: 'direct',
570+
type: 'datasource',
571+
},
572+
{
573+
logs: true,
574+
}
575+
),
576+
},
577+
[
578+
{
579+
sourceUID: 'loki',
580+
targetUID: 'loki',
581+
uid: '1',
582+
label: 'Loki to Loki',
583+
config: {
584+
field: 'line',
585+
target: {},
586+
type: 'query',
587+
transformations: [
588+
{ type: SupportedTransformationType.Regex, expression: 'url=http[s]?://(S*)', mapValue: 'path' },
589+
],
590+
},
591+
},
592+
{
593+
sourceUID: 'loki',
594+
targetUID: 'prometheus',
595+
uid: '2',
596+
label: 'Loki to Prometheus',
597+
config: {
598+
field: 'line',
599+
target: {},
600+
type: 'query',
601+
transformations: [
602+
{ type: SupportedTransformationType.Regex, expression: 'url=http[s]?://(S*)', mapValue: 'path' },
603+
],
604+
},
605+
},
606+
{
607+
sourceUID: 'prometheus',
608+
targetUID: 'loki',
609+
uid: '3',
610+
label: 'Prometheus to Loki',
611+
config: { field: 'label', target: {}, type: 'query' },
612+
},
613+
{
614+
sourceUID: 'prometheus',
615+
targetUID: 'prometheus',
616+
uid: '4',
617+
label: 'Prometheus to Prometheus',
618+
config: { field: 'label', target: {}, type: 'query' },
619+
},
620+
]
621+
);
622+
queryCellsByColumnName = renderResult.queryCellsByColumnName;
623+
});
624+
625+
it("doesn't show correlations from source or target datasources the user doesn't have access to", async () => {
626+
await screen.findByRole('table');
627+
628+
const labels = queryCellsByColumnName('Label');
629+
expect(labels.length).toBe(1);
630+
expect(labels[0].textContent).toBe('Loki to Loki');
631+
});
632+
});
633+
558634
describe('Read only correlations', () => {
559635
const correlations: Correlation[] = [
560636
{

public/app/features/correlations/useCorrelations.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,18 @@ const toEnrichedCorrelationData = ({
4141
...correlation
4242
}: Correlation): CorrelationData | undefined => {
4343
const sourceDatasource = getDataSourceSrv().getInstanceSettings(sourceUID);
44-
if (sourceDatasource) {
44+
const targetDatasource = getDataSourceSrv().getInstanceSettings(targetUID);
45+
46+
if (
47+
sourceDatasource &&
48+
sourceDatasource?.uid !== undefined &&
49+
targetDatasource &&
50+
targetDatasource.uid !== undefined
51+
) {
4552
return {
4653
...correlation,
4754
source: sourceDatasource,
48-
target: getDataSourceSrv().getInstanceSettings(targetUID)!,
55+
target: targetDatasource,
4956
};
5057
} else {
5158
return undefined;

0 commit comments

Comments
 (0)