Skip to content

Commit

Permalink
feat: support build etcd with failpoint (#2)
Browse files Browse the repository at this point in the history
* feat: support build etcd with failpoint

* chore: add e2e test

* chore: fix e2e test

* chore: fix e2e test

* fix: BUILD_WITH_FAILPOINT condition

* fix: BUILD_WITH_FAILPOINT condition

* fix: vfox use when etcd build with failpoint

* opt: vfox use flow

* chore(e2e): check failpoint

* chore(e2e): fix macos go

* docs: update plugin desc

* chore: fix ci

* docs: update README

* docs: update README ref link
  • Loading branch information
yeshan333 authored May 19, 2024
1 parent fd1d142 commit 20103b2
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 11 deletions.
58 changes: 56 additions & 2 deletions .github/workflows/e2e_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: E2E tests
on:
push:
branches: [main]
pull_request:
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -38,8 +39,14 @@ jobs:
scoop install vfox
- name: add vfox-etcd plugin
if: runner.os == 'Windows'
run: |
vfox add --source https://github.com/version-fox/vfox-etcd/archive/$env:GITHUB_REF.zip etcd
- name: add vfox-etcd plugin
if: runner.os != 'Windows'
run: |
vfox add --source https://github.com/version-fox/vfox-etcd/archive/refs/heads/main.zip etcd
vfox add --source https://github.com/version-fox/vfox-etcd/archive/${GITHUB_REF}.zip etcd
- name: install etcd by vfox-etcd plugin (Linux)
if: runner.os == 'Linux'
Expand Down Expand Up @@ -72,4 +79,51 @@ jobs:
echo "===============PATH==============="
echo $env:PATH
echo "===============PATH==============="
etcd -version
etcd -version
- name: install etcd with failpoint by vfox-etcd plugin (Linux)
if: runner.os == 'Linux'
run: |
export BUILD_WITH_FAILPOINT=yes
vfox install [email protected]
vfox use -g [email protected]
eval "$(vfox activate bash)"
echo "===============PATH==============="
echo $PATH
echo "===============PATH==============="
etcd -version
export GOFAIL_HTTP="127.0.0.1:22381"
nohup etcd > etcd.log 2>&1 &
output=$(curl http://127.0.0.1:22381 | grep afterCommit)
if [ -n "$output" ]; then
echo "etcd with failpoint"
echo $output
else
echo "etcd does not with failpoint"
echo $output
exit 1
fi
- name: install etcd with failpoint by vfox-etcd plugin (MacOS)
if: runner.os == 'MacOS'
run: |
brew install go
export BUILD_WITH_FAILPOINT=yes
vfox install [email protected]
vfox use -g [email protected]
eval "$(vfox activate bash)"
echo "===============PATH==============="
echo $PATH
echo "===============PATH==============="
etcd -version
export GOFAIL_HTTP="127.0.0.1:22381"
nohup etcd > etcd.log 2>&1 &
output=$(curl http://127.0.0.1:22381 | grep afterCommit)
if [ -n "$output" ]; then
echo "etcd with failpoint"
echo $output
else
echo "etcd does not with failpoint"
echo $output
exit 1
fi
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,37 @@

# vfox-etcd plugin

etcd [vfox](https://github.com/version-fox) plugin. Use the vfox to manage multiple [etcd](https://etcd.io/) versions in Linux/Darwin MacOS/Windows.
etcd [vfox](https://github.com/version-fox) plugin. Use the vfox to manage multiple [etcd](https://etcd.io/) & etcdctl & etcductl versions in Linux/Darwin MacOS/Windows. Also can be used to build etcd with [failpoint](https://github.com/etcd-io/etcd/tree/main/tests/robustness#running-locally).

## Usage

```shell
# install plugin
vfox add --source https://github.com/version-fox/vfox-etcd/archive/refs/heads/main.zip etcd

# install an available version
# install an available etcd version
vofx search etcd
# or specific version
vfox install [email protected]
```

### etcd with failpoint (Only support in Unix-like OS system)

For the [chaos testing](https://testsigma.com/blog/chaos-testing/) proposal, you can also utilize vfox-etcd to build etcd with failpoint. Example:

**Requirements:**

- [Go 1.21+](https://go.dev/)
- [GNU Make](https://www.gnu.org/software/make/)

```shell
# install etcd with failpoint
BUILD_WITH_FAILPOINT=yes vfox install [email protected]

vfox use [email protected]
# start etcd with failpoint
GOFAIL_HTTP="127.0.0.1:22381" etcd

# get all failpoint
curl http://127.0.0.1:22381
```
6 changes: 6 additions & 0 deletions hooks/env_keys.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local etcdUtils = require("etcd_utils")

--- Each SDK may have different environment variable configurations.
--- This allows plugins to define custom environment variables (including PATH settings)
--- Note: Be sure to distinguish between environment variable settings for different platforms!
Expand All @@ -6,6 +8,10 @@
function PLUGIN:EnvKeys(ctx)
--- this variable is same as ctx.sdkInfo['plugin-name'].path
local mainPath = ctx.path
-- etcd install from source build
if etcdUtils.is_dir(ctx.path .. "/etcd/bin") then
mainPath = ctx.path .. "/etcd/bin"
end
return {
{
key = "PATH",
Expand Down
10 changes: 10 additions & 0 deletions hooks/post_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ function PLUGIN:PostInstall(ctx)
local sdkInfo = ctx.sdkInfo['etcd']
local path = sdkInfo.path
print("etcd installed path: " .. path)

BUILD_WITH_FAILPOINT = os.getenv("BUILD_WITH_FAILPOINT") or "false"
if BUILD_WITH_FAILPOINT == "yes" and RUNTIME.osType ~= "windows" then
-- Build etcd with failpoints:
local install_cmd = "cd " .. path .. " && git clone https://github.com/etcd-io/etcd.git && cd etcd && make gofail-enable && make build"
local status = os.execute(install_cmd)
if status ~= 0 then
error("etcd build with failpoint, please check the stdout for details.")
end
end
end
17 changes: 13 additions & 4 deletions hooks/pre_install.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ local etcdUtils = require("etcd_utils")
--- @field ctx.version string User-input version
--- @return table Version information
function PLUGIN:PreInstall(ctx)
local etcd_version = ctx.version
local file
local etcd_version = ctx.version
local file, download_url

-- Build etcd with failpoints: https://github.com/etcd-io/etcd/tree/main/tests/robustness#running-locally
BUILD_WITH_FAILPOINT = os.getenv("BUILD_WITH_FAILPOINT") or "false"
if BUILD_WITH_FAILPOINT == "yes" and RUNTIME.osType ~= "windows" then
return {
version = etcd_version
}
end

if RUNTIME.osType == "linux" then
file = "etcd-v" .. etcd_version .. "-" .. string.lower(RUNTIME.osType) .. "-" .. string.lower(RUNTIME.archType) .. ".tar.gz"
else
file = "etcd-v" .. etcd_version .. "-" .. string.lower(RUNTIME.osType) .. "-" .. string.lower(RUNTIME.archType) .. ".zip"
end
local checksum = etcdUtils.get_sha256sums(etcd_version, file)
local download_url = "https://github.com/etcd-io/etcd/releases/download/v" .. etcd_version .. "/" .. file
download_url = "https://github.com/etcd-io/etcd/releases/download/v" .. etcd_version .. "/" .. file
print("etcd download url: " .. download_url)

return {
version = etcd_version,
url = download_url,
Expand Down
1 change: 0 additions & 1 deletion hooks/pre_use.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ function PLUGIN:PreUse(ctx)
local path = sdkInfo.path
local name = sdkInfo.name
local used_version = sdkInfo.version

--- working directory
local cwd = ctx.cwd

Expand Down
6 changes: 6 additions & 0 deletions lib/etcd_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ function etcd_utils.get_sha256sums(etcd_version, file_name)
end
end

function etcd_utils.is_dir(path)
local status = os.execute("[ -d " .. path .. " ]")
return status == 0
end


return etcd_utils
4 changes: 2 additions & 2 deletions metadata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ PLUGIN = {}
--- Plugin name
PLUGIN.name = "etcd"
--- Plugin version
PLUGIN.version = "0.1.0"
PLUGIN.version = "0.2.0"
--- Plugin homepage
PLUGIN.homepage = "https://github.com/version-fox/vfox-etcd"
--- Plugin license, please choose a correct license according to your needs.
PLUGIN.license = "Apache 2.0"
--- Plugin description
PLUGIN.description = "etcd vfox plugin, support for managing multiple etcd versions."
PLUGIN.description = "etcd vfox plugin, support for managing multiple etcd & etcdctl & etcductl versions."


--- !!! OPTIONAL !!!
Expand Down

0 comments on commit 20103b2

Please sign in to comment.