(opts *cli.Option)
| 140 | } |
| 141 | |
| 142 | func 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()) |
no test coverage detected
searching dependent graphs…