summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/performance_bar/components/performance_bar_app.vue
blob: b76965f280b4ff7e4d83e5199d50d2432cc734cc (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
<script>
import $ from 'jquery';

import PerformanceBarService from '../services/performance_bar_service';
import detailedMetric from './detailed_metric.vue';
import requestSelector from './request_selector.vue';
import simpleMetric from './simple_metric.vue';

import Flash from '../../flash';

export default {
  components: {
    detailedMetric,
    requestSelector,
    simpleMetric,
  },
  props: {
    store: {
      type: Object,
      required: true,
    },
    env: {
      type: String,
      required: true,
    },
    requestId: {
      type: String,
      required: true,
    },
    peekUrl: {
      type: String,
      required: true,
    },
    profileUrl: {
      type: String,
      required: true,
    },
  },
  detailedMetrics: [
    { metric: 'pg', header: 'SQL queries', details: 'queries', keys: ['sql'] },
    {
      metric: 'gitaly',
      header: 'Gitaly calls',
      details: 'details',
      keys: ['feature', 'request'],
    },
  ],
  simpleMetrics: ['redis', 'sidekiq'],
  data() {
    return { currentRequestId: '' };
  },
  computed: {
    requests() {
      return this.store.requestsWithDetails();
    },
    currentRequest: {
      get() {
        return this.store.findRequest(this.currentRequestId);
      },
      set(requestId) {
        this.currentRequestId = requestId;
      },
    },
    initialRequest() {
      return this.currentRequestId === this.requestId;
    },
    lineProfileModal() {
      return $('#modal-peek-line-profile');
    },
  },
  mounted() {
    this.interceptor = PerformanceBarService.registerInterceptor(
      this.peekUrl,
      this.loadRequestDetails,
    );

    this.loadRequestDetails(this.requestId, window.location.href);
    this.currentRequest = this.requestId;

    if (this.lineProfileModal.length) {
      this.lineProfileModal.modal('toggle');
    }
  },
  beforeDestroy() {
    PerformanceBarService.removeInterceptor(this.interceptor);
  },
  methods: {
    loadRequestDetails(requestId, requestUrl) {
      if (!this.store.canTrackRequest(requestUrl)) {
        return;
      }

      this.store.addRequest(requestId, requestUrl);

      PerformanceBarService.fetchRequestDetails(this.peekUrl, requestId)
        .then(res => {
          this.store.addRequestDetails(requestId, res.data.data);
        })
        .catch(() =>
          Flash(`Error getting performance bar results for ${requestId}`),
        );
    },
    changeCurrentRequest(newRequestId) {
      this.currentRequest = newRequestId;
    },
  },
};
</script>
<template>
  <div
    id="js-peek"
    :class="env"
  >
    <div
      v-if="currentRequest"
      class="d-flex container-fluid container-limited"
    >
      <div
        id="peek-view-host"
        class="view"
      >
        <span
          v-if="currentRequest.details"
          class="current-host"
        >
          {{ currentRequest.details.host.hostname }}
        </span>
      </div>
      <detailed-metric
        v-for="metric in $options.detailedMetrics"
        :key="metric.metric"
        :current-request="currentRequest"
        :metric="metric.metric"
        :header="metric.header"
        :details="metric.details"
        :keys="metric.keys"
      />
      <div
        v-if="initialRequest"
        id="peek-view-rblineprof"
        class="view"
      >
        <button
          v-if="lineProfileModal.length"
          class="btn-link btn-blank"
          data-toggle="modal"
          data-target="#modal-peek-line-profile"
        >
          profile
        </button>
        <a
          v-else
          :href="profileUrl"
        >
          profile
        </a>
      </div>
      <simple-metric
        v-for="metric in $options.simpleMetrics"
        :current-request="currentRequest"
        :key="metric"
        :metric="metric"
      />
      <div
        id="peek-view-gc"
        class="view"
      >
        <span
          v-if="currentRequest.details"
          class="bold"
        >
          <span title="Invoke Time">{{ currentRequest.details.gc.gc_time }}</span>ms
          /
          <span title="Invoke Count">{{ currentRequest.details.gc.invokes }}</span>
          gc
        </span>
      </div>
      <request-selector
        v-if="currentRequest"
        :current-request="currentRequest"
        :requests="requests"
        class="ml-auto"
        @change-current-request="changeCurrentRequest"
      />
    </div>
  </div>
</template>