MCPcopy
hub / github.com/netdata/netdata / runFunctionCLI

Function runFunctionCLI

src/go/cmd/godplugin/main.go:142–244  ·  view source on GitHub ↗
(opts *cli.Option)

Source from the content-addressed store, hash-verified

140}
141
142func runFunctionCLI(opts *cli.Option) int {
143 functionName := strings.TrimSpace(opts.Function)
144 if functionName == "" {
145 writeFunctionError(400, "missing function name (expected module:method)")
146 return 1
147 }
148
149 moduleName, methodID, err := functions.SplitFunctionName(functionName)
150 if err != nil {
151 writeFunctionError(400, "%v", err)
152 return 1
153 }
154
155 creator, ok := collectorapi.DefaultRegistry.Lookup(moduleName)
156 if !ok {
157 writeFunctionError(404, "unknown module '%s'", moduleName)
158 return 1
159 }
160 if creator.Methods == nil {
161 writeFunctionError(404, "module '%s' does not expose functions", moduleName)
162 return 1
163 }
164 if methodID == "" {
165 writeFunctionError(400, "missing method name in function '%s'", functionName)
166 return 1
167 }
168
169 payloadBytes, payloadTimeout, err := readFunctionPayload(opts.FunctionPayload)
170 if err != nil {
171 writeFunctionError(400, "%v", err)
172 return 1
173 }
174
175 timeout, err := resolveFunctionTimeout(opts.FunctionTimeout, payloadTimeout)
176 if err != nil {
177 writeFunctionError(400, "%v", err)
178 return 1
179 }
180
181 reg := confgroup.Registry{}
182 reg.Register(moduleName, confgroup.Default{
183 MinUpdateEvery: opts.UpdateEvery,
184 UpdateEvery: creator.UpdateEvery,
185 AutoDetectionRetry: creator.AutoDetectionRetry,
186 Priority: creator.Priority,
187 })
188
189 groups, err := loadConfigGroups(moduleName, reg, pluginconfig.CollectorsDir())
190 if err != nil {
191 writeFunctionError(500, "%v", err)
192 return 1
193 }
194 if len(groups) == 0 {
195 writeFunctionError(404, "no configs found for module '%s'", moduleName)
196 return 1
197 }
198
199 ctx, cancel := context.WithCancel(context.Background())

Callers 1

mainFunction · 0.85

Calls 13

RegisterMethod · 0.95
writeFunctionErrorFunction · 0.85
readFunctionPayloadFunction · 0.85
resolveFunctionTimeoutFunction · 0.85
loadConfigGroupsFunction · 0.85
waitForJobsFunction · 0.85
WaitStartedMethod · 0.80
NewMethod · 0.65
WriteMethod · 0.65
RunMethod · 0.65
LookupMethod · 0.45
SetDyncfgResponderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…