-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
docs,tools/etcd-dump-metrics: automate metrics documentation
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright 2018 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 main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/ioutil" | ||
"net/url" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/coreos/etcd/clientv3" | ||
"github.com/coreos/etcd/embed" | ||
|
||
"go.uber.org/zap" | ||
) | ||
|
||
func newEmbedURLs(n int) (urls []url.URL) { | ||
urls = make([]url.URL, n) | ||
for i := 0; i < n; i++ { | ||
u, _ := url.Parse(fmt.Sprintf("unix://localhost:%d%06d", os.Getpid(), i)) | ||
urls[i] = *u | ||
} | ||
return urls | ||
} | ||
|
||
func setupEmbedCfg(cfg *embed.Config, curls, purls, ics []url.URL) { | ||
cfg.Logger = "zap" | ||
cfg.LogOutputs = []string{"/dev/null"} | ||
// []string{"stderr"} to enable server logging | ||
cfg.Debug = false | ||
|
||
var err error | ||
cfg.Dir, err = ioutil.TempDir(os.TempDir(), fmt.Sprintf("%016X", time.Now().UnixNano())) | ||
if err != nil { | ||
panic(err) | ||
} | ||
os.RemoveAll(cfg.Dir) | ||
|
||
cfg.ClusterState = "new" | ||
cfg.LCUrls, cfg.ACUrls = curls, curls | ||
cfg.LPUrls, cfg.APUrls = purls, purls | ||
|
||
cfg.InitialCluster = "" | ||
for i := range ics { | ||
cfg.InitialCluster += fmt.Sprintf(",%d=%s", i, ics[i].String()) | ||
} | ||
cfg.InitialCluster = cfg.InitialCluster[1:] | ||
} | ||
|
||
func getCommand(exec, name, dir, cURL, pURL, cluster string) string { | ||
s := fmt.Sprintf("%s --name %s --data-dir %s --listen-client-urls %s --advertise-client-urls %s ", | ||
exec, name, dir, cURL, cURL) | ||
s += fmt.Sprintf("--listen-peer-urls %s --initial-advertise-peer-urls %s ", pURL, pURL) | ||
s += fmt.Sprintf("--initial-cluster %s ", cluster) | ||
return s + "--initial-cluster-token tkn --initial-cluster-state new" | ||
} | ||
|
||
func write(ep string) { | ||
cli, err := clientv3.New(clientv3.Config{Endpoints: []string{strings.Replace(ep, "/metrics", "", 1)}}) | ||
if err != nil { | ||
lg.Panic("failed to create client", zap.Error(err)) | ||
} | ||
defer cli.Close() | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
_, err = cli.Put(ctx, "____test", "") | ||
if err != nil { | ||
lg.Panic("failed to write test key", zap.Error(err)) | ||
} | ||
_, err = cli.Get(ctx, "____test") | ||
if err != nil { | ||
lg.Panic("failed to read test key", zap.Error(err)) | ||
} | ||
_, err = cli.Delete(ctx, "____test") | ||
if err != nil { | ||
lg.Panic("failed to delete test key", zap.Error(err)) | ||
} | ||
cli.Watch(ctx, "____test", clientv3.WithCreatedNotify()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright 2018 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. | ||
|
||
// +build darwin | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/coreos/etcd/pkg/fileutil" | ||
) | ||
|
||
const downloadURL = `https://storage.googleapis.com/etcd/%s/etcd-%s-darwin-amd64.zip` | ||
|
||
func install(ver, dir string) (string, error) { | ||
ep := fmt.Sprintf(downloadURL, ver, ver) | ||
|
||
resp, err := http.Get(ep) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer resp.Body.Close() | ||
|
||
d, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
zipPath := filepath.Join(dir, "etcd.zip") | ||
if err = ioutil.WriteFile(zipPath, d, fileutil.PrivateFileMode); err != nil { | ||
return "", err | ||
} | ||
|
||
if err = exec.Command("bash", "-c", fmt.Sprintf("unzip %s -d %s", zipPath, dir)).Run(); err != nil { | ||
return "", err | ||
} | ||
|
||
bp1 := filepath.Join(dir, fmt.Sprintf("etcd-%s-darwin-amd64", ver), "etcd") | ||
bp2 := filepath.Join(dir, "etcd") | ||
return bp2, os.Rename(bp1, bp2) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2018 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. | ||
|
||
// +build linux | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"os/exec" | ||
"path/filepath" | ||
|
||
"github.com/coreos/etcd/pkg/fileutil" | ||
) | ||
|
||
const downloadURL = `https://storage.googleapis.com/etcd/%s/etcd-%s-linux-amd64.tar.gz` | ||
|
||
func install(ver, dir string) (string, error) { | ||
ep := fmt.Sprintf(downloadURL, ver, ver) | ||
|
||
resp, err := http.Get(ep) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer resp.Body.Close() | ||
|
||
d, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
tarPath := filepath.Join(dir, "etcd.tar.gz") | ||
if err = ioutil.WriteFile(tarPath, d, fileutil.PrivateFileMode); err != nil { | ||
return "", err | ||
} | ||
|
||
if err = exec.Command("bash", "-c", fmt.Sprintf("tar xzvf %s -C %s --strip-components=1", tarPath, dir)).Run(); err != nil { | ||
return "", err | ||
} | ||
return filepath.Join(dir, "etcd"), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2018 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. | ||
|
||
// +build windows | ||
|
||
package main | ||
|
||
import "errors" | ||
|
||
func install(ver, dir string) error { | ||
return errors.New("windows install is not supported yet") | ||
} |