Commit 58298749 authored by Sarah GP's avatar Sarah GP

Add paths, utils for polling

Involves all files invoking the graph
parent 0658a194
...@@ -15,6 +15,13 @@ export default { ...@@ -15,6 +15,13 @@ export default {
StageColumnComponent, StageColumnComponent,
}, },
props: { props: {
configPaths: {
type: Object,
required: true,
validator: function(value) {
return Object.keys(value).includes('graphqlResourceEtag');
}
},
pipeline: { pipeline: {
type: Object, type: Object,
required: true, required: true,
...@@ -24,11 +31,6 @@ export default { ...@@ -24,11 +31,6 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
metricsPath: {
type: String,
required: false,
default: '',
},
type: { type: {
type: String, type: String,
required: false, required: false,
...@@ -73,7 +75,7 @@ export default { ...@@ -73,7 +75,7 @@ export default {
}, },
metricsConfig() { metricsConfig() {
return { return {
path: this.metricsPath, path: this.configPaths.metricsPath,
collectMetrics: true, collectMetrics: true,
}; };
}, },
...@@ -142,6 +144,7 @@ export default { ...@@ -142,6 +144,7 @@ export default {
<template #upstream> <template #upstream>
<linked-pipelines-column <linked-pipelines-column
v-if="showUpstreamPipelines" v-if="showUpstreamPipelines"
:config-paths="configPaths"
:linked-pipelines="upstreamPipelines" :linked-pipelines="upstreamPipelines"
:column-title="__('Upstream')" :column-title="__('Upstream')"
:type="$options.pipelineTypeConstants.UPSTREAM" :type="$options.pipelineTypeConstants.UPSTREAM"
...@@ -182,6 +185,7 @@ export default { ...@@ -182,6 +185,7 @@ export default {
<linked-pipelines-column <linked-pipelines-column
v-if="showDownstreamPipelines" v-if="showDownstreamPipelines"
class="gl-mr-6" class="gl-mr-6"
:config-paths="configPaths"
:linked-pipelines="downstreamPipelines" :linked-pipelines="downstreamPipelines"
:column-title="__('Downstream')" :column-title="__('Downstream')"
:type="$options.pipelineTypeConstants.DOWNSTREAM" :type="$options.pipelineTypeConstants.DOWNSTREAM"
......
...@@ -4,7 +4,12 @@ import getPipelineDetails from 'shared_queries/pipelines/get_pipeline_details.qu ...@@ -4,7 +4,12 @@ import getPipelineDetails from 'shared_queries/pipelines/get_pipeline_details.qu
import { __ } from '~/locale'; import { __ } from '~/locale';
import { DEFAULT, DRAW_FAILURE, LOAD_FAILURE } from '../../constants'; import { DEFAULT, DRAW_FAILURE, LOAD_FAILURE } from '../../constants';
import PipelineGraph from './graph_component.vue'; import PipelineGraph from './graph_component.vue';
import { unwrapPipelineData, toggleQueryPollingByVisibility, reportToSentry } from './utils'; import {
getQueryHeaders,
reportToSentry,
toggleQueryPollingByVisibility,
unwrapPipelineData
} from './utils';
export default { export default {
name: 'PipelineGraphWrapper', name: 'PipelineGraphWrapper',
...@@ -14,6 +19,9 @@ export default { ...@@ -14,6 +19,9 @@ export default {
PipelineGraph, PipelineGraph,
}, },
inject: { inject: {
graphqlResourceEtag: {
default: '',
},
metricsPath: { metricsPath: {
default: '', default: '',
}, },
...@@ -23,9 +31,6 @@ export default { ...@@ -23,9 +31,6 @@ export default {
pipelineProjectPath: { pipelineProjectPath: {
default: '', default: '',
}, },
graphqlResourceEtag: {
default: '',
},
}, },
data() { data() {
return { return {
...@@ -42,16 +47,7 @@ export default { ...@@ -42,16 +47,7 @@ export default {
apollo: { apollo: {
pipeline: { pipeline: {
context() { context() {
return { return getQueryHeaders(this.graphqlResourceEtag);
fetchOptions: {
method: 'GET',
},
headers: {
'X-GITLAB-GRAPHQL-FEATURE-CORRELATION': 'verify/ci/pipeline-graph',
'X-GITLAB-GRAPHQL-RESOURCE-ETAG': this.graphqlResourceEtag,
'X-REQUESTED_WITH': 'XMLHttpRequest',
},
};
}, },
query: getPipelineDetails, query: getPipelineDetails,
pollInterval: 10000, pollInterval: 10000,
...@@ -89,6 +85,12 @@ export default { ...@@ -89,6 +85,12 @@ export default {
}; };
} }
}, },
configPaths(){
return {
graphqlResourceEtag: this.graphqlResourceEtag,
metricsPath: this.metricsPath,
};
},
showLoadingIcon() { showLoadingIcon() {
/* /*
Shows the icon only when the graph is empty, not when it is is Shows the icon only when the graph is empty, not when it is is
...@@ -126,7 +128,7 @@ export default { ...@@ -126,7 +128,7 @@ export default {
<gl-loading-icon v-if="showLoadingIcon" class="gl-mx-auto gl-my-4" size="lg" /> <gl-loading-icon v-if="showLoadingIcon" class="gl-mx-auto gl-my-4" size="lg" />
<pipeline-graph <pipeline-graph
v-if="pipeline" v-if="pipeline"
:metrics-path="metricsPath" :config-paths="configPaths"
:pipeline="pipeline" :pipeline="pipeline"
@error="reportFailure" @error="reportFailure"
@refreshPipelineGraph="refreshPipelineGraph" @refreshPipelineGraph="refreshPipelineGraph"
......
...@@ -3,7 +3,12 @@ import getPipelineDetails from 'shared_queries/pipelines/get_pipeline_details.qu ...@@ -3,7 +3,12 @@ import getPipelineDetails from 'shared_queries/pipelines/get_pipeline_details.qu
import { LOAD_FAILURE } from '../../constants'; import { LOAD_FAILURE } from '../../constants';
import { ONE_COL_WIDTH, UPSTREAM } from './constants'; import { ONE_COL_WIDTH, UPSTREAM } from './constants';
import LinkedPipeline from './linked_pipeline.vue'; import LinkedPipeline from './linked_pipeline.vue';
import { unwrapPipelineData, toggleQueryPollingByVisibility, reportToSentry } from './utils'; import {
getQueryHeaders,
reportToSentry,
toggleQueryPollingByVisibility,
unwrapPipelineData
} from './utils';
export default { export default {
components: { components: {
...@@ -15,6 +20,13 @@ export default { ...@@ -15,6 +20,13 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
configPaths: {
type: Object,
required: true,
validator: function(value) {
return Object.keys(value).includes('graphqlResourceEtag');
}
},
linkedPipelines: { linkedPipelines: {
type: Array, type: Array,
required: true, required: true,
...@@ -73,16 +85,7 @@ export default { ...@@ -73,16 +85,7 @@ export default {
query: getPipelineDetails, query: getPipelineDetails,
pollInterval: 10000, pollInterval: 10000,
context() { context() {
return { return getQueryHeaders(this.configPaths.graphqlResourceEtag);
fetchOptions: {
method: 'GET',
},
headers: {
'X-GITLAB-GRAPHQL-FEATURE-CORRELATION': 'verify/ci/pipeline-graph',
'X-GITLAB-GRAPHQL-RESOURCE-ETAG': this.graphqlResourceEtag,
'X-REQUESTED_WITH': 'XMLHttpRequest',
},
}
}, },
variables() { variables() {
return { return {
...@@ -187,6 +190,7 @@ export default { ...@@ -187,6 +190,7 @@ export default {
v-if="isExpanded(pipeline.id)" v-if="isExpanded(pipeline.id)"
:type="type" :type="type"
class="d-inline-block gl-mt-n2" class="d-inline-block gl-mt-n2"
:config-paths="configPaths"
:pipeline="currentPipeline" :pipeline="currentPipeline"
:is-linked-pipeline="true" :is-linked-pipeline="true"
/> />
......
...@@ -10,6 +10,39 @@ const addMulti = (mainPipelineProjectPath, linkedPipeline) => { ...@@ -10,6 +10,39 @@ const addMulti = (mainPipelineProjectPath, linkedPipeline) => {
}; };
}; };
const getQueryHeaders = (etagResource) => {
return {
fetchOptions: {
method: 'GET',
},
headers: {
'X-GITLAB-GRAPHQL-FEATURE-CORRELATION': 'verify/ci/pipeline-graph',
'X-GITLAB-GRAPHQL-RESOURCE-ETAG': etagResource,
'X-REQUESTED_WITH': 'XMLHttpRequest',
},
};
};
const reportToSentry = (component, failureType) => {
Sentry.withScope((scope) => {
scope.setTag('component', component);
Sentry.captureException(failureType);
});
};
const toggleQueryPollingByVisibility = (queryRef, interval = 10000) => {
const stopStartQuery = (query) => {
if (!Visibility.hidden()) {
query.startPolling(interval);
} else {
query.stopPolling();
}
};
stopStartQuery(queryRef);
Visibility.change(stopStartQuery.bind(null, queryRef));
};
const transformId = (linkedPipeline) => { const transformId = (linkedPipeline) => {
return { ...linkedPipeline, id: getIdFromGraphQLId(linkedPipeline.id) }; return { ...linkedPipeline, id: getIdFromGraphQLId(linkedPipeline.id) };
}; };
...@@ -42,24 +75,4 @@ const unwrapPipelineData = (mainPipelineProjectPath, data) => { ...@@ -42,24 +75,4 @@ const unwrapPipelineData = (mainPipelineProjectPath, data) => {
}; };
}; };
const toggleQueryPollingByVisibility = (queryRef, interval = 10000) => { export { getQueryHeaders, reportToSentry, toggleQueryPollingByVisibility, unwrapPipelineData };
const stopStartQuery = (query) => {
if (!Visibility.hidden()) {
query.startPolling(interval);
} else {
query.stopPolling();
}
};
stopStartQuery(queryRef);
Visibility.change(stopStartQuery.bind(null, queryRef));
};
export { unwrapPipelineData, toggleQueryPollingByVisibility };
export const reportToSentry = (component, failureType) => {
Sentry.withScope((scope) => {
scope.setTag('component', component);
Sentry.captureException(failureType);
});
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment