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

dashboard.vue « components « monitoring « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8da723ced03400ed3ee154997410fccdddaf3fa9 (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
<script>
  import _ from 'underscore';
  import Flash from '../../flash';
  import MonitoringService from '../services/monitoring_service';
  import GraphGroup from './graph_group.vue';
  import Graph from './graph.vue';
  import EmptyState from './empty_state.vue';
  import MonitoringStore from '../stores/monitoring_store';
  import eventHub from '../event_hub';
  import { convertPermissionToBoolean } from '../../lib/utils/common_utils';

  export default {

    data() {
      const metricsData = document.querySelector('#prometheus-graphs').dataset;
      const store = new MonitoringStore();

      return {
        store,
        state: 'gettingStarted',
        hasMetrics: convertPermissionToBoolean(metricsData.hasMetrics),
        documentationPath: metricsData.documentationPath,
        settingsPath: metricsData.settingsPath,
        tagsPath: metricsData.tagsPath,
        projectPath: metricsData.projectPath,
        metricsEndpoint: metricsData.additionalMetrics,
        deploymentEndpoint: metricsData.deploymentEndpoint,
        emptyGettingStartedSvgPath: metricsData.emptyGettingStartedSvgPath,
        emptyLoadingSvgPath: metricsData.emptyLoadingSvgPath,
        emptyUnableToConnectSvgPath: metricsData.emptyUnableToConnectSvgPath,
        showEmptyState: true,
        updateAspectRatio: false,
        updatedAspectRatios: 0,
        hoverData: {},
        resizeThrottled: {},
      };
    },

    components: {
      Graph,
      GraphGroup,
      EmptyState,
    },

    methods: {
      getGraphsData() {
        this.state = 'loading';
        Promise.all([
          this.service.getGraphsData()
            .then(data => this.store.storeMetrics(data)),
          this.service.getDeploymentData()
            .then(data => this.store.storeDeploymentData(data))
            .catch(() => new Flash('Error getting deployment information.')),
        ])
          .then(() => { this.showEmptyState = false; })
          .catch(() => { this.state = 'unableToConnect'; });
      },

      resize() {
        this.updateAspectRatio = true;
      },

      toggleAspectRatio() {
        this.updatedAspectRatios = this.updatedAspectRatios += 1;
        if (this.store.getMetricsCount() === this.updatedAspectRatios) {
          this.updateAspectRatio = !this.updateAspectRatio;
          this.updatedAspectRatios = 0;
        }
      },

      hoverChanged(data) {
        this.hoverData = data;
      },
    },

    created() {
      this.service = new MonitoringService({
        metricsEndpoint: this.metricsEndpoint,
        deploymentEndpoint: this.deploymentEndpoint,
      });
      eventHub.$on('toggleAspectRatio', this.toggleAspectRatio);
      eventHub.$on('hoverChanged', this.hoverChanged);
    },

    beforeDestroy() {
      eventHub.$off('toggleAspectRatio', this.toggleAspectRatio);
      eventHub.$off('hoverChanged', this.hoverChanged);
      window.removeEventListener('resize', this.resizeThrottled, false);
    },

    mounted() {
      this.resizeThrottled = _.throttle(this.resize, 600);
      if (!this.hasMetrics) {
        this.state = 'gettingStarted';
      } else {
        this.getGraphsData();
        window.addEventListener('resize', this.resizeThrottled, false);
      }
    },
  };
</script>

<template>
  <div v-if="!showEmptyState" class="prometheus-graphs">
    <graph-group
      v-for="(groupData, index) in store.groups"
      :key="index"
      :name="groupData.group"
    >
      <graph
        v-for="(graphData, index) in groupData.metrics"
        :key="index"
        :graph-data="graphData"
        :hover-data="hoverData"
        :update-aspect-ratio="updateAspectRatio"
        :deployment-data="store.deploymentData"
        :project-path="projectPath"
        :tags-path="tagsPath"
      />
    </graph-group>
  </div>
  <empty-state
    v-else
    :selected-state="state"
    :documentation-path="documentationPath"
    :settings-path="settingsPath"
    :empty-getting-started-svg-path="emptyGettingStartedSvgPath"
    :empty-loading-svg-path="emptyLoadingSvgPath"
    :empty-unable-to-connect-svg-path="emptyUnableToConnectSvgPath"
  />
</template>