Skip to content

Commit 83d19f2

Browse files
Kerrykerry-emqx
authored andcommitted
chore(logTrace,Gateway,RuleEngine): add LogTrace; fix some issues in Gateway; change file directory level of RuleEngine
1 parent 1bd8a61 commit 83d19f2

File tree

20 files changed

+1269
-594
lines changed

20 files changed

+1269
-594
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"element-plus": "^1.1.0-beta.24",
2020
"lodash": "^4.17.21",
2121
"moment": "^2.29.1",
22-
"monaco-editor": "^0.30.1",
22+
"monaco-editor": "^0.30.0",
2323
"mqtt": "^4.2.8",
2424
"nprogress": "^0.2.0",
2525
"vue": "^3.2.13",
@@ -50,6 +50,7 @@
5050
"sass": "^1.26.5",
5151
"sass-loader": "^8.0.2",
5252
"typescript": "~4.1.5",
53-
"vue-jest": "^5.0.0-0"
53+
"vue-jest": "^5.0.0-0",
54+
"webpack": "^4.36.0"
5455
}
5556
}

src/api/diagnose.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import http from "@/common/http";
22
import { ListDataWithPagination } from "@/types/common";
33
import { SlowSubConfig, SlowSubStatistic } from "@/types/diagnose";
4+
import { createURLWithAuth } from "@/common/utils";
5+
import store from "@/store";
46

57
export const querySlowSubConfig = (): Promise<SlowSubConfig> => {
68
return http.get("/slow_subscriptions/settings");
@@ -14,6 +16,38 @@ export const clearSlowSubData = () => {
1416
return http.delete("/slow_subscriptions");
1517
};
1618

17-
export const querySlowSubStatistics = (): Promise<ListDataWithPagination<SlowSubStatistic>> => {
19+
export const querySlowSubStatistics = (): Promise<
20+
ListDataWithPagination<SlowSubStatistic>
21+
> => {
1822
return http.get("/slow_subscriptions");
1923
};
24+
25+
export function getTraceList() {
26+
return http.get("/trace");
27+
}
28+
29+
export function addTrace(body: Record<string, unknown>) {
30+
return http.post("/trace", body);
31+
}
32+
33+
export function getTraceLog(name: string, params: Record<string, unknown>) {
34+
if (!name) return false;
35+
return http.get(`/trace/${encodeURIComponent(name)}/log`, { params });
36+
}
37+
38+
export function downloadTrace(name: string) {
39+
const link = document.createElement("a");
40+
link.href = `/trace/${encodeURIComponent(name)}/download`;
41+
console.log(link.href);
42+
// link.setAttribute('download', 'emqx.zip')
43+
document.body.appendChild(link);
44+
link.click();
45+
return Promise.resolve();
46+
}
47+
export function stopTrace(name: string) {
48+
return http.put(`/trace/${encodeURIComponent(name)}/stop`);
49+
}
50+
51+
export function deleteTrace(name: string) {
52+
return http.delete(`/trace/${encodeURIComponent(name)}`);
53+
}

src/common/monacoUtils.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* eslint-disable */
2+
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
3+
4+
function getInertText(text, preWord) {
5+
// let $text = text.replace(/\"/g, '')
6+
return text
7+
}
8+
export function createMonacoComplete(hints, range, { word }) {
9+
let customHints = []
10+
if (hints.length) {
11+
customHints = hints.map((doc) => ({
12+
label: doc.name,
13+
// kind is icon
14+
kind: doc.type ? monaco.languages.CompletionItemKind[doc.type] : monaco.languages.CompletionItemKind.Function,
15+
documentation: doc.documentation,
16+
insertText: getInertText(doc.name, word),
17+
detail: doc.detail || 'EMQX',
18+
range,
19+
}))
20+
}
21+
return customHints
22+
}
23+
24+
function getValueName(hint) {
25+
let { name, default: defaultValue, valueType } = hint
26+
if (valueType) {
27+
name = `${name}: ${valueType}`
28+
}
29+
return defaultValue ? `${name}, value: ${defaultValue}` : name
30+
}
31+
export function createMonacoHover(key, hints) {
32+
const contents = []
33+
hints.forEach((hint) => {
34+
let word = hint.name
35+
if (hint.name.match(/\$events\//)) {
36+
word = hint.name.split('/')[1].replace('"', '')
37+
}
38+
if (key === word) {
39+
contents.push(
40+
{
41+
value: getValueName(hint),
42+
},
43+
{
44+
value: hint.documentation,
45+
},
46+
)
47+
}
48+
})
49+
return contents
50+
}
51+
52+
export default {}

src/components/Monaco.vue

Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
<template>
2+
<div :id="`monaco-${id}`" class="monaco-view"></div>
3+
</template>
4+
5+
<script>
6+
import * as monaco from "monaco-editor";
7+
// import * as monaco from "monaco-editor/esm/vs/editor/editor.api";
8+
// import { createMonacoComplete, createMonacoHover } from "@/common/monacoUtils";
9+
10+
export default {
11+
name: "Monaco",
12+
13+
props: {
14+
id: {
15+
type: String,
16+
required: true,
17+
},
18+
value: {
19+
type: String,
20+
required: true,
21+
},
22+
lang: {
23+
type: String,
24+
required: true,
25+
},
26+
disabled: {
27+
type: Boolean,
28+
default: false,
29+
},
30+
// warp: {
31+
// type: Boolean,
32+
// default: false,
33+
// },
34+
// provider: {
35+
// type: Array,
36+
// default: () => [],
37+
// },
38+
scrollLoading: {
39+
type: Boolean,
40+
default: false,
41+
},
42+
scrollFunc: {
43+
type: Function,
44+
default: () => () => {},
45+
},
46+
},
47+
48+
data() {
49+
return {
50+
editor: null,
51+
providerDisposeID: null,
52+
hoverDisposeID: null,
53+
sqlHints: [
54+
{
55+
name: "SELECT",
56+
type: "Keyword",
57+
detail: "SQL",
58+
documentation: "SQL selector.",
59+
},
60+
{
61+
name: "FROM",
62+
type: "Keyword",
63+
detail: "SQL",
64+
documentation: "What event.",
65+
},
66+
{
67+
name: "WHERE",
68+
type: "Keyword",
69+
detail: "SQL",
70+
documentation:
71+
"Filters a result set to include only records that fulfill a specified condition. ",
72+
},
73+
{
74+
name: "and",
75+
type: "Keyword",
76+
detail: "SQL",
77+
documentation: "Operator.",
78+
},
79+
{
80+
name: "or",
81+
type: "Keyword",
82+
detail: "SQL",
83+
documentation: "Operator.",
84+
},
85+
],
86+
};
87+
},
88+
89+
watch: {
90+
// value(val) {
91+
// if (this.editor) {
92+
// if (val !== this.editor.getValue()) {
93+
// this.editor.setValue(val);
94+
// }
95+
// }
96+
// },
97+
// lang() {
98+
// if (this.editor) {
99+
// this.editor.dispose();
100+
// this.initEditor();
101+
// }
102+
// },
103+
},
104+
105+
created() {
106+
window.onresize = () => {
107+
console.log("resize");
108+
// if (this.editor) {
109+
// this.editor.layout();
110+
// }
111+
};
112+
// if (this.provider.length) {
113+
// this.registerCustomHintsProvider();
114+
// this.registerCustomHoverProvider();
115+
// }
116+
},
117+
118+
mounted() {
119+
this.initEditor();
120+
},
121+
// beforeUpdate() {
122+
// this.editor.dispose();
123+
// },
124+
125+
beforeUnmount() {
126+
if (this.editor) {
127+
// this.editor.getModel().dispose();
128+
this.editor.dispose();
129+
// this.editor = null;
130+
}
131+
// if (this.providerDisposeID) {
132+
// this.providerDisposeID.dispose();
133+
// }
134+
// if (this.hoverDisposeID) {
135+
// this.hoverDisposeID.dispose();
136+
// }
137+
},
138+
139+
methods: {
140+
initEditor() {
141+
const id = `monaco-${this.id}`;
142+
const defaultOptions = {
143+
value: this.value,
144+
language: this.lang,
145+
readOnly: this.disabled,
146+
// fontSize: 12,
147+
// automaticLayout: true,
148+
// scrollBeyondLastLine: false,
149+
theme: "vs",
150+
minimap: {
151+
enabled: false,
152+
},
153+
// hover: {
154+
// delay: 500,
155+
// enabled: true,
156+
// },
157+
};
158+
const options = this.beforeMonacoCreate(defaultOptions);
159+
// Create
160+
this.editor = monaco.editor.create(document.getElementById(id), options);
161+
// event changed
162+
// this.editor.onDidChangeModelContent((event) => {
163+
// const value = this.editor.getValue();
164+
// if (value !== this.value) {
165+
// this.$emit("input", value, event);
166+
// this.$emit("change", value, event);
167+
// }
168+
// });
169+
// Qucik save method
170+
// eslint-disable-next-line
171+
// this.editor.addCommand(
172+
// monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S,
173+
// () => {
174+
// this.$emit("qucik-save", this.value);
175+
// }
176+
// );
177+
// Update editor options
178+
// this.editor.getModel().updateOptions({ tabSize: 2 });
179+
180+
if (this.scrollLoading) this.editor.onDidScrollChange(this.scrollFunc);
181+
},
182+
beforeMonacoCreate(options) {
183+
// if (this.warp) {
184+
// const warpOptions = {
185+
// wordWrap: "on",
186+
// wrappingIndent: "indent",
187+
// };
188+
// Object.assign(options, warpOptions);
189+
// }
190+
return options;
191+
},
192+
// getHints() {
193+
// const $hints = [...this.provider];
194+
// if (this.lang === "sql") {
195+
// $hints.push(...this.sqlHints);
196+
// }
197+
// return $hints;
198+
// },
199+
// registerCustomHintsProvider() {
200+
// this.providerDisposeID = monaco.languages.registerCompletionItemProvider(
201+
// this.lang,
202+
// {
203+
// provideCompletionItems: (model, position) => {
204+
// const wordObj = model.getWordUntilPosition(position);
205+
// const hints = this.getHints(wordObj);
206+
// const range = {
207+
// startLineNumber: position.lineNumber,
208+
// endLineNumber: position.lineNumber,
209+
// startColumn: wordObj.startColumn,
210+
// endColumn: wordObj.endColumn,
211+
// };
212+
// return {
213+
// suggestions: createMonacoComplete(hints, range, wordObj),
214+
// };
215+
// },
216+
// triggerCharacters: [" "],
217+
// }
218+
// );
219+
// },
220+
// registerCustomHoverProvider() {
221+
// monaco.languages.register({ id: this.lang });
222+
// this.hoverDisposeID = monaco.languages.registerHoverProvider(this.lang, {
223+
// provideHover: (model, position) => {
224+
// if (!model.getWordAtPosition(position)) {
225+
// return {};
226+
// }
227+
// const { word } = model.getWordAtPosition(position);
228+
// return {
229+
// contents: createMonacoHover(word, this.provider),
230+
// };
231+
// },
232+
// });
233+
// },
234+
},
235+
};
236+
</script>
237+
238+
<style lang="scss">
239+
.monaco-view {
240+
height: 100%;
241+
position: relative;
242+
}
243+
</style>

0 commit comments

Comments
 (0)