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

client.js « observability « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 251c165e7dd7b3219948f1ec9fd9870ab9dfa5f1 (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
import axios from '~/lib/utils/axios_utils';

function enableTraces() {
  // TODO remove mocks https://gitlab.com/gitlab-org/opstrace/opstrace/-/issues/2271
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve();
    }, 1000);
  });
}

function isTracingEnabled() {
  // TODO remove mocks https://gitlab.com/gitlab-org/opstrace/opstrace/-/issues/2271
  return new Promise((resolve) => {
    setTimeout(() => {
      // Currently relying on manual provisioning, hence assuming tracing is enabled
      resolve(true);
    }, 1000);
  });
}

async function fetchTraces(tracingUrl) {
  const { data } = await axios.get(tracingUrl, { withCredentials: true });
  if (!Array.isArray(data.traces)) {
    throw new Error('traces are missing/invalid in the response.'); // eslint-disable-line @gitlab/require-i18n-strings
  }
  return data.traces.map((t) => {
    // aggregating duration on the client for now, but expecting to be coming from the backend
    const duration = t.spans.reduce((acc, cur) => acc + cur.duration_nano, 0);
    return {
      ...t,
      duration: duration / 1000,
    };
  });
}

export function buildClient({ provisioningUrl, tracingUrl }) {
  return {
    enableTraces: () => enableTraces(provisioningUrl),
    isTracingEnabled: () => isTracingEnabled(provisioningUrl),
    fetchTraces: () => fetchTraces(tracingUrl),
  };
}