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
|
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
import { createAlert } from '~/alert';
import { visitUrl, joinPaths } from '~/lib/utils/url_utility';
import UrlSync from '~/vue_shared/components/url_sync.vue';
import {
queryToFilterObj,
filterObjToQuery,
filterObjToFilterToken,
filterTokensToFilterObj,
} from '../filters';
import TracingEmptyState from './tracing_empty_state.vue';
import TracingTableList from './tracing_table_list.vue';
import FilteredSearch from './tracing_list_filtered_search.vue';
export default {
components: {
GlLoadingIcon,
TracingTableList,
TracingEmptyState,
FilteredSearch,
UrlSync,
},
props: {
observabilityClient: {
required: true,
type: Object,
},
},
data() {
return {
loading: true,
/**
* tracingEnabled: boolean | null.
* null identifies a state where we don't know if tracing is enabled or not (e.g. when fetching the status from the API fails)
*/
tracingEnabled: null,
traces: [],
filters: queryToFilterObj(window.location.search),
};
},
computed: {
query() {
return filterObjToQuery(this.filters);
},
initialFilterValue() {
return filterObjToFilterToken(this.filters);
},
},
async created() {
this.checkEnabled();
},
methods: {
async checkEnabled() {
this.loading = true;
try {
this.tracingEnabled = await this.observabilityClient.isTracingEnabled();
if (this.tracingEnabled) {
await this.fetchTraces();
}
} catch (e) {
createAlert({
message: s__('Tracing|Failed to load page.'),
});
} finally {
this.loading = false;
}
},
async enableTracing() {
this.loading = true;
try {
await this.observabilityClient.enableTraces();
this.tracingEnabled = true;
await this.fetchTraces();
} catch (e) {
createAlert({
message: s__('Tracing|Failed to enable tracing.'),
});
} finally {
this.loading = false;
}
},
async fetchTraces() {
this.loading = true;
try {
const traces = await this.observabilityClient.fetchTraces(this.filters);
this.traces = traces;
} catch (e) {
createAlert({
message: s__('Tracing|Failed to load traces.'),
});
} finally {
this.loading = false;
}
},
selectTrace(trace) {
visitUrl(joinPaths(window.location.pathname, trace.trace_id));
},
handleFilters(filterTokens) {
this.filters = filterTokensToFilterObj(filterTokens);
this.fetchTraces();
},
},
};
</script>
<template>
<div>
<div v-if="loading" class="gl-py-5">
<gl-loading-icon size="lg" />
</div>
<template v-else-if="tracingEnabled !== null">
<tracing-empty-state v-if="tracingEnabled === false" @enable-tracing="enableTracing" />
<template v-else>
<filtered-search :initial-filters="initialFilterValue" @submit="handleFilters" />
<url-sync :query="query" />
<tracing-table-list :traces="traces" @reload="fetchTraces" @trace-selected="selectTrace" />
</template>
</template>
</div>
</template>
|