/
TC_func_stdlib_system.go
125 lines (111 loc) · 3.52 KB
/
TC_func_stdlib_system.go
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
package ThreadComputation
import (
"strings"
log "github.com/sirupsen/logrus"
"github.com/gammazero/deque"
)
func TCLoglevelFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
if q.Len() == 0 {
lvl, err := GetVariable("tc.Debuglevel")
if err != nil {
return nil, err
}
return lvl, nil
}
for q.Len() > 0 {
e := q.PopFront()
switch lvl := e.(type) {
case string:
lvl = strings.ToLower(lvl)
switch lvl {
case "trace":
l.TC.IsDebug = true
log.SetLevel(log.TraceLevel)
case "debug":
l.TC.IsDebug = true
log.SetLevel(log.DebugLevel)
case "info":
l.TC.IsDebug = false
log.SetLevel(log.InfoLevel)
case "warning":
l.TC.IsDebug = false
log.SetLevel(log.WarnLevel)
case "error":
l.TC.IsDebug = false
log.SetLevel(log.ErrorLevel)
case "fatal":
l.TC.IsDebug = false
log.SetLevel(log.FatalLevel)
default:
l.TC.IsDebug = false
log.SetLevel(log.InfoLevel)
}
log.Debugf("Loglevel set to: %v", lvl)
}
}
return nil, nil
}
func TCTestEnableFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
l.TC.IsTest = true
return nil, nil
}
func TCTestDisableFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
l.TC.IsTest = false
return nil, nil
}
func TCObserveEnableFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
l.TC.IsObserve = true
return nil, nil
}
func TCObserveDisableFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
l.TC.IsObserve = false
return nil, nil
}
func TCPoolCapacityFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
return l.TC.Pool.PoolSize(), nil
}
func TCPoolActiveFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
return l.TC.Pool.ActiveWorkers(), nil
}
func BlockTesting(l *TCExecListener, name string, code string) interface{} {
if l.TC.IsTest {
log.Debugf("Executing testing[] section")
l.TC.Eval(code)
}
return nil
}
func BlockMonitoring(l *TCExecListener, name string, code string) interface{} {
if l.TC.IsTest {
log.Debugf("Executing monitoring[] section")
l.TC.Eval(code)
}
return nil
}
func TCNSNameFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
if l.TC.ResNames.Len() == 0 {
return nil, l.TC.MakeError("Namespace context is too shallow for getting name")
}
return l.TC.ResNames.Front().(string), nil
}
func TCNSPreviousNameFunction(l *TCExecListener, name string, q *deque.Deque) (interface{}, error) {
if l.TC.ResNames.Len() == 0 {
return nil, l.TC.MakeError("Namespace context is too shallow for getting name")
}
l.TC.StacksLeft(1)
sname := l.TC.ResNames.Front().(string)
l.TC.StacksRight(1)
return sname, nil
}
func init() {
RegisterBlockCallback("testing", BlockTesting)
RegisterBlockCallback("monitoring", BlockMonitoring)
SetCommand("system.Loglevel", TCLoglevelFunction)
SetCommand("system.TestEnable", TCTestEnableFunction)
SetCommand("system.TestDisable", TCTestDisableFunction)
SetCommand("system.ObservabilityEnable", TCObserveEnableFunction)
SetCommand("system.ObservabilityDisable", TCObserveDisableFunction)
SetCommand("system.PoolCapacity", TCPoolCapacityFunction)
SetCommand("system.Workers", TCPoolActiveFunction)
SetCommand("name", TCNSNameFunction)
SetCommand("previous", TCNSPreviousNameFunction)
}