master
go 83 lines 2.2 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package mysqlfunc
4
5 import (
6 "time"
7
8 "github.com/netdata/netdata/go/plugins/pkg/confopt"
9 )
10
11 const defaultTopQueriesLimit = 500
12
13 // FunctionsConfig holds MySQL function-specific settings.
14 //
15 // Timeout is an internal fallback timeout inherited from collector config.
16 // It is intentionally excluded from YAML/JSON.
17 type FunctionsConfig struct {
18 Timeout confopt.Duration `yaml:"-" json:"-"`
19
20 TopQueries TopQueriesConfig `yaml:"top_queries,omitempty" json:"top_queries"`
21 DeadlockInfo DeadlockInfoConfig `yaml:"deadlock_info,omitempty" json:"deadlock_info"`
22 ErrorInfo ErrorInfoConfig `yaml:"error_info,omitempty" json:"error_info"`
23 }
24
25 type TopQueriesConfig struct {
26 Disabled bool `yaml:"disabled" json:"disabled"`
27 Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
28 Limit int `yaml:"limit,omitempty" json:"limit"`
29 }
30
31 type DeadlockInfoConfig struct {
32 Disabled bool `yaml:"disabled" json:"disabled"`
33 Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
34 }
35
36 type ErrorInfoConfig struct {
37 Disabled bool `yaml:"disabled" json:"disabled"`
38 Timeout confopt.Duration `yaml:"timeout,omitempty" json:"timeout"`
39 }
40
41 func (c FunctionsConfig) topQueriesDisabled() bool {
42 return c.TopQueries.Disabled
43 }
44
45 func (c FunctionsConfig) deadlockInfoDisabled() bool {
46 return c.DeadlockInfo.Disabled
47 }
48
49 func (c FunctionsConfig) errorInfoDisabled() bool {
50 return c.ErrorInfo.Disabled
51 }
52
53 func (c FunctionsConfig) topQueriesTimeout() time.Duration {
54 if c.TopQueries.Timeout == 0 {
55 return c.Timeout.Duration()
56 }
57 return c.TopQueries.Timeout.Duration()
58 }
59
60 func (c FunctionsConfig) deadlockInfoTimeout() time.Duration {
61 if c.DeadlockInfo.Timeout == 0 {
62 return c.Timeout.Duration()
63 }
64 return c.DeadlockInfo.Timeout.Duration()
65 }
66
67 func (c FunctionsConfig) errorInfoTimeout() time.Duration {
68 if c.ErrorInfo.Timeout == 0 {
69 return c.Timeout.Duration()
70 }
71 return c.ErrorInfo.Timeout.Duration()
72 }
73
74 func (c FunctionsConfig) collectorTimeout() time.Duration {
75 return c.Timeout.Duration()
76 }
77
78 func (c FunctionsConfig) topQueriesLimit() int {
79 if c.TopQueries.Limit <= 0 {
80 return defaultTopQueriesLimit
81 }
82 return c.TopQueries.Limit
83 }