Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Update from Intelsdi-x pluginsync 0.1.14
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenddn committed Apr 17, 2017
1 parent 4e88711 commit 4bcf8e6
Show file tree
Hide file tree
Showing 13 changed files with 396 additions and 35 deletions.
6 changes: 5 additions & 1 deletion .pluginsync.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# File managed by pluginsync
pluginsync_config: '0.1.9'
pluginsync_config: '0.1.14'
managed_files:
- .github
- .github/ISSUE_TEMPLATE.md
Expand All @@ -14,5 +14,9 @@ managed_files:
- scripts/build.sh
- scripts/common.sh
- scripts/deps.sh
- scripts/large.sh
- scripts/pre_deploy.sh
- scripts/test
- scripts/test/large_spec.rb
- scripts/test/spec_helper.rb
- scripts/test.sh
6 changes: 0 additions & 6 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,3 @@
matrix:
- TEST_TYPE=small
- TEST_TYPE=medium
deploy:
access_key_id: AKIAINMB43VSSPFZISAA
secret_access_key:
secure: M2MPahJfZeE1dAJcAB1mshyizhm3yJVa//4YwJz4aqNIIpT3hFyIVoIW1Ud2zXah3G5eARv8vq3WYxc//nLrQy1Baii532JkRRBkehoqhoj1+94lH/qy3qeOU1itsPYgmx8rwPLfjorIB/TdJnWJaJhEZxmuhyX0tVwM1N23WXlaDAZkYVEvT2dOhpBiQJRmbPzO9LBXd2KewRrs+NQNP1TEQjISqKHtA6wPlHRNkMe7BPrTzBJ8uciaiXsf0T+RdIsqX6W+h+nBUPv0S/V3VYR/TXvKSzkWcUf30lwLYT439/hFoRiNhMLcDDwl4bxHrU1RrlSS8JF1+2SuXltx1l7HU9wUk+meKEciHiHDBPTu1Ouy/9HfbAzyVZ5UXM/aeEB3j3lfjQezG2JzVvHap4wjtvMmifhYKPkHpB4C+nlMyvPwtncg11/9KNdABB5g/xvvh66YeD7RdW9KyOaaaipBC489Y72o1UZUZo7NYPRIhnJFJSxQoN1n9yYn6st9dfczhWmdnPFYac+iMUTkD7XezRH4D7aEMGMrvfdsGUB0WW8iaUn3csk0TDqnnzy75Uqj0Ddpthu6J60g+6AI0SMkK0b7XlsTALRq3eGO9SGHq23o57M0YzSMWgyjOgLeUhngUpfgDJM76jtmPJckAjFl7UJsGeFS91w0E1+fu0Y=
api_key:
secure: xBP1/9GdLtYHGUKXk/ac7t+NNodLo16fucPfqLoxC23Rw3a84vMluVZheWplSVbiTmuOVn777EfoK2ej0nTGL7+iNLc/z84pqDM5kW6Bo/EO5J9r54DpMcEznbkxsNyXtNdeX5EO7Ufs35+eU2cuvZ8YeIs3NNna6EBcB/JD7DlVKcLq4oKeMLafEs2vDSaFRDrgirtQhIU8525LCVSNwK3MiBPZnRMcTj6i0GLtz5BnVOBwgIElYhDawkIBnYmVxoBSMD7OyOfDt5zAq/1WJuoFj9zxjcTvCSKkgyno0ziDy3HrhV07QOy9gZ8nPUXPRI1u1cz0J3WLErvj0hmoBsOYbFGB6PpYwyjPZb0Pa8KrNqHYrVdgEu9VP6Y6y+YwzHOLqn8rFSaTCwlWlDN4Z9iso3jrbDfVdSKDb/GGF7MhWG981eresWB0jYpx3kJJ5mQtFTa0uD+udyYDyrvp5EP1MNxMCAkcg7s23E/517hcctFKCRRc5qt7ulDOD8djhYCQDTZlBkv5K6sWhILcyXMFsbKVLRc6pRYbdBN8P3BJ+6MkqxhQuu+ae7UQbAWtJxkPGWkaz3mYVEUUuu7Jne3wCs1lXbU0ORPuqSDhZckOuBpF4yd7WnBliqIrQ1TNc5K9eO3nLdWcF0gMLopOLDHw8MrI1EPGzlpIlx9Aink=
27 changes: 12 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
sudo: false
language: go
go:
- 1.6.3
- 1.7.3
- 1.7.x
- 1.8.x
env:
global:
- ORG_PATH=/home/travis/gopath/src/github.com/intelsdi-x
- SNAP_PLUGIN_SOURCE=/home/travis/gopath/src/github.com/${TRAVIS_REPO_SLUG}
matrix:
- TEST_TYPE=small
- TEST_TYPE=medium
- TEST_TYPE=build
- TEST_TYPE: build
matrix:
exclude:
- go: 1.6.3
- go: 1.7.x
env: TEST_TYPE=build
before_install:
- "[[ -d $SNAP_PLUGIN_SOURCE ]] || mkdir -p $ORG_PATH && ln -s $TRAVIS_BUILD_DIR $SNAP_PLUGIN_SOURCE"
Expand All @@ -31,9 +31,8 @@ before_deploy:
- "./scripts/pre_deploy.sh"
deploy:
- provider: s3
access_key_id: AKIAINMB43VSSPFZISAA
secret_access_key:
secure: M2MPahJfZeE1dAJcAB1mshyizhm3yJVa//4YwJz4aqNIIpT3hFyIVoIW1Ud2zXah3G5eARv8vq3WYxc//nLrQy1Baii532JkRRBkehoqhoj1+94lH/qy3qeOU1itsPYgmx8rwPLfjorIB/TdJnWJaJhEZxmuhyX0tVwM1N23WXlaDAZkYVEvT2dOhpBiQJRmbPzO9LBXd2KewRrs+NQNP1TEQjISqKHtA6wPlHRNkMe7BPrTzBJ8uciaiXsf0T+RdIsqX6W+h+nBUPv0S/V3VYR/TXvKSzkWcUf30lwLYT439/hFoRiNhMLcDDwl4bxHrU1RrlSS8JF1+2SuXltx1l7HU9wUk+meKEciHiHDBPTu1Ouy/9HfbAzyVZ5UXM/aeEB3j3lfjQezG2JzVvHap4wjtvMmifhYKPkHpB4C+nlMyvPwtncg11/9KNdABB5g/xvvh66YeD7RdW9KyOaaaipBC489Y72o1UZUZo7NYPRIhnJFJSxQoN1n9yYn6st9dfczhWmdnPFYac+iMUTkD7XezRH4D7aEMGMrvfdsGUB0WW8iaUn3csk0TDqnnzy75Uqj0Ddpthu6J60g+6AI0SMkK0b7XlsTALRq3eGO9SGHq23o57M0YzSMWgyjOgLeUhngUpfgDJM76jtmPJckAjFl7UJsGeFS91w0E1+fu0Y=
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: snap.ci.snap-telemetry.io
region: us-west-2
skip_cleanup: true
Expand All @@ -43,11 +42,10 @@ deploy:
on:
repo: intelsdi-x/snap-plugin-publisher-kafka
branch: master
condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.3"
condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION =~ ^1\.8(|\.[0-9]+)$
- provider: s3
access_key_id: AKIAINMB43VSSPFZISAA
secret_access_key:
secure: M2MPahJfZeE1dAJcAB1mshyizhm3yJVa//4YwJz4aqNIIpT3hFyIVoIW1Ud2zXah3G5eARv8vq3WYxc//nLrQy1Baii532JkRRBkehoqhoj1+94lH/qy3qeOU1itsPYgmx8rwPLfjorIB/TdJnWJaJhEZxmuhyX0tVwM1N23WXlaDAZkYVEvT2dOhpBiQJRmbPzO9LBXd2KewRrs+NQNP1TEQjISqKHtA6wPlHRNkMe7BPrTzBJ8uciaiXsf0T+RdIsqX6W+h+nBUPv0S/V3VYR/TXvKSzkWcUf30lwLYT439/hFoRiNhMLcDDwl4bxHrU1RrlSS8JF1+2SuXltx1l7HU9wUk+meKEciHiHDBPTu1Ouy/9HfbAzyVZ5UXM/aeEB3j3lfjQezG2JzVvHap4wjtvMmifhYKPkHpB4C+nlMyvPwtncg11/9KNdABB5g/xvvh66YeD7RdW9KyOaaaipBC489Y72o1UZUZo7NYPRIhnJFJSxQoN1n9yYn6st9dfczhWmdnPFYac+iMUTkD7XezRH4D7aEMGMrvfdsGUB0WW8iaUn3csk0TDqnnzy75Uqj0Ddpthu6J60g+6AI0SMkK0b7XlsTALRq3eGO9SGHq23o57M0YzSMWgyjOgLeUhngUpfgDJM76jtmPJckAjFl7UJsGeFS91w0E1+fu0Y=
access_key_id: $AWS_ACCESS_KEY_ID
secret_access_key: $AWS_SECRET_ACCESS_KEY
bucket: snap.ci.snap-telemetry.io
region: us-west-2
skip_cleanup: true
Expand All @@ -57,15 +55,14 @@ deploy:
on:
repo: intelsdi-x/snap-plugin-publisher-kafka
tags: true
condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.3"
condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION =~ ^1\.8(|\.[0-9]+)$
- provider: releases
api_key:
secure: xBP1/9GdLtYHGUKXk/ac7t+NNodLo16fucPfqLoxC23Rw3a84vMluVZheWplSVbiTmuOVn777EfoK2ej0nTGL7+iNLc/z84pqDM5kW6Bo/EO5J9r54DpMcEznbkxsNyXtNdeX5EO7Ufs35+eU2cuvZ8YeIs3NNna6EBcB/JD7DlVKcLq4oKeMLafEs2vDSaFRDrgirtQhIU8525LCVSNwK3MiBPZnRMcTj6i0GLtz5BnVOBwgIElYhDawkIBnYmVxoBSMD7OyOfDt5zAq/1WJuoFj9zxjcTvCSKkgyno0ziDy3HrhV07QOy9gZ8nPUXPRI1u1cz0J3WLErvj0hmoBsOYbFGB6PpYwyjPZb0Pa8KrNqHYrVdgEu9VP6Y6y+YwzHOLqn8rFSaTCwlWlDN4Z9iso3jrbDfVdSKDb/GGF7MhWG981eresWB0jYpx3kJJ5mQtFTa0uD+udyYDyrvp5EP1MNxMCAkcg7s23E/517hcctFKCRRc5qt7ulDOD8djhYCQDTZlBkv5K6sWhILcyXMFsbKVLRc6pRYbdBN8P3BJ+6MkqxhQuu+ae7UQbAWtJxkPGWkaz3mYVEUUuu7Jne3wCs1lXbU0ORPuqSDhZckOuBpF4yd7WnBliqIrQ1TNc5K9eO3nLdWcF0gMLopOLDHw8MrI1EPGzlpIlx9Aink=
api_key: $GITHUB_API_KEY
file:
- release/snap-plugin-publisher-kafka_linux_x86_64
- release/snap-plugin-publisher-kafka_darwin_x86_64
skip_cleanup: true
on:
repo: intelsdi-x/snap-plugin-publisher-kafka
tags: true
condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION = "1.7.3"
condition: $TEST_TYPE = "build" && $TRAVIS_GO_VERSION =~ ^1\.8(|\.[0-9]+)$
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ $ git clone https://github.com/intelsdi-x/snap-plugin-publisher-kafka.git
```
$ git checkout -b some-topic-branch
```
* Make your changes and run the test suite if one is provided.
* Make your changes to the code and add tests to cover contributed code.
* Validate the changes and run the test suite if one is provided.
* Commit your changes and push them to your fork.
* Open a pull request for the appropriate project.
* Contributors will review your pull request, suggest changes, and merge it when it’s ready and/or offer feedback.
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ test-medium:
bash -c "./scripts/test.sh medium"
test-large:
bash -c "./scripts/test.sh large"
test-all:
$(MAKE) test-small
$(MAKE) test-medium
$(MAKE) test-large
check:
$(MAKE) test
all:
bash -c "./scripts/build.sh $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))"
bash -c "./scripts/build.sh"
2 changes: 1 addition & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# File managed by pluginsync

# http://www.apache.org/licenses/LICENSE-2.0.txt
Expand Down
17 changes: 14 additions & 3 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# File managed by pluginsync

# http://www.apache.org/licenses/LICENSE-2.0.txt
Expand All @@ -24,6 +24,7 @@ set -o pipefail

LOG_LEVEL="${LOG_LEVEL:-6}"
NO_COLOR="${NO_COLOR:-}"
NO_GO_TEST=${NO_GO_TEST:-'-not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*"'}

trap_exitcode() {
exit $?
Expand Down Expand Up @@ -54,8 +55,14 @@ _notice () { [ "${LOG_LEVEL}" -ge 5 ] && echo "$(_fmt notice) ${*}" 1>&2 || tru
_warning () { [ "${LOG_LEVEL}" -ge 4 ] && echo "$(_fmt warning) ${*}" 1>&2 || true; }
_error () { [ "${LOG_LEVEL}" -ge 3 ] && echo "$(_fmt error) ${*}" 1>&2 || true; exit 1; }

_test_files() {
local test_files=$(sh -c "find . -type f -name '*.go' ${NO_GO_TEST} -print")
_debug "go source files ${test_files}"
echo "${test_files}"
}

_test_dirs() {
local test_dirs=$(find . -type f -name '*.go' -not -path "./.*" -not -path "*/_*" -not -path "./Godeps/*" -not -path "./vendor/*" -print0 | xargs -0 -n1 dirname| sort -u)
local test_dirs=$(sh -c "find . -type f -name '*.go' ${NO_GO_TEST} -print0" | xargs -0 -n1 dirname | sort -u)
_debug "go code directories ${test_dirs}"
echo "${test_dirs}"
}
Expand All @@ -69,9 +76,13 @@ _go_get() {
type -p "${_util}" > /dev/null || go get "${_url}" && _debug "go get ${_util} ${_url}"
}

_gofmt() {
test -z "$(gofmt -l -d $(_test_files) | tee /dev/stderr)"
}

_goimports() {
_go_get golang.org/x/tools/cmd/goimports
test -z "$(goimports -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)"
test -z "$(goimports -l -d $(_test_files) | tee /dev/stderr)"
}

_golint() {
Expand Down
2 changes: 1 addition & 1 deletion scripts/deps.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# File managed by pluginsync

# http://www.apache.org/licenses/LICENSE-2.0.txt
Expand Down
38 changes: 38 additions & 0 deletions scripts/large.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# File managed by pluginsync

set -e
set -u
set -o pipefail

__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__proj_dir="$(dirname "$__dir")"
__proj_name="$(basename "$__proj_dir")"

# shellcheck source=scripts/common.sh
. "${__dir}/common.sh"

_verify_docker() {
type -p docker > /dev/null 2>&1 || _error "docker needs to be installed"
type -p docker-compose > /dev/null 2>&1 || _error "docker-compose needs to be installed"
docker version >/dev/null 2>&1 || _error "docker needs to be configured/running"
}

_verify_docker

[[ -f "${__proj_dir}/build/linux/x86_64/${__proj_name}" ]] || (cd "${__proj_dir}" && make)

SNAP_VERSION=${SNAP_VERSION:-"latest"}
OS=${OS:-"alpine"}
PLUGIN_PATH=${PLUGIN_PATH:-"${__proj_dir}"}
DEMO=${DEMO:-"false"}
TASK=${TASK:-""}

if [[ ${DEBUG:-} == "true" ]]; then
cmd="cd /plugin/scripts && rescue rspec ./test/*_spec.rb"
else
cmd="cd /plugin/scripts && rspec ./test/*_spec.rb"
fi

_info "running large test"
docker run -v /var/run/docker.sock:/var/run/docker.sock -v "${__proj_dir}":/plugin -e DEMO="${DEMO}" -e TASK="${TASK}" -e PLUGIN_PATH="${PLUGIN_PATH}" -e SNAP_VERSION="${SNAP_VERSION}" -e OS="${OS}" -ti intelsdi/serverspec:alpine /bin/sh -c "${cmd}"
2 changes: 1 addition & 1 deletion scripts/pre_deploy.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# File managed by pluginsync

# http://www.apache.org/licenses/LICENSE-2.0.txt
Expand Down
9 changes: 4 additions & 5 deletions scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash
# File managed by pluginsync

# http://www.apache.org/licenses/LICENSE-2.0.txt
Expand Down Expand Up @@ -35,12 +35,10 @@ __proj_dir="$(dirname "$__dir")"

_debug "script directory ${__dir}"
_debug "project directory ${__proj_dir}"
_info "skipping go test in following directories: ${NO_GO_TEST}"

[[ "$TEST_TYPE" =~ ^(small|medium|large|legacy|build)$ ]] || _error "invalid TEST_TYPE (value must be 'small', 'medium', 'large', 'legacy', or 'build' recieved:${TEST_TYPE}"

_gofmt() {
test -z "$(gofmt -l -d $(find . -type f -name '*.go' -not -path "./vendor/*") | tee /dev/stderr)"
}

test_unit() {
# The script does automatic checking on a Go package and its sub-packages, including:
Expand Down Expand Up @@ -70,6 +68,7 @@ test_unit() {
}

if [[ $TEST_TYPE == "legacy" ]]; then
UNIT_TEST="go_test go_cover"
echo "mode: count" > profile.cov
export TEST_TYPE="unit"
test_unit
Expand All @@ -94,7 +93,7 @@ elif [[ $TEST_TYPE == "large" ]]; then
elif [[ -f "${__dir}/large_compose.sh" ]]; then
. "${__dir}/large_compose.sh"
else
_info "No large tests."
. "${__dir}/large.sh"
fi
elif [[ $TEST_TYPE == "build" ]]; then
"${__dir}/build.sh"
Expand Down
133 changes: 133 additions & 0 deletions scripts/test/large_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# File managed by pluginsync

require_relative './spec_helper'
require 'specinfra/backend/docker_compose'

compose_yml = File.expand_path(File.join(__FILE__, "../docker-compose.yml"))
raise(Exception, "Missing docker-compose file: #{compose_yml}") unless File.exists? compose_yml

# NOTE: scan docker compose file and pull latest containers:
images = File.readlines(compose_yml).select {|l| l =~ /^\s*image:/}
images = images.collect{|l| l.split('image:').last.strip }.uniq
images.each do |i|
puts `docker pull #{i}`
end

set :docker_compose_container, :snap

describe docker_compose(compose_yml) do

# NOTE: If you need to wait for a service or create a database perform it in setup.rb
setup = File.expand_path(File.join(__FILE__, '../setup.rb'))
eval File.read setup if File.exists? setup

its_container(:snap) do
describe 'docker-compose.yml run' do
TIMEOUT = 60

describe "download Snap" do
it {
expect(cmd_with_retry("/opt/snap/bin/snaptel --version", :timeout => TIMEOUT).exit_status).to eq 0
expect(cmd_with_retry("/opt/snap/sbin/snapteld --version", :timeout => TIMEOUT).exit_status).to eq 0
}
end

if os[:family] == 'alpine'
describe port(8181) do
it { should be_listening }
end
end

context "load Snap plugins" do
describe command("snaptel plugin list") do
it { load_all_plugins }
its(:exit_status) { should eq 0 }
its(:stdout) {
plugins.each do |p|
_ , name = p
should contain(/#{name}/)
end
}
end
end

describe file("/opt/snap/sbin/snapteld") do
it { should be_file }
it { should be_executable }
end

describe file("/opt/snap/bin/snaptel") do
it { should be_file }
it { should be_executable }
end

describe command("snapteld --version") do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain(/#{ENV['SNAP_VERSION']}/) }
end if ENV['SNAP_VERSION'] =~ /^\d+.\d+.\d+$/

SnapUtils.tasks.each do |t|
context "Snap task #{t}" do
task_id = nil

describe command("snaptel task create -t /plugin/examples/tasks/#{t}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain(/Task created/) }
it {
id = subject.stdout.split("\n").find{|l|l=~/^ID:/}
task_id = $1 if id.match(/^ID: (.*)$/)
expect(task_id).to_not be_nil
# NOTE we need a short pause before checking task state in case it fails:
sleep 3
}
end

describe command("snaptel task list") do
its(:exit_status) { should eq 0 }
its(:stdout) { should contain(/Running/) }
end

describe "Metrics in running tasks" do
it {
binding.pry if ENV["DEMO"] == "true"

data = curl_json_api("http://127.0.0.1:8181/v1/tasks")
task = data["body"]["ScheduledTasks"].find{|i| i['id'] == task_id}
expect(task['id']).to eq task_id
data = curl_json_api(task['href'])
collect_metrics = data["body"]["workflow"]["collect"]["metrics"].collect{|k,v| k}

config = load_yaml(SnapUtils.examples/"tasks/#{t}")
config_metrics = config['workflow']['collect']['metrics'].collect{|k,v| k}

config_metrics.each do |m|
expect(collect_metrics).to include(m)
end
}
end

# NOTE: can not use the normal describe command(...) since we need to access task_id
describe "Stop task" do
it {
c = command("snaptel task stop #{task_id}")
expect(c.exit_status).to eq 0
expect(c.stdout).to match(/Task stopped/)
}
end

describe "Remove task" do
it {
c = command("snaptel task remove #{task_id}")
expect(c.exit_status).to eq 0
expect(c.stdout).to match(/Task removed/)
}
end
end
end
end
end

# NOTE: If you need to perform additional checks such as database verification it be done at the end:
verify = File.expand_path(File.join(__FILE__, '../verify.rb'))
eval File.read verify if File.exists? verify
end
Loading

0 comments on commit 4bcf8e6

Please sign in to comment.