@@ -12,15 +12,36 @@ import (
1212 "time"
1313
1414 "k8s.io/klog/v2"
15+ "k8s.io/utils/set"
1516
1617 "github.com/kubeovn/kube-ovn/pkg/util"
1718)
1819
19- var limiter * Limiter
20-
21- func init () {
22- limiter = new (Limiter )
23- }
20+ var limiter = new (Limiter )
21+
22+ var readOnlyCommands = set .New (
23+ "" , // no command specified
24+ "show" , // print overview of database contents
25+ "list-br" , // print the names of all the bridges
26+ "br-exists" , // exit 2 if BRIDGE does not exist
27+ "br-to-vlan" , // print the VLAN which BRIDGE is on
28+ "br-to-parent" , // print the parent of BRIDGE
29+ "br-get-external-id" , // print value of KEY on BRIDGE or list key-value pairs on BRIDGE
30+ "list-ports" , // print the names of all the ports on BRIDGE
31+ "port-to-br" , // print name of bridge that contains PORT
32+ "list-ifaces" , // print the names of all interfaces on BRIDGE
33+ "iface-to-br" , // print name of bridge that contains IFACE
34+ "get-controller" , // print the controllers for BRIDGE
35+ "get-fail-mode" , // print the fail-mode for BRIDGE
36+ "get-manager" , // print the managers
37+ "get-ssl" , // print the SSL configuration
38+ "get-aa-mapping" , // get Auto Attach mappings from BRIDGE
39+ "list-zone-limits" , // list all limits configured on DATAPATH
40+ "list" , // list RECord (or all records) in TBL
41+ "find" , // list records satisfying CONDITION in TBL
42+ "get" , // print values of COLumns in RECord in TBL
43+ "wait-until" , // wait until condition is true
44+ )
2445
2546func UpdateOVSVsctlLimiter (c int32 ) {
2647 if c >= 0 {
@@ -35,40 +56,35 @@ func UpdateOVSVsctlLimiter(c int32) {
3556var podNetNsRegexp = regexp .MustCompile (`pod_netns="([^"]+)"` )
3657
3758func Exec (args ... string ) (string , error ) {
38- ctx , cancel := context .WithTimeout (context .Background (), time .Second )
39- defer cancel ()
40-
41- var (
42- start time.Time
43- elapsed float64
44- output []byte
45- method , code string
46- err error
47- )
48-
49- if err = limiter .Wait (ctx ); err != nil {
50- klog .V (4 ).Infof ("command %s %s waiting for execution timeout by concurrency limit of %d" , OvsVsCtl , strings .Join (args , " " ), limiter .Limit ())
51- return "" , err
59+ var command string
60+ for arg := range slices .Values (args ) {
61+ if ! strings .HasPrefix (arg , "-" ) {
62+ command = arg
63+ break
64+ }
5265 }
53- defer limiter .Done ()
54- klog .V (4 ).Infof ("command %s %s waiting for execution concurrency %d/%d" , OvsVsCtl , strings .Join (args , " " ), limiter .Current (), limiter .Limit ())
5566
56- start = time .Now ()
57- args = append ([]string {"--timeout=30" }, args ... )
58- output , err = exec .Command (OvsVsCtl , args ... ).CombinedOutput ()
59- elapsed = float64 ((time .Since (start )) / time .Millisecond )
60- klog .V (4 ).Infof ("command %s %s in %vms" , OvsVsCtl , strings .Join (args , " " ), elapsed )
67+ if ! readOnlyCommands .Has (command ) {
68+ ctx , cancel := context .WithTimeout (context .Background (), time .Second )
69+ defer cancel ()
6170
62- for _ , arg := range args {
63- if ! strings .HasPrefix (arg , "--" ) {
64- method = arg
65- break
71+ if err := limiter .Wait (ctx ); err != nil {
72+ klog .V (4 ).Infof ("command %s %s waiting for execution timeout by concurrency limit of %d" , OvsVsCtl , strings .Join (args , " " ), limiter .Limit ())
73+ return "" , err
6674 }
75+ defer limiter .Done ()
76+ klog .V (4 ).Infof ("command %s %s waiting for execution concurrency %d/%d" , OvsVsCtl , strings .Join (args , " " ), limiter .Current (), limiter .Limit ())
6777 }
6878
69- code = "0"
79+ start := time .Now ()
80+ args = slices .Insert (args , 0 , "--timeout=30" )
81+ output , err := exec .Command (OvsVsCtl , args ... ).CombinedOutput ()
82+ elapsed := float64 ((time .Since (start )) / time .Millisecond )
83+ klog .V (4 ).Infof ("command %s %s in %vms" , OvsVsCtl , strings .Join (args , " " ), elapsed )
84+
85+ code := "0"
7086 defer func () {
71- ovsClientRequestLatency .WithLabelValues ("ovsdb" , method , code ).Observe (elapsed )
87+ ovsClientRequestLatency .WithLabelValues ("ovsdb" , command , code ).Observe (elapsed )
7288 }()
7389
7490 if err != nil {
@@ -78,6 +94,7 @@ func Exec(args ...string) (string, error) {
7894 } else if elapsed > 500 {
7995 klog .Warningf ("ovs-vsctl command took too long: %s %s in %vms" , OvsVsCtl , strings .Join (args , " " ), elapsed )
8096 }
97+
8198 return trimCommandOutput (output ), nil
8299}
83100
0 commit comments