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

observability_container.vue « components « observability « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1518c13256012013c7b19b6fdba4473bb7cb1409 (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
<script>
import { buildClient } from '../client';
import { SKELETON_SPINNER_VARIANT } from '../constants';
import ObservabilitySkeleton from './skeleton/index.vue';

export default {
  SKELETON_SPINNER_VARIANT,
  components: {
    ObservabilitySkeleton,
  },
  props: {
    oauthUrl: {
      type: String,
      required: true,
    },
    provisioningUrl: {
      type: String,
      required: true,
    },
    tracingUrl: {
      type: String,
      required: true,
    },
    servicesUrl: {
      type: String,
      required: true,
    },
    operationsUrl: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      observabilityClient: null,
      authCompleted: false,
    };
  },
  mounted() {
    window.addEventListener('message', this.messageHandler);

    // TODO: Improve local GDK dev experience with tracing https://gitlab.com/gitlab-org/opstrace/opstrace/-/issues/2308
    // Uncomment the lines below to to test this locally
    // setTimeout(() => {
    //   this.messageHandler({
    //     data: { type: 'AUTH_COMPLETION', status: 'success' },
    //     origin: new URL(this.oauthUrl).origin,
    //   });
    // }, 2000);
  },
  destroyed() {
    window.removeEventListener('message', this.messageHandler);
  },
  methods: {
    messageHandler(e) {
      const isExpectedOrigin = e.origin === new URL(this.oauthUrl).origin;
      if (!isExpectedOrigin) return;

      const { data } = e;

      if (data.type === 'AUTH_COMPLETION') {
        if (this.authCompleted) return;

        const { status, message, statusCode } = data;
        if (status === 'success') {
          this.observabilityClient = buildClient({
            provisioningUrl: this.provisioningUrl,
            tracingUrl: this.tracingUrl,
            servicesUrl: this.servicesUrl,
            operationsUrl: this.operationsUrl,
          });
          this.$refs.observabilitySkeleton?.onContentLoaded();
        } else if (status === 'error') {
          // eslint-disable-next-line @gitlab/require-i18n-strings,no-console
          console.error('GOB auth failed with error:', message, statusCode);
          this.$refs.observabilitySkeleton?.onError();
        }
        this.authCompleted = true;
      }
    },
  },
};
</script>

<template>
  <div>
    <iframe
      v-if="!authCompleted"
      sandbox="allow-same-origin allow-forms allow-scripts"
      hidden
      :src="oauthUrl"
      data-testid="observability-oauth-iframe"
    ></iframe>

    <observability-skeleton
      ref="observabilitySkeleton"
      :variant="$options.SKELETON_SPINNER_VARIANT"
    >
      <slot v-if="observabilityClient" :observability-client="observabilityClient"></slot>
    </observability-skeleton>
  </div>
</template>