Skip to content

Commit

Permalink
[8.11] [EBT] Click's target circuit-breakers (elastic#170440) (elasti…
Browse files Browse the repository at this point in the history
…c#170509)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[EBT] Click's target circuit-breakers
(elastic#170440)](elastic#170440)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Alejandro Fernández
Haro","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-11-03T11:21:26Z","message":"[EBT]
Click's target circuit-breakers
(elastic#170440)","sha":"52aec54df4bc75b5feb8485487aa8aae21236494","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","Feature:Telemetry","release_note:skip","telemetry","backport:prev-minor","v8.12.0"],"number":170440,"url":"https://github.com/elastic/kibana/pull/170440","mergeCommit":{"message":"[EBT]
Click's target circuit-breakers
(elastic#170440)","sha":"52aec54df4bc75b5feb8485487aa8aae21236494"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/170440","number":170440,"mergeCommit":{"message":"[EBT]
Click's target circuit-breakers
(elastic#170440)","sha":"52aec54df4bc75b5feb8485487aa8aae21236494"}}]}]
BACKPORT-->

Co-authored-by: Alejandro Fernández Haro <[email protected]>
  • Loading branch information
kibanamachine and afharo authored Nov 3, 2023
1 parent 80840ed commit 414848c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,38 @@ describe('trackClicks', () => {
`);
});

test('trims values longer than 256 chars', async () => {
// Gather an actual "click" event
const event$ = new ReplaySubject<MouseEvent>(1);
const parent = document.createElement('div');
parent.setAttribute('data-test-subj', 'test-click-target-parent');
const element = document.createElement('button');
parent.appendChild(element);
const reallyLongText = `test-click-target-${new Array(10000).fill('0').join('')}`;
element.setAttribute('data-test-subj', reallyLongText);
element.innerText = 'test'; // Only to validate that it is not included in the event.
element.value = 'test'; // Only to validate that it is not included in the event.
element.addEventListener('click', (e) => event$.next(e));
element.click();
// Using an observable because the event might not be immediately available
const event = await firstValueFrom(event$.pipe(take(1)));
event$.complete(); // No longer needed

trackClicks(analyticsClientMock, true);
expect(addEventListenerSpy).toHaveBeenCalledTimes(1);

(addEventListenerSpy.mock.calls[0][1] as EventListener)(event);
expect(analyticsClientMock.reportEvent).toHaveBeenCalledTimes(1);
expect(analyticsClientMock.reportEvent).toHaveBeenCalledWith('click', {
target: [
'DIV',
'data-test-subj=test-click-target-parent',
'BUTTON',
`data-test-subj=test-click-target-${new Array(256 - 33).fill('0').join('')}`,
],
});
});

test('swallows any processing errors when not in dev mode', async () => {
trackClicks(analyticsClientMock, false);
expect(addEventListenerSpy).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const HTML_ATTRIBUTES_TO_REMOVE = [
'data-rfd-draggable-id',
'href',
'value',
'title',
];

/**
Expand Down Expand Up @@ -81,6 +82,6 @@ function getTargetDefinition(target: HTMLElement): string[] {
target.tagName,
...[...target.attributes]
.filter((attr) => !HTML_ATTRIBUTES_TO_REMOVE.includes(attr.name))
.map((attr) => `${attr.name}=${attr.value}`),
.map((attr) => `${attr.name}=${attr.value}`.slice(0, 256)),
];
}

0 comments on commit 414848c

Please sign in to comment.