-
Notifications
You must be signed in to change notification settings - Fork 10.2k
etcdctl
: Migrate etcd-diagnosis
as a new subcommand diagnosis
#20280
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
Open
seshachalam-yv
wants to merge
2
commits into
etcd-io:main
Choose a base branch
from
seshachalam-yv:etcdctl-diagnosis
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2025 The etcd Authors | ||
// | ||
// 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 engine | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"go.etcd.io/etcd/etcdctl/v3/ctlv3/command/diagnosis/engine/intf" | ||
) | ||
|
||
type report struct { | ||
Input any `json:"input,omitempty"` | ||
Results []any `json:"results,omitempty"` | ||
} | ||
|
||
// Diagnose runs all provided plugins and returns a JSON report. | ||
// It logs plugin progress and individual results to stderr. | ||
func Diagnose(input any, plugins []intf.Plugin) ([]byte, error) { | ||
rp := report{ | ||
Input: input, | ||
} | ||
for _, plugin := range plugins { | ||
result := plugin.Diagnose() | ||
rp.Results = append(rp.Results, result) | ||
} | ||
|
||
return json.MarshalIndent(rp, "", "\t") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright 2025 The etcd Authors | ||
// | ||
// 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 intf | ||
|
||
type Plugin interface { | ||
// Name returns the name of the plugin | ||
Name() string | ||
// Diagnose performs diagnosis and returns the result. If it fails | ||
// to do the diagnosis for any reason, it gets the detailed reason | ||
// included in the diagnosis result. | ||
Diagnose() any | ||
} | ||
|
||
// FailedResult is the result returned by a plugin if it fails to | ||
// perform the diagnosis for any reason. | ||
type FailedResult struct { | ||
Name string `json:"name"` | ||
Reason string `json:"reason"` | ||
} |
181 changes: 181 additions & 0 deletions
181
etcdctl/ctlv3/command/diagnosis/examples/etcd_diagnosis_report.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
{ | ||
"input": { | ||
"endpoints": [ | ||
"http://127.0.0.1:2379" | ||
], | ||
"useClusterEndpoints": true, | ||
"dial-timeout": 2000000000, | ||
"command-timeout": 5000000000, | ||
"keep-alive-time": 2000000000, | ||
"keep-alive-timeout": 5000000000, | ||
"insecure": true, | ||
"insecure-discovery": true, | ||
"db-quota-bytes": 2147483648 | ||
}, | ||
"results": [ | ||
{ | ||
"name": "membershipChecker", | ||
"memberList": { | ||
"header": { | ||
"cluster_id": 17237436991929493444, | ||
"member_id": 9372538179322589801, | ||
"raft_term": 2 | ||
}, | ||
"members": [ | ||
{ | ||
"ID": 9372538179322589801, | ||
"name": "infra1", | ||
"peerURLs": [ | ||
"http://127.0.0.1:12380" | ||
], | ||
"clientURLs": [ | ||
"http://127.0.0.1:2379" | ||
] | ||
}, | ||
{ | ||
"ID": 10501334649042878790, | ||
"name": "infra2", | ||
"peerURLs": [ | ||
"http://127.0.0.1:22380" | ||
], | ||
"clientURLs": [ | ||
"http://127.0.0.1:22379" | ||
] | ||
}, | ||
{ | ||
"ID": 18249187646912138824, | ||
"name": "infra3", | ||
"peerURLs": [ | ||
"http://127.0.0.1:32380" | ||
], | ||
"clientURLs": [ | ||
"http://127.0.0.1:32379" | ||
] | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"name": "epStatusChecker", | ||
"summary": [ | ||
"Successful" | ||
], | ||
"epStatusList": [ | ||
{ | ||
"endpoint": "http://127.0.0.1:2379", | ||
"epStatus": { | ||
"header": { | ||
"cluster_id": 17237436991929493444, | ||
"member_id": 9372538179322589801, | ||
"revision": 1, | ||
"raft_term": 2 | ||
}, | ||
"version": "3.5.9", | ||
"dbSize": 98304, | ||
"leader": 18249187646912138824, | ||
"raftIndex": 8, | ||
"raftTerm": 2, | ||
"raftAppliedIndex": 8, | ||
"dbSizeInUse": 98304 | ||
} | ||
}, | ||
{ | ||
"endpoint": "http://127.0.0.1:22379", | ||
"epStatus": { | ||
"header": { | ||
"cluster_id": 17237436991929493444, | ||
"member_id": 10501334649042878790, | ||
"revision": 1, | ||
"raft_term": 2 | ||
}, | ||
"version": "3.5.9", | ||
"dbSize": 98304, | ||
"leader": 18249187646912138824, | ||
"raftIndex": 8, | ||
"raftTerm": 2, | ||
"raftAppliedIndex": 8, | ||
"dbSizeInUse": 98304 | ||
} | ||
}, | ||
{ | ||
"endpoint": "http://127.0.0.1:32379", | ||
"epStatus": { | ||
"header": { | ||
"cluster_id": 17237436991929493444, | ||
"member_id": 18249187646912138824, | ||
"revision": 1, | ||
"raft_term": 2 | ||
}, | ||
"version": "3.5.9", | ||
"dbSize": 98304, | ||
"leader": 18249187646912138824, | ||
"raftIndex": 8, | ||
"raftTerm": 2, | ||
"raftAppliedIndex": 8, | ||
"dbSizeInUse": 98304 | ||
} | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "serializableReadChecker", | ||
"summary": "Successful", | ||
"readResponses": [ | ||
{ | ||
"endpoint": "http://127.0.0.1:2379", | ||
"took": "686.5µs" | ||
}, | ||
{ | ||
"endpoint": "http://127.0.0.1:22379", | ||
"took": "1.129291ms" | ||
}, | ||
{ | ||
"endpoint": "http://127.0.0.1:32379", | ||
"took": "1.034625ms" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "linearizableReadChecker", | ||
"summary": "Successful", | ||
"readResponses": [ | ||
{ | ||
"endpoint": "http://127.0.0.1:2379", | ||
"took": "1.286333ms" | ||
}, | ||
{ | ||
"endpoint": "http://127.0.0.1:22379", | ||
"took": "890.417µs" | ||
}, | ||
{ | ||
"endpoint": "http://127.0.0.1:32379", | ||
"took": "1.257791ms" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "metricsChecker", | ||
"summary": [ | ||
"Successful" | ||
], | ||
"epMetricsList": [ | ||
{ | ||
"endpoint": "http://127.0.0.1:2379", | ||
"took": "3.752625ms", | ||
"epMetrics": { | ||
"etcd_disk_backend_commit_duration_seconds_bucket": [ | ||
"etcd_disk_backend_commit_duration_seconds_bucket{le=\"0.001\"} 0" | ||
], | ||
"etcd_disk_wal_fsync_duration_seconds_bucket": [ | ||
"etcd_disk_wal_fsync_duration_seconds_bucket{le=\"0.001\"} 0" | ||
], | ||
"etcd_network_peer_round_trip_time_seconds_bucket": [ | ||
"etcd_network_peer_round_trip_time_seconds_bucket{To=\"91bc3c398fb3c146\",le=\"0.0001\"} 2" | ||
], | ||
"process_resident_memory_bytes": null | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2025 The etcd Authors | ||
// | ||
// 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 common | ||
|
||
import ( | ||
"time" | ||
|
||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
// Checker carries shared configuration for diagnosis plugins. | ||
// It embeds generic options such as the etcd client configuration, | ||
// resolved endpoints, and command timeout. | ||
type Checker struct { | ||
Cfg *clientv3.ConfigSpec | ||
Endpoints []string | ||
CommandTimeout time.Duration | ||
DbQuotaBytes int | ||
Name string | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2025 The etcd Authors | ||
// | ||
// 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 common | ||
|
||
import ( | ||
"go.uber.org/zap" | ||
|
||
"go.etcd.io/etcd/client/pkg/v3/logutil" | ||
clientv3 "go.etcd.io/etcd/client/v3" | ||
) | ||
|
||
// NewClient creates an etcd client from the given configuration spec. | ||
func NewClient(cfg *clientv3.ConfigSpec) (*clientv3.Client, error) { | ||
lg, _ := logutil.CreateDefaultZapLogger(zap.InfoLevel) | ||
cliCfg, err := clientv3.NewClientConfig(cfg, lg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return clientv3.New(*cliCfg) | ||
} | ||
|
||
// ConfigWithEndpoint returns a shallow copy of cfg with Endpoints set to the | ||
// provided single endpoint. | ||
func ConfigWithEndpoint(cfg *clientv3.ConfigSpec, ep string) *clientv3.ConfigSpec { | ||
c := *cfg | ||
c.Endpoints = []string{ep} | ||
return &c | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
For etcd version >= 3.6.0, we are able to get the quota by
endpoint status
query. For versions < 3.6.0, we still need to users to provide a value for this flag.It's OK to enhance this in a followup PR.