summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/performance_insights_modal.vue
blob: ae6b918693029af7ee4cf2c47b77cbfe70acc1ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<script>
import { GlAlert, GlCard, GlLink, GlLoadingIcon, GlModal } from '@gitlab/ui';
import { __, s__ } from '~/locale';
import { humanizeTimeInterval } from '~/lib/utils/datetime_utility';
import HelpPopover from '~/vue_shared/components/help_popover.vue';
import getPerformanceInsightsQuery from '../graphql/queries/get_performance_insights.query.graphql';
import { performanceModalId } from '../constants';
import { calculateJobStats, calculateSlowestFiveJobs } from '../utils';

export default {
  name: 'PerformanceInsightsModal',
  i18n: {
    queuedCardHeader: s__('Pipeline|Longest queued job'),
    queuedCardHelp: s__(
      'Pipeline|The longest queued job is the job that spent the longest time in the pending state, waiting to be picked up by a Runner',
    ),
    executedCardHeader: s__('Pipeline|Last executed job'),
    executedCardHelp: s__(
      'Pipeline|The last executed job is the last job to start in the pipeline.',
    ),
    viewDependency: s__('Pipeline|View dependency'),
    slowJobsTitle: s__('Pipeline|Five slowest jobs'),
    feeback: __('Feedback issue'),
    insightsLimit: s__('Pipeline|Only able to show first 100 results'),
  },
  modal: {
    title: s__('Pipeline|Performance insights'),
    actionCancel: {
      text: __('Close'),
      attributes: {
        variant: 'confirm',
      },
    },
  },
  performanceModalId,
  components: {
    GlAlert,
    GlCard,
    GlLink,
    GlModal,
    GlLoadingIcon,
    HelpPopover,
  },
  inject: {
    pipelineIid: {
      default: '',
    },
    pipelineProjectPath: {
      default: '',
    },
  },
  apollo: {
    jobs: {
      query: getPerformanceInsightsQuery,
      variables() {
        return {
          fullPath: this.pipelineProjectPath,
          iid: this.pipelineIid,
        };
      },
      update(data) {
        return data.project?.pipeline?.jobs;
      },
    },
  },
  data() {
    return {
      jobs: null,
    };
  },
  computed: {
    longestQueuedJob() {
      return calculateJobStats(this.jobs, 'queuedDuration');
    },
    lastExecutedJob() {
      return calculateJobStats(this.jobs, 'startedAt');
    },
    slowestFiveJobs() {
      return calculateSlowestFiveJobs(this.jobs);
    },
    queuedDurationDisplay() {
      return humanizeTimeInterval(this.longestQueuedJob.queuedDuration);
    },
    showLimitMessage() {
      return this.jobs.pageInfo.hasNextPage;
    },
  },
};
</script>

<template>
  <gl-modal
    :modal-id="$options.performanceModalId"
    :title="$options.modal.title"
    :action-cancel="$options.modal.actionCancel"
  >
    <gl-loading-icon v-if="$apollo.queries.jobs.loading" size="lg" />

    <template v-else>
      <gl-alert v-if="showLimitMessage" class="gl-mb-4" :dismissible="false">
        <p>{{ $options.i18n.insightsLimit }}</p>
        <gl-link href="https://gitlab.com/gitlab-org/gitlab/-/issues/365902" class="gl-mt-5">
          {{ $options.i18n.feeback }}
        </gl-link>
      </gl-alert>
      <div class="gl-display-flex gl-justify-content-space-between gl-mb-7">
        <gl-card class="gl-w-half gl-mr-7 gl-text-center">
          <template #header>
            <span class="gl-font-weight-bold">{{ $options.i18n.queuedCardHeader }}</span>
            <help-popover>
              {{ $options.i18n.queuedCardHelp }}
            </help-popover>
          </template>
          <div class="gl-display-flex gl-flex-direction-column">
            <span
              class="gl-font-weight-bold gl-font-size-h2 gl-mb-2"
              data-testid="insights-queued-card-data"
            >
              {{ queuedDurationDisplay }}
            </span>
            <gl-link
              :href="longestQueuedJob.detailedStatus.detailsPath"
              data-testid="insights-queued-card-link"
            >
              {{ longestQueuedJob.name }}
            </gl-link>
          </div>
        </gl-card>
        <gl-card class="gl-w-half gl-text-center" data-testid="insights-executed-card">
          <template #header>
            <span class="gl-font-weight-bold">{{ $options.i18n.executedCardHeader }}</span>
            <help-popover>
              {{ $options.i18n.executedCardHelp }}
            </help-popover>
          </template>
          <div class="gl-display-flex gl-flex-direction-column">
            <span
              class="gl-font-weight-bold gl-font-size-h2 gl-mb-2"
              data-testid="insights-executed-card-data"
            >
              {{ lastExecutedJob.name }}
            </span>
            <gl-link
              :href="lastExecutedJob.detailedStatus.detailsPath"
              data-testid="insights-executed-card-link"
            >
              {{ $options.i18n.viewDependency }}
            </gl-link>
          </div>
        </gl-card>
      </div>

      <div class="gl-mt-7">
        <span class="gl-font-weight-bold">{{ $options.i18n.slowJobsTitle }}</span>
        <div
          v-for="job in slowestFiveJobs"
          :key="job.name"
          class="gl-display-flex gl-justify-content-space-between gl-mb-3 gl-mt-3 gl-p-4 gl-border-t-1 gl-border-t-solid gl-border-b-0 gl-border-b-solid gl-border-gray-100"
        >
          <span data-testid="insights-slow-job-stage">{{ job.stage.name }}</span>
          <gl-link :href="job.detailedStatus.detailsPath" data-testid="insights-slow-job-link">{{
            job.name
          }}</gl-link>
        </div>
      </div>
    </template>
  </gl-modal>
</template>