Add latest changes from gitlab-org/gitlab@master

This commit is contained in:
GitLab Bot 2022-06-05 18:08:59 +00:00
parent 118f3e3bdb
commit 36d0a94b85
9 changed files with 41 additions and 16 deletions

View File

@ -166,6 +166,7 @@ export default (resolvers = {}, config = {}) => {
PerformanceBarService.interceptor({ PerformanceBarService.interceptor({
config: { config: {
url: httpResponse.url, url: httpResponse.url,
operationName: operation.operationName,
}, },
headers: { headers: {
'x-request-id': httpResponse.headers.get('x-request-id'), 'x-request-id': httpResponse.headers.get('x-request-id'),

View File

@ -121,7 +121,7 @@ export default {
return window.URL.createObjectURL(blob); return window.URL.createObjectURL(blob);
}, },
downloadName() { downloadName() {
const fileName = this.requests[0].truncatedUrl; const fileName = this.requests[0].displayName;
return `${fileName}_perf_bar_${Date.now()}.json`; return `${fileName}_perf_bar_${Date.now()}.json`;
}, },
memoryReportPath() { memoryReportPath() {

View File

@ -31,7 +31,7 @@ export default {
:value="request.id" :value="request.id"
data-qa-selector="request_dropdown_option" data-qa-selector="request_dropdown_option"
> >
{{ request.truncatedUrl }} {{ request.displayName }}
</option> </option>
</select> </select>
</div> </div>

View File

@ -56,12 +56,12 @@ const initPerformanceBar = (el) => {
this.addRequest(urlOrRequestId, urlOrRequestId); this.addRequest(urlOrRequestId, urlOrRequestId);
} }
}, },
addRequest(requestId, requestUrl) { addRequest(requestId, requestUrl, operationName) {
if (!this.store.canTrackRequest(requestUrl)) { if (!this.store.canTrackRequest(requestUrl)) {
return; return;
} }
this.store.addRequest(requestId, requestUrl); this.store.addRequest(requestId, requestUrl, operationName);
}, },
loadRequestDetails(requestId) { loadRequestDetails(requestId) {
const request = this.store.findRequest(requestId); const request = this.store.findRequest(requestId);

View File

@ -10,13 +10,15 @@ export default class PerformanceBarService {
static registerInterceptor(peekUrl, callback) { static registerInterceptor(peekUrl, callback) {
PerformanceBarService.interceptor = (response) => { PerformanceBarService.interceptor = (response) => {
const [fireCallback, requestId, requestUrl] = PerformanceBarService.callbackParams( const [
response, fireCallback,
peekUrl, requestId,
); requestUrl,
operationName,
] = PerformanceBarService.callbackParams(response, peekUrl);
if (fireCallback) { if (fireCallback) {
callback(requestId, requestUrl); callback(requestId, requestUrl, operationName);
} }
return response; return response;
@ -36,7 +38,8 @@ export default class PerformanceBarService {
const cachedResponse = const cachedResponse =
response.headers && parseBoolean(response.headers['x-gitlab-from-cache']); response.headers && parseBoolean(response.headers['x-gitlab-from-cache']);
const fireCallback = requestUrl !== peekUrl && Boolean(requestId) && !cachedResponse; const fireCallback = requestUrl !== peekUrl && Boolean(requestId) && !cachedResponse;
const operationName = response.config?.operationName;
return [fireCallback, requestId, requestUrl]; return [fireCallback, requestId, requestUrl, operationName];
} }
} }

View File

@ -3,15 +3,19 @@ export default class PerformanceBarStore {
this.requests = []; this.requests = [];
} }
addRequest(requestId, requestUrl) { addRequest(requestId, requestUrl, operationName) {
if (!this.findRequest(requestId)) { if (!this.findRequest(requestId)) {
const shortUrl = PerformanceBarStore.truncateUrl(requestUrl); let displayName = PerformanceBarStore.truncateUrl(requestUrl);
if (operationName) {
displayName += ` (${operationName})`;
}
this.requests.push({ this.requests.push({
id: requestId, id: requestId,
url: requestUrl, url: requestUrl,
truncatedUrl: shortUrl,
details: {}, details: {},
displayName,
}); });
} }

View File

@ -69,7 +69,7 @@ describe('performance bar wrapper', () => {
it('adds the request immediately', () => { it('adds the request immediately', () => {
vm.addRequest('123', 'https://gitlab.com/'); vm.addRequest('123', 'https://gitlab.com/');
expect(vm.store.addRequest).toHaveBeenCalledWith('123', 'https://gitlab.com/'); expect(vm.store.addRequest).toHaveBeenCalledWith('123', 'https://gitlab.com/', undefined);
}); });
}); });

View File

@ -63,5 +63,17 @@ describe('PerformanceBarService', () => {
); );
}); });
}); });
describe('operationName', () => {
function requestUrl(response, peekUrl) {
return PerformanceBarService.callbackParams(response, peekUrl)[3];
}
it('gets the operation name from response.config', () => {
expect(
requestUrl({ headers: {}, config: { operationName: 'someOperation' } }, '/peek'),
).toBe('someOperation');
});
});
}); });
}); });

View File

@ -1,9 +1,9 @@
import PerformanceBarStore from '~/performance_bar/stores/performance_bar_store'; import PerformanceBarStore from '~/performance_bar/stores/performance_bar_store';
describe('PerformanceBarStore', () => { describe('PerformanceBarStore', () => {
describe('truncateUrl', () => { describe('displayName', () => {
let store; let store;
const findUrl = (id) => store.findRequest(id).truncatedUrl; const findUrl = (id) => store.findRequest(id).displayName;
beforeEach(() => { beforeEach(() => {
store = new PerformanceBarStore(); store = new PerformanceBarStore();
@ -41,6 +41,11 @@ describe('PerformanceBarStore', () => {
store.addRequest('id', 'http://localhost:3001/h5bp/html5-boilerplate/#frag/ment'); store.addRequest('id', 'http://localhost:3001/h5bp/html5-boilerplate/#frag/ment');
expect(findUrl('id')).toEqual('html5-boilerplate'); expect(findUrl('id')).toEqual('html5-boilerplate');
}); });
it('appends the GraphQL operation name', () => {
store.addRequest('id', 'http://localhost:3001/api/graphql', 'someOperation');
expect(findUrl('id')).toBe('graphql (someOperation)');
});
}); });
describe('setRequestDetailsData', () => { describe('setRequestDetailsData', () => {