-
Notifications
You must be signed in to change notification settings - Fork 201
Tibi - Testing OTEL #5102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v3
Are you sure you want to change the base?
Tibi - Testing OTEL #5102
Changes from 26 commits
b4edae2
2360ed6
87e7afa
d0a9531
5fea0cc
dfd9910
69562c0
a5e4afc
ecd9cfc
81a8f10
d35589c
a6b0886
f979e02
f7d3d4c
8578248
9f64b95
5485877
91ec6dc
9572312
db9cee0
aa1d6ed
449a3bd
72d2721
658f90d
120606b
0a762b7
1b4a4fb
9e2823b
7371d21
494e6b9
6fb97fc
17f3fff
65d3dfb
dca6865
65e02f2
b34d2e1
1db9088
6a44b81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Copyright (C) 2023 Percona LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package management | ||
|
|
||
| import ( | ||
| "strings" | ||
|
|
||
| "github.com/percona/pmm/admin/agentlocal" | ||
| "github.com/percona/pmm/admin/commands" | ||
| "github.com/percona/pmm/api/inventory/v1/json/client" | ||
| agents "github.com/percona/pmm/api/inventory/v1/json/client/agents_service" | ||
| ) | ||
|
|
||
| var addOtelResultT = commands.ParseTemplate(` | ||
| OTEL Collector added. | ||
| Agent ID : {{ .Agent.AgentID }} | ||
| PMM-Agent ID : {{ .Agent.PMMAgentID }} | ||
| Status : {{ .Agent.Status }} | ||
| Disabled : {{ .Agent.Disabled }} | ||
| `) | ||
|
|
||
| type addOtelResult struct { | ||
| Agent *agents.AddAgentOKBodyOtelCollector `json:"otel_collector"` | ||
| } | ||
|
|
||
| func (res *addOtelResult) Result() {} | ||
|
|
||
| func (res *addOtelResult) String() string { | ||
| return commands.RenderTemplate(addOtelResultT, res) | ||
| } | ||
|
|
||
| // AddOtelCommand is used by Kong for CLI flags and commands. | ||
| type AddOtelCommand struct { | ||
| PMMAgentID string `help:"Node ID where pmm-agent runs (default is autodetected)"` | ||
| LogFilePaths []string `name:"log-file-paths" help:"Comma-separated list of log file paths to collect (e.g. /var/log/mysql/error.log). Used with --parser-preset or as raw if --log-sources not set."` | ||
| LogSources string `name:"log-sources" help:"Comma-separated path:preset pairs (e.g. /var/log/mysql/error.log:mysql_error,/other.log:raw). Preset 'raw' means no parsing. Available presets: mysql_error, nginx_access, nginx_error, grafana, pmm_managed, pmm_agent, postgres, raw. Overrides --log-file-paths and --parser-preset."` | ||
|
||
| ParserPreset string `name:"parser-preset" help:"Parser preset for all paths from --log-file-paths. Available presets: mysql_error, nginx_access, nginx_error, grafana, pmm_managed, pmm_agent, postgres, raw. Ignored if --log-sources is set."` | ||
|
||
| CustomLabels map[string]string `mapsep:"," help:"Custom user-assigned labels"` | ||
| } | ||
|
|
||
| // RunCmd runs the command for AddOtelCommand. | ||
| func (cmd *AddOtelCommand) RunCmd() (commands.Result, error) { | ||
| pmmAgentID := cmd.PMMAgentID | ||
| if pmmAgentID == "" { | ||
| status, err := agentlocal.GetStatus(agentlocal.DoNotRequestNetworkInfo) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| pmmAgentID = status.AgentID | ||
| } | ||
|
|
||
| customLabels := commands.ParseKeyValuePair(cmd.CustomLabels) | ||
|
|
||
| body := &agents.AddAgentParamsBodyOtelCollector{ | ||
| PMMAgentID: pmmAgentID, | ||
| CustomLabels: customLabels, | ||
| } | ||
| if cmd.LogSources != "" { | ||
|
||
| // Parse path:preset pairs. | ||
| for _, pair := range strings.Split(cmd.LogSources, ",") { | ||
|
||
| pair = strings.TrimSpace(pair) | ||
| if pair == "" { | ||
| continue | ||
| } | ||
| path := pair | ||
| preset := "raw" | ||
| if idx := strings.Index(pair, ":"); idx >= 0 { | ||
| path = strings.TrimSpace(pair[:idx]) | ||
| preset = strings.TrimSpace(pair[idx+1:]) | ||
| if preset == "" { | ||
| preset = "raw" | ||
| } | ||
| } | ||
| if path != "" { | ||
| body.LogSources = append(body.LogSources, &agents.AddAgentParamsBodyOtelCollectorLogSourcesItems0{ | ||
| Path: path, | ||
| Preset: preset, | ||
| }) | ||
| } | ||
| } | ||
| } else if len(cmd.LogFilePaths) != 0 { | ||
| if cmd.ParserPreset != "" { | ||
| for _, p := range cmd.LogFilePaths { | ||
| p = strings.TrimSpace(p) | ||
| if p != "" { | ||
| body.LogSources = append(body.LogSources, &agents.AddAgentParamsBodyOtelCollectorLogSourcesItems0{ | ||
| Path: p, | ||
| Preset: cmd.ParserPreset, | ||
| }) | ||
| } | ||
| } | ||
| } else { | ||
| body.LogFilePaths = cmd.LogFilePaths | ||
|
||
| } | ||
| } | ||
|
|
||
| params := &agents.AddAgentParams{ | ||
| Body: agents.AddAgentBody{ | ||
| OtelCollector: body, | ||
| }, | ||
| Context: commands.Ctx, | ||
| } | ||
|
|
||
| resp, err := client.Default.AgentsService.AddAgent(params) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &addOtelResult{ | ||
| Agent: resp.Payload.OtelCollector, | ||
| }, nil | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
The line is 210 characters long, which exceeds the maximum of 170 characters. (lll)