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

performance_bar_app.vue « components « performance_bar « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c5f8fd1904f954c8674d330132bc7e4401060c82 (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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<script>
import { GlLink, GlTooltipDirective } from '@gitlab/ui';
import { mergeUrlParams } from '~/lib/utils/url_utility';

import { s__ } from '~/locale';
import AddRequest from './add_request.vue';
import DetailedMetric from './detailed_metric.vue';
import RequestSelector from './request_selector.vue';

export default {
  components: {
    AddRequest,
    DetailedMetric,
    GlLink,
    RequestSelector,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
  },
  props: {
    store: {
      type: Object,
      required: true,
    },
    env: {
      type: String,
      required: true,
    },
    requestId: {
      type: String,
      required: true,
    },
    requestMethod: {
      type: String,
      required: true,
    },
    peekUrl: {
      type: String,
      required: true,
    },
    statsUrl: {
      type: String,
      required: true,
    },
  },
  detailedMetrics: [
    {
      metric: 'active-record',
      title: 'pg',
      header: s__('PerformanceBar|SQL queries'),
      keys: ['sql', 'cached', 'transaction', 'db_role', 'db_config_name'],
    },
    {
      metric: 'bullet',
      header: s__('PerformanceBar|Bullet notifications'),
      keys: ['notification'],
    },
    {
      metric: 'gitaly',
      header: s__('PerformanceBar|Gitaly calls'),
      keys: ['feature', 'request'],
    },
    {
      metric: 'redis',
      header: s__('PerformanceBar|Redis calls'),
      keys: ['cmd', 'instance'],
    },
    {
      metric: 'es',
      header: s__('PerformanceBar|Elasticsearch calls'),
      keys: ['request', 'body'],
    },
    {
      metric: 'zkt',
      header: s__('PerformanceBar|Zoekt calls'),
      keys: ['request', 'body'],
    },
    {
      metric: 'ch',
      header: s__('PerformanceBar|ClickHouse queries'),
      keys: ['sql', 'database', 'statistics'],
    },
    {
      metric: 'external-http',
      title: 'external',
      header: s__('PerformanceBar|External Http calls'),
      keys: ['label', 'code', 'proxy', 'error'],
    },
    {
      metric: 'memory',
      header: s__('PerformanceBar|Memory'),
      keys: ['item_header', 'item_content'],
    },
    {
      metric: 'total',
      header: s__('PerformanceBar|Frontend resources'),
      keys: ['name', 'size'],
    },
  ],
  data() {
    return { currentRequestId: '' };
  },
  computed: {
    requests() {
      return this.store.requestsWithDetails();
    },
    currentRequest: {
      get() {
        return this.store.findRequest(this.currentRequestId);
      },
      set(requestId) {
        this.currentRequestId = requestId;
      },
    },
    hasHost() {
      return this.currentRequest && this.currentRequest.details && this.currentRequest.details.host;
    },
    isCanary() {
      return Boolean(this.currentRequest.details.host.canary);
    },
    downloadPath() {
      const data = JSON.stringify(this.requests);
      const blob = new Blob([data], { type: 'text/plain' });
      return window.URL.createObjectURL(blob);
    },
    downloadName() {
      const fileName = this.requests[0].displayName;
      return `${fileName}_perf_bar_${Date.now()}.json`;
    },
    showZoekt() {
      return document.body.dataset.page === 'search:show';
    },
    showFlamegraphButtons() {
      return this.isGetRequest(this.currentRequestId);
    },
    showMemoryReportButton() {
      return this.isGetRequest(this.currentRequestId) && this.env === 'development';
    },
    memoryReportPath() {
      return mergeUrlParams(
        { performance_bar: 'memory' },
        this.store.findRequest(this.currentRequestId).fullUrl,
      );
    },
  },
  created() {
    if (!this.showZoekt) {
      this.$options.detailedMetrics = this.$options.detailedMetrics.filter(
        (item) => item.metric !== 'zkt',
      );
    }
  },
  mounted() {
    this.currentRequest = this.requestId;
  },
  methods: {
    changeCurrentRequest(newRequestId) {
      this.currentRequest = newRequestId;
      this.$emit('change-request', newRequestId);
    },
    flamegraphPath(mode, requestId) {
      return mergeUrlParams(
        { performance_bar: 'flamegraph', stackprof_mode: mode },
        this.store.findRequest(requestId).fullUrl,
      );
    },
    isGetRequest(requestId) {
      return this.store.findRequest(requestId)?.method?.toUpperCase() === 'GET';
    },
  },
};
</script>
<template>
  <div id="js-peek" :class="env">
    <div
      v-if="currentRequest"
      class="gl-display-flex container-fluid gl-overflow-x-auto"
      data-qa-selector="performance_bar"
    >
      <div class="gl-display-flex gl-flex-shrink-0 view-performance-container">
        <div v-if="hasHost" id="peek-view-host" class="gl-display-flex gl-gap-2 view">
          <span class="current-host" :class="{ canary: isCanary }">
            <gl-emoji
              v-if="isCanary"
              id="canary-emoji"
              v-gl-tooltip.viewport="'Canary'"
              data-name="baby_chick"
            />
            <gl-emoji
              id="host-emoji"
              v-gl-tooltip.viewport="currentRequest.details.host.hostname"
              data-name="computer"
            />
          </span>
        </div>
        <detailed-metric
          v-for="metric in $options.detailedMetrics"
          :key="metric.metric"
          :current-request="currentRequest"
          :metric="metric.metric"
          :title="metric.title"
          :header="metric.header"
          :keys="metric.keys"
        />
        <div
          v-if="currentRequest.details && currentRequest.details.tracing"
          id="peek-view-trace"
          class="view"
        >
          <gl-link
            class="gl-text-decoration-underline"
            :href="currentRequest.details.tracing.tracing_url"
            >{{ s__('PerformanceBar|Trace') }}</gl-link
          >
        </div>
        <div v-if="showFlamegraphButtons" id="peek-flamegraph" class="view">
          <gl-link
            v-gl-tooltip.viewport
            class="gl-font-sm"
            :href="flamegraphPath('wall', currentRequestId)"
            :title="s__('PerformanceBar|Wall flamegraph')"
            >{{ s__('PerformanceBar|Wall') }}</gl-link
          >
          /
          <gl-link
            v-gl-tooltip.viewport
            class="gl-font-sm"
            :href="flamegraphPath('cpu', currentRequestId)"
            :title="s__('PerformanceBar|CPU flamegraph')"
            >{{ s__('PerformanceBar|CPU') }}</gl-link
          >
          /
          <gl-link
            v-gl-tooltip.viewport
            class="gl-font-sm"
            :href="flamegraphPath('object', currentRequestId)"
            :title="s__('PerformanceBar|Object flamegraph')"
            >{{ s__('PerformanceBar|Object') }}</gl-link
          >
          <span class="gl-opacity-7">{{ s__('PerformanceBar|flamegraph') }}</span>
        </div>
      </div>
      <div class="gl-display-flex gl-flex-shrink-0 gl-ml-auto">
        <div class="gl-display-flex view-reports-container">
          <gl-link
            v-if="currentRequest.details"
            id="peek-download"
            v-gl-tooltip.viewport
            class="view gl-font-sm"
            is-unsafe-link
            :download="downloadName"
            :href="downloadPath"
            :title="s__('PerformanceBar|Download report')"
            >{{ s__('PerformanceBar|Download') }}</gl-link
          >
          <gl-link
            v-if="showMemoryReportButton"
            id="peek-memory-report"
            v-gl-tooltip.viewport
            class="view gl-font-sm"
            :href="memoryReportPath"
            :title="s__('PerformanceBar|Download memory report')"
            >{{ s__('PerformanceBar|Memory report') }}</gl-link
          >
          <gl-link
            v-if="statsUrl"
            v-gl-tooltip.viewport
            class="view gl-font-sm"
            :href="statsUrl"
            :title="s__('PerformanceBar|Show stats')"
            >{{ s__('PerformanceBar|Stats') }}</gl-link
          >
        </div>
        <request-selector
          v-if="currentRequest"
          :current-request="currentRequest"
          :requests="requests"
          @change-current-request="changeCurrentRequest"
        />
        <add-request v-on="$listeners" />
      </div>
    </div>
  </div>
</template>