Welcome to mirror list, hosted at ThFree Co, Russian Federation.

links_layer.vue « graph_shared « components « pipelines « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8dbab245f4431d9dd3982d70796c5fbe07f15eea (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<script>
import { GlAlert } from '@gitlab/ui';
import { isEmpty } from 'lodash';
import { __ } from '~/locale';
import {
  PIPELINES_DETAIL_LINKS_MARK_CALCULATE_START,
  PIPELINES_DETAIL_LINKS_MARK_CALCULATE_END,
  PIPELINES_DETAIL_LINKS_MEASURE_CALCULATION,
  PIPELINES_DETAIL_LINK_DURATION,
  PIPELINES_DETAIL_LINKS_TOTAL,
  PIPELINES_DETAIL_LINKS_JOB_RATIO,
} from '~/performance/constants';
import { performanceMarkAndMeasure } from '~/performance/utils';
import { reportToSentry } from '../../utils';
import { parseData } from '../parsing_utils';
import { reportPerformance } from './api';
import LinksInner from './links_inner.vue';

export default {
  name: 'LinksLayer',
  components: {
    GlAlert,
    LinksInner,
  },
  MAX_GROUPS: 200,
  props: {
    containerMeasurements: {
      type: Object,
      required: true,
    },
    pipelineData: {
      type: Array,
      required: true,
    },
    metricsConfig: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    neverShowLinks: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      alertDismissed: false,
      showLinksOverride: false,
    };
  },
  i18n: {
    showLinksAnyways: __('Show links anyways'),
    tooManyJobs: __(
      'This graph has a large number of jobs and showing the links between them may have performance implications.',
    ),
  },
  computed: {
    containerZero() {
      return !this.containerMeasurements.width || !this.containerMeasurements.height;
    },
    numGroups() {
      return this.pipelineData.reduce((acc, { groups }) => {
        return acc + Number(groups.length);
      }, 0);
    },
    shouldCollectMetrics() {
      return this.metricsConfig.collectMetrics && this.metricsConfig.path;
    },
    showAlert() {
      /*
        This is a hard override that allows us to turn off the links without
        needing to remove the component entirely for iteration or based on graph type.
      */
      if (this.neverShowLinks) {
        return false;
      }

      return !this.containerZero && !this.showLinkedLayers && !this.alertDismissed;
    },
    showLinkedLayers() {
      /*
        This is a hard override that allows us to turn off the links without
        needing to remove the component entirely for iteration or based on graph type.
      */
      if (this.neverShowLinks) {
        return false;
      }

      return (
        !this.containerZero && (this.showLinksOverride || this.numGroups < this.$options.MAX_GROUPS)
      );
    },
  },
  errorCaptured(err, _vm, info) {
    reportToSentry(this.$options.name, `error: ${err}, info: ${info}`);
  },
  mounted() {
    /*
      This is code to get metrics for the graph (to observe links performance).
      It is currently here because we want values for links without drawing them.
      It can be removed when https://gitlab.com/gitlab-org/gitlab/-/issues/298930
      is closed and functionality is enabled by default.
    */

    if (this.neverShowLinks && !isEmpty(this.pipelineData)) {
      window.requestAnimationFrame(() => {
        this.prepareLinkData();
      });
    }
  },
  methods: {
    beginPerfMeasure() {
      if (this.shouldCollectMetrics) {
        performanceMarkAndMeasure({ mark: PIPELINES_DETAIL_LINKS_MARK_CALCULATE_START });
      }
    },
    finishPerfMeasureAndSend(numLinks) {
      if (this.shouldCollectMetrics) {
        performanceMarkAndMeasure({
          mark: PIPELINES_DETAIL_LINKS_MARK_CALCULATE_END,
          measures: [
            {
              name: PIPELINES_DETAIL_LINKS_MEASURE_CALCULATION,
              start: PIPELINES_DETAIL_LINKS_MARK_CALCULATE_START,
            },
          ],
        });
      }

      window.requestAnimationFrame(() => {
        const duration = window.performance.getEntriesByName(
          PIPELINES_DETAIL_LINKS_MEASURE_CALCULATION,
        )[0]?.duration;

        if (!duration) {
          return;
        }

        const data = {
          histograms: [
            { name: PIPELINES_DETAIL_LINK_DURATION, value: duration / 1000 },
            { name: PIPELINES_DETAIL_LINKS_TOTAL, value: numLinks },
            {
              name: PIPELINES_DETAIL_LINKS_JOB_RATIO,
              value: numLinks / this.numGroups,
            },
          ],
        };

        reportPerformance(this.metricsConfig.path, data);
      });
    },
    dismissAlert() {
      this.alertDismissed = true;
    },
    overrideShowLinks() {
      this.dismissAlert();
      this.showLinksOverride = true;
    },
    prepareLinkData() {
      this.beginPerfMeasure();
      let numLinks;
      try {
        const arrayOfJobs = this.pipelineData.flatMap(({ groups }) => groups);
        numLinks = parseData(arrayOfJobs).links.length;
      } catch (err) {
        reportToSentry(this.$options.name, err);
      }
      this.finishPerfMeasureAndSend(numLinks);
    },
  },
};
</script>
<template>
  <links-inner
    v-if="showLinkedLayers"
    :container-measurements="containerMeasurements"
    :pipeline-data="pipelineData"
    :total-groups="numGroups"
    :metrics-config="metricsConfig"
    v-bind="$attrs"
    v-on="$listeners"
  >
    <slot></slot>
  </links-inner>
  <div v-else>
    <gl-alert
      v-if="showAlert"
      class="gl-ml-4 gl-mb-4"
      :primary-button-text="$options.i18n.showLinksAnyways"
      @primaryAction="overrideShowLinks"
      @dismiss="dismissAlert"
    >
      {{ $options.i18n.tooManyJobs }}
    </gl-alert>
    <div class="gl-display-flex gl-relative">
      <slot></slot>
    </div>
  </div>
</template>