├── .github └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── README.md ├── cmd └── snaptel │ ├── commands.go │ ├── config.go │ ├── flags.go │ ├── main.go │ ├── metric.go │ ├── plugin.go │ ├── sample │ ├── psutil-file.json │ └── psutil-influx.json │ ├── task.go │ └── tribe.go ├── control ├── available_plugin.go ├── available_plugin_test.go ├── config.go ├── config_test.go ├── control.go ├── control_grpc_server.go ├── control_grpc_server_test.go ├── control_security_test.go ├── control_test.go ├── fixtures │ ├── fixtures.go │ └── tls_cert_util.go ├── flags.go ├── metrics.go ├── metrics_small_test.go ├── metrics_test.go ├── monitor.go ├── monitor_test.go ├── mttrie.go ├── mttrie_medium_test.go ├── plugin │ ├── client │ │ ├── client.go │ │ ├── grpc.go │ │ ├── grpc_test.go │ │ └── native.go │ ├── collector_deprecated.go │ ├── collector_proxy.go │ ├── collector_proxy_deprecated.go │ ├── collector_proxy_test.go │ ├── collector_test.go │ ├── cpolicy │ │ ├── bool.go │ │ ├── bool_test.go │ │ ├── float.go │ │ ├── float_test.go │ │ ├── integer.go │ │ ├── integer_test.go │ │ ├── node.go │ │ ├── node_test.go │ │ ├── rule.go │ │ ├── string.go │ │ ├── string_test.go │ │ ├── tree.go │ │ └── tree_test.go │ ├── encoding │ │ ├── encoding.go │ │ ├── gob.go │ │ └── json.go │ ├── encrypter │ │ ├── encrypter.go │ │ └── encrypter_test.go │ ├── execution.go │ ├── execution_test.go │ ├── metric.go │ ├── metric_deprecated.go │ ├── metric_test.go │ ├── plugin.go │ ├── plugin_deprecated.go │ ├── plugin_test.go │ ├── processor_deprecated.go │ ├── processor_proxy.go │ ├── processor_proxy_deprecated.go │ ├── processor_test.go │ ├── publisher_deprecated.go │ ├── publisher_proxy.go │ ├── publisher_proxy_deprecated.go │ ├── publisher_test.go │ ├── rpc │ │ ├── plugin.go │ │ ├── plugin.pb.go │ │ └── plugin.proto │ ├── session.go │ ├── session_deprecated.go │ └── session_test.go ├── plugin_manager.go ├── plugin_manager_test.go ├── runner.go ├── runner_test.go ├── strategy │ ├── cache.go │ ├── cache_small_test.go │ ├── cache_test.go │ ├── config_based.go │ ├── config_based_test.go │ ├── fixtures │ │ └── fixtures.go │ ├── lru.go │ ├── pool.go │ ├── pool_test.go │ ├── sticky.go │ ├── sticky_test.go │ └── strategy.go ├── subscription_group.go └── subscription_group_medium_test.go ├── core ├── cdata │ ├── node.go │ ├── node_test.go │ ├── tree.go │ └── tree_test.go ├── control_event │ └── control_event.go ├── core.go ├── ctypes │ └── ctypes.go ├── metric.go ├── metric_test.go ├── plugin.go ├── plugin_test.go ├── schedule.go ├── schedule_small_test.go ├── scheduler_event │ └── scheduler_event.go ├── serror │ └── serror.go ├── subscription_group.go ├── task.go ├── task_medium_test.go ├── tribe_event │ └── tribe_event.go └── workflow.go ├── doc.go ├── docs ├── AUTHORS.md ├── BUILD_AND_TEST.md ├── DISTRIBUTED_WORKFLOW_ARCHITECTURE.md ├── GLOSSARY.md ├── LARGE_TESTS.md ├── MAINTAINERS.md ├── METRICS.md ├── PLUGIN_AUTHORING.md ├── PLUGIN_CATALOG.md ├── PLUGIN_DIAGNOSTICS.md ├── PLUGIN_LIFECYCLE.md ├── PLUGIN_PACKAGING.md ├── PLUGIN_SIGNING.md ├── PLUGIN_STATUS.md ├── PROFILING.md ├── REST_API_V1.md ├── REST_API_V2.md ├── SECURE_PLUGIN_COMMUNICATION.md ├── SETUP_TLS_CERTIFICATES.md ├── SNAPTEL.md ├── SNAPTELD.md ├── SNAPTELD_CONFIGURATION.md ├── STAND-ALONE_MODE.md ├── STREAMING.md ├── TASKS.md ├── TRIBE.md └── plugins.yml ├── examples ├── README.md ├── configs │ ├── README.md │ ├── snap-config-empty.yaml │ ├── snap-config-sample.json │ ├── snap-config-sample.yaml │ ├── snaptel-config-sample.json │ └── snapteld.conf └── tasks │ └── psutil-file.yaml ├── glide.lock ├── glide.yaml ├── grpc ├── common │ ├── common.go │ ├── common.pb.go │ └── common.proto └── controlproxy │ ├── controlproxy.go │ ├── controlproxy_medium_test.go │ └── rpc │ ├── control.go │ ├── control.pb.go │ └── control.proto ├── mgmt ├── rest │ ├── api │ │ ├── api.go │ │ ├── config.go │ │ ├── metric.go │ │ ├── task.go │ │ └── tribe.go │ ├── client │ │ ├── README.md │ │ ├── client.go │ │ ├── client_config_func_test.go │ │ ├── client_func_test.go │ │ ├── client_tribe_func_test.go │ │ ├── config.go │ │ ├── metric.go │ │ ├── plugin.go │ │ ├── task.go │ │ └── tribe.go │ ├── config.go │ ├── flags.go │ ├── log_handler.go │ ├── pprof.go │ ├── readme.md │ ├── rest_test.go │ ├── rest_v1_test.go │ ├── rest_v2_test.go │ ├── server.go │ ├── server_test.go │ ├── snapTLS.go │ ├── tribe_v1_test.go │ ├── v1 │ │ ├── api.go │ │ ├── config.go │ │ ├── fixtures │ │ │ ├── mock_config_manager.go │ │ │ ├── mock_metric_manager.go │ │ │ ├── mock_task_manager.go │ │ │ └── mock_tribe_manager.go │ │ ├── metric.go │ │ ├── metric_test.go │ │ ├── plugin.go │ │ ├── plugin_test.go │ │ ├── rbody │ │ │ ├── body.go │ │ │ ├── config.go │ │ │ ├── error.go │ │ │ ├── metric.go │ │ │ ├── plugin.go │ │ │ ├── task.go │ │ │ └── tribe.go │ │ ├── task.go │ │ └── tribe.go │ ├── v2 │ │ ├── api.go │ │ ├── config.go │ │ ├── error.go │ │ ├── metric.go │ │ ├── metric_test.go │ │ ├── mock │ │ │ ├── mock_config_manager.go │ │ │ ├── mock_metric_manager.go │ │ │ └── mock_task_manager.go │ │ ├── plugin.go │ │ ├── task.go │ │ └── watch.go │ └── wmap_sample │ │ ├── 1.json │ │ ├── 2.json │ │ ├── 3.json │ │ └── bad.json └── tribe │ ├── agreement │ └── agreement.go │ ├── broadcast.go │ ├── clock.go │ ├── config.go │ ├── config_test.go │ ├── delegate.go │ ├── flags.go │ ├── member_delegate.go │ ├── messages.go │ ├── query.go │ ├── tribe.go │ ├── tribe_test.go │ └── worker │ ├── worker.go │ └── worker_test.go ├── pkg ├── aci │ └── aci.go ├── cfgfile │ ├── cfgfile.go │ ├── cfgfile_small_test.go │ └── cfgfile_test.go ├── chrono │ ├── chrono.go │ └── chrono_test.go ├── ctree │ ├── tree.go │ └── tree_test.go ├── fileutils │ └── file.go ├── netutil │ ├── net.go │ └── net_medium_test.go ├── promise │ ├── promise.go │ └── promise_test.go ├── psigning │ ├── psigning.go │ ├── psigning_test.go │ ├── pubkeys.gpg │ ├── pubring.gpg │ ├── snap-plugin-collector-mock1 │ └── snap-plugin-collector-mock1.asc ├── rpcutil │ ├── rpc.go │ └── rpc_medium_test.go ├── schedule │ ├── cron_schedule.go │ ├── cron_schedule_test.go │ ├── schedule.go │ ├── streaming_schedule.go │ ├── windowed_schedule.go │ ├── windowed_schedule_medium_test.go │ └── windowed_schedule_small_test.go └── stringutils │ └── string.go ├── plugin ├── README.md ├── collector │ ├── README.md │ ├── snap-plugin-collector-anothermock1 │ │ ├── README.md │ │ ├── anothermock │ │ │ ├── README.md │ │ │ ├── anothermock.go │ │ │ └── anothermock_medium_test.go │ │ ├── main.go │ │ ├── main_small_test.go │ │ └── main_test.go │ ├── snap-plugin-collector-mock1 │ │ ├── README.md │ │ ├── main.go │ │ ├── main_small_test.go │ │ ├── main_test.go │ │ └── mock │ │ │ ├── README.md │ │ │ ├── mock.go │ │ │ └── mock_medium_test.go │ ├── snap-plugin-collector-mock2-grpc │ │ ├── README.md │ │ ├── main.go │ │ ├── main_small_test.go │ │ ├── main_test.go │ │ └── mock │ │ │ ├── README.md │ │ │ ├── mock.go │ │ │ └── mock_medium_test.go │ ├── snap-plugin-collector-mock2 │ │ ├── README.md │ │ ├── main.go │ │ ├── main_small_test.go │ │ ├── main_test.go │ │ └── mock │ │ │ ├── README.md │ │ │ ├── mock.go │ │ │ └── mock_medium_test.go │ └── snap-plugin-streaming-collector-rand1 │ │ ├── README.md │ │ ├── main.go │ │ └── rand │ │ └── rand.go ├── helper │ ├── README.md │ └── helper.go ├── processor │ ├── README.md │ ├── snap-plugin-processor-passthru-grpc │ │ ├── main.go │ │ ├── main_small_test.go │ │ └── passthru │ │ │ └── passthru.go │ └── snap-plugin-processor-passthru │ │ ├── README.md │ │ ├── main.go │ │ ├── main_small_test.go │ │ └── passthru │ │ ├── README.md │ │ └── passthru.go └── publisher │ ├── README.md │ ├── snap-plugin-publisher-mock-file-grpc │ ├── README.md │ ├── file │ │ ├── file.go │ │ └── file_small_test.go │ ├── main.go │ ├── main_small_test.go │ └── main_test.go │ └── snap-plugin-publisher-mock-file │ ├── README.md │ ├── file │ ├── README.md │ ├── file.go │ └── file_small_test.go │ ├── main.go │ ├── main_small_test.go │ └── main_test.go ├── scheduler ├── config.go ├── config_test.go ├── distributed_task_test.go ├── fixtures │ └── fixtures.go ├── flags.go ├── job.go ├── job_test.go ├── managers.go ├── queue.go ├── queue_test.go ├── scheduler.go ├── scheduler_medium_test.go ├── scheduler_test.go ├── task.go ├── task_test.go ├── watcher.go ├── watcher_test.go ├── wmap │ ├── fixtures │ │ └── tasks.go │ ├── sample │ │ ├── 1.json │ │ ├── 1.yml │ │ ├── 2.json │ │ └── rest-1.json │ ├── string.go │ ├── wmap.go │ ├── wmap_small_test.go │ └── wmap_test.go ├── work_manager.go ├── work_manager_test.go ├── worker.go ├── worker_test.go ├── workflow.go ├── workflow_string.go ├── workflow_string_test.go └── workflow_test.go ├── scripts ├── Dockerfile ├── build_all.sh ├── build_plugin.sh ├── build_plugins.sh ├── build_snap.sh ├── common.sh ├── deps.sh ├── gen-proto.sh ├── gitcookie.sh ├── pre_deploy.sh ├── run_tests_with_docker.sh ├── swagger.sh └── test.sh ├── snapteld.go ├── snapteld_test.go ├── swagger.json └── third_party_licenses ├── README.md ├── app_container_license.txt ├── cli_license.txt ├── cron_license.txt ├── go_cryptography_license.txt ├── go_msgpack_license.txt ├── go_networking_licenses.txt ├── gojsonschema_license.txt ├── govalidator_license.txt ├── grpc_go_license.txt ├── httprouter_license.txt ├── jsonutil_license.txt ├── logrus_license.txt ├── memberlist_license.txt ├── negroni_license.txt ├── protobuf_license.txt ├── uuid_license.txt ├── yaml_license.txt └── yaml_v2_license.txt /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Fixes # 2 | 3 | Summary of changes: 4 | - 5 | - 6 | - 7 | 8 | Testing done: 9 | - 10 | 11 | @intelsdi-x/snap-maintainers 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | .idea 25 | tmp/ 26 | *.tmp 27 | scratch/ 28 | *.swp 29 | profile.cov 30 | gin-bin 31 | tags 32 | .vscode/ 33 | vendor/ 34 | 35 | # we don't vendor godep _workspace 36 | **/Godeps/_workspace/** 37 | 38 | # OSX stuff 39 | .DS_Store 40 | 41 | *.cov 42 | 43 | # build and release artifacts 44 | build/ 45 | s3/ 46 | release/ 47 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: true 2 | language: go 3 | go: 4 | - 1.9.x 5 | - 1.8.x 6 | - 1.7.x 7 | before_install: 8 | - bash scripts/gitcookie.sh 9 | - go get github.com/smartystreets/goconvey/convey 10 | - if [ ! -d $SNAP_SOURCE ]; then mkdir -p $HOME/gopath/src/github.com/intelsdi-x; ln -s $TRAVIS_BUILD_DIR $SNAP_SOURCE; fi # CI for forks not from intelsdi-x 11 | - go get -u github.com/alecthomas/gometalinter 12 | env: 13 | global: 14 | - SNAP_SOURCE=/home/travis/gopath/src/github.com/intelsdi-x/snap 15 | - GO15VENDOREXPERIMENT=1 16 | - GLIDE_HOME="${HOME}/.glide" 17 | matrix: 18 | - SNAP_TEST_TYPE=legacy 19 | - SNAP_TEST_TYPE=small 20 | - SNAP_TEST_TYPE=medium 21 | - SNAP_TEST_TYPE=build 22 | install: 23 | - export TMPDIR=$HOME/tmp 24 | - mkdir -p $TMPDIR 25 | - cd $SNAP_SOURCE # change dir into source 26 | - make 27 | - gometalinter --install 28 | script: 29 | - make test 2>&1 # Run test suite 30 | - gometalinter ./... || true 31 | notifications: 32 | email: false 33 | slack: 34 | secure: VkbZLIc2RH8yf3PtIAxUNPdAu3rQQ7yQx0GcK124JhbEnZGaHyK615V0rbG7HcVmYKGPdB0cXqZiLBDKGqGKb2zR1NepOe1nF03jxGSpPq8jIFeEXSJGEYGL34ScDzZZGuG6qwbjFcXiW5lqn6t8igzp7v2+URYBaZo5ktCS2xY= 35 | before_deploy: 36 | - make all 37 | - "./scripts/pre_deploy.sh" 38 | deploy: 39 | - provider: s3 40 | access_key_id: $AWS_ACCESS_KEY_ID 41 | secret_access_key: $AWS_SECRET_ACCESS_KEY 42 | bucket: snap.ci.snap-telemetry.io 43 | region: us-west-2 44 | skip_cleanup: true 45 | local-dir: s3/snap 46 | upload-dir: snap 47 | acl: public_read 48 | on: 49 | repo: intelsdi-x/snap 50 | branch: master 51 | condition: $SNAP_TEST_TYPE = build && $TRAVIS_GO_VERSION = "1.7.3" 52 | - provider: s3 53 | access_key_id: $AWS_ACCESS_KEY_ID 54 | secret_access_key: $AWS_SECRET_ACCESS_KEY 55 | bucket: snap.ci.snap-telemetry.io 56 | region: us-west-2 57 | skip_cleanup: true 58 | local-dir: s3/snap 59 | upload-dir: snap 60 | acl: public_read 61 | on: 62 | repo: intelsdi-x/snap 63 | tags: true 64 | condition: $SNAP_TEST_TYPE = build && $TRAVIS_GO_VERSION = "1.7.3" 65 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #http://www.apache.org/licenses/LICENSE-2.0.txt 2 | # 3 | # 4 | #Copyright 2015 Intel Corporation 5 | # 6 | #Licensed under the Apache License, Version 2.0 (the "License"); 7 | #you may not use this file except in compliance with the License. 8 | #You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | #Unless required by applicable law or agreed to in writing, software 13 | #distributed under the License is distributed on an "AS IS" BASIS, 14 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | #See the License for the specific language governing permissions and 16 | #limitations under the License. 17 | 18 | OS = $(shell uname -s | tr '[:upper:]' '[:lower:]') 19 | ARCH = $(shell uname -m) 20 | 21 | default: 22 | $(MAKE) deps 23 | $(MAKE) snap 24 | $(MAKE) plugins 25 | $(MAKE) swagger 26 | deps: 27 | bash -c "./scripts/deps.sh" 28 | test: 29 | bash -c "./scripts/test.sh $(SNAP_TEST_TYPE)" 30 | test-legacy: 31 | bash -c "./scripts/test.sh legacy" 32 | test-small: 33 | bash -c "./scripts/test.sh small" 34 | test-medium: 35 | bash -c "./scripts/test.sh medium" 36 | test-large: 37 | bash -c "./scripts/test.sh large" 38 | test-all: 39 | $(MAKE) test-legacy 40 | $(MAKE) test-medium 41 | $(MAKE) test-small 42 | $(MAKE) test-large 43 | # NOTE: 44 | # By default compiles will use all cpu cores, use BUILD_JOBS to control number 45 | # of parallel builds: `BUILD_JOBS=2 make plugins` 46 | # 47 | # Build only snapteld/snaptel 48 | snap: 49 | bash -c "./scripts/build_snap.sh" 50 | # Build only plugins 51 | plugins: 52 | bash -c "./scripts/build_plugins.sh" 53 | # Build snap and plugins for all platforms 54 | all: 55 | bash -c "./scripts/build_all.sh" 56 | install: 57 | mkdir -p /usr/local/sbin 58 | mkdir -p /usr/local/bin 59 | cp build/$(OS)/$(ARCH)/snapteld /usr/local/sbin/ 60 | cp build/$(OS)/$(ARCH)/snaptel /usr/local/bin/ 61 | proto: 62 | cd `echo $(GOPATH) | cut -d: -f 1`; bash -c "./src/github.com/intelsdi-x/snap/scripts/gen-proto.sh" 63 | swagger: 64 | bash -c "./scripts/swagger.sh" 65 | -------------------------------------------------------------------------------- /cmd/snaptel/sample/psutil-file.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "schedule": { 4 | "type": "simple", 5 | "interval": "1s" 6 | }, 7 | "workflow": { 8 | "collect": { 9 | "metrics": { 10 | "/psutil/load/load1": {}, 11 | "/psutil/load/load5": {}, 12 | "/psutil/load/load15": {}, 13 | "/psutil/net/all/bytes_recv": {}, 14 | "/psutil/net/all/bytes_sent": {}, 15 | "/psutil/net/all/dropin": {}, 16 | "/psutil/net/all/dropout": {}, 17 | "/psutil/net/all/errin": {}, 18 | "/psutil/net/all/errout": {}, 19 | "/psutil/net/all/packets_recv": {}, 20 | "/psutil/net/all/packets_sent": {}, 21 | "/psutil/vm/active": {}, 22 | "/psutil/vm/available": {}, 23 | "/psutil/vm/buffers": {}, 24 | "/psutil/vm/cached": {}, 25 | "/psutil/vm/free": {}, 26 | "/psutil/vm/inactive": {}, 27 | "/psutil/vm/shared": {}, 28 | "/psutil/vm/total": {}, 29 | "/psutil/vm/used": {}, 30 | "/psutil/vm/used_percent": {}, 31 | "/psutil/vm/wired": {} 32 | }, 33 | "config": { 34 | "/intel/mock": { 35 | "password": "secret", 36 | "user": "root" 37 | } 38 | }, 39 | "process": [ 40 | { 41 | "plugin_name": "passthru", 42 | "plugin_version": 1, 43 | "process": null, 44 | "publish": [ 45 | { 46 | "plugin_name": "file", 47 | "plugin_version": 1, 48 | "config": { 49 | "file": "/tmp/snap-file.out" 50 | } 51 | } 52 | ], 53 | "config": null 54 | } 55 | ], 56 | "publish": null 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /control/plugin/client/client.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package client 21 | 22 | import ( 23 | "time" 24 | 25 | "github.com/intelsdi-x/snap/control/plugin" 26 | "github.com/intelsdi-x/snap/control/plugin/cpolicy" 27 | "github.com/intelsdi-x/snap/core" 28 | "github.com/intelsdi-x/snap/core/ctypes" 29 | ) 30 | 31 | // PluginClient A client providing common plugin method calls. 32 | type PluginClient interface { 33 | SetKey() error 34 | Ping() error 35 | Kill(string) error 36 | Close() error 37 | GetConfigPolicy() (*cpolicy.ConfigPolicy, error) 38 | } 39 | 40 | // PluginCollectorClient A client providing collector specific plugin method calls. 41 | type PluginCollectorClient interface { 42 | PluginClient 43 | CollectMetrics([]core.Metric) ([]core.Metric, error) 44 | GetMetricTypes(plugin.ConfigType) ([]core.Metric, error) 45 | } 46 | 47 | type PluginStreamCollectorClient interface { 48 | PluginClient 49 | StreamMetrics(string, []core.Metric) (chan []core.Metric, chan error, error) 50 | GetMetricTypes(plugin.ConfigType) ([]core.Metric, error) 51 | UpdateCollectedMetrics([]core.Metric) error 52 | UpdatePluginConfig([]byte) error 53 | UpdateMetricsBuffer(int64) error 54 | UpdateCollectDuration(time.Duration) error 55 | Killed() 56 | } 57 | 58 | // PluginProcessorClient A client providing processor specific plugin method calls. 59 | type PluginProcessorClient interface { 60 | PluginClient 61 | Process([]core.Metric, map[string]ctypes.ConfigValue) ([]core.Metric, error) 62 | } 63 | 64 | // PluginPublisherClient A client providing publishing specific plugin method calls. 65 | type PluginPublisherClient interface { 66 | PluginClient 67 | Publish([]core.Metric, map[string]ctypes.ConfigValue) error 68 | } 69 | -------------------------------------------------------------------------------- /control/plugin/client/grpc_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package client 23 | 24 | import ( 25 | "testing" 26 | "time" 27 | 28 | "github.com/intelsdi-x/snap/core" 29 | . "github.com/smartystreets/goconvey/convey" 30 | ) 31 | 32 | func TestToCoreMetric(t *testing.T) { 33 | tc := testCases() 34 | Convey("Test ToCoreMetric", t, func() { 35 | for _, c := range tc { 36 | Convey(c.description, func() { 37 | mt := ToMetric(c) 38 | cmt := ToCoreMetric(mt) 39 | So(cmt.Timestamp(), ShouldNotBeNil) 40 | So(cmt.LastAdvertisedTime(), ShouldNotBeNil) 41 | 42 | if cmt.Version() == 2 { 43 | So(cmt.Timestamp(), ShouldResemble, cmt.LastAdvertisedTime()) 44 | } 45 | }) 46 | } 47 | }) 48 | } 49 | 50 | func testCases() []*metric { 51 | now := time.Now() 52 | tc := []*metric{ 53 | &metric{ 54 | namespace: core.NewNamespace("a", "b", "c"), 55 | version: 1, 56 | description: "No timeStamp and lastAdvertisedTime defined", 57 | }, 58 | &metric{ 59 | namespace: core.NewNamespace("x", "y", "z"), 60 | version: 1, 61 | timeStamp: time.Now(), 62 | description: "Has timestamp but no lastAdvertisedTime defined", 63 | }, 64 | &metric{ 65 | namespace: core.NewNamespace("x", "y", "z"), 66 | version: 1, 67 | lastAdvertisedTime: time.Now(), 68 | description: "No timestamp but has lastAdvertisedTime defined", 69 | }, 70 | &metric{ 71 | namespace: core.NewNamespace("x", "y", "z"), 72 | version: 2, 73 | timeStamp: now, 74 | lastAdvertisedTime: now, 75 | description: "Has both timestamp and lastAdvertisedTime defined", 76 | }, 77 | } 78 | return tc 79 | } 80 | -------------------------------------------------------------------------------- /control/plugin/collector_deprecated.go: -------------------------------------------------------------------------------- 1 | /* ** DEPRECATED ** 2 | For more information, see our deprecation notice 3 | on Github: https://github.com/intelsdi-x/snap/issues/1289 4 | */ 5 | 6 | /* 7 | http://www.apache.org/licenses/LICENSE-2.0.txt 8 | 9 | 10 | Copyright 2015 Intel Corporation 11 | 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | */ 24 | 25 | package plugin 26 | 27 | // Acts as a proxy for RPC calls to a CollectorPlugin. This helps keep the function signature simple 28 | // within plugins vs. having to match required RPC patterns. 29 | 30 | // Collector plugin 31 | type CollectorPlugin interface { 32 | Plugin 33 | CollectMetrics([]MetricType) ([]MetricType, error) 34 | GetMetricTypes(ConfigType) ([]MetricType, error) 35 | } 36 | -------------------------------------------------------------------------------- /control/plugin/collector_proxy.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package plugin 21 | 22 | // Arguments passed to CollectMetrics() for a Collector implementation 23 | type CollectMetricsArgs struct { 24 | MetricTypes []MetricType 25 | } 26 | 27 | // Reply assigned by a Collector implementation using CollectMetrics() 28 | type CollectMetricsReply struct { 29 | PluginMetrics []MetricType 30 | } 31 | 32 | // GetMetricTypesArgs args passed to GetMetricTypes 33 | type GetMetricTypesArgs struct { 34 | PluginConfig ConfigType 35 | } 36 | 37 | // GetMetricTypesReply assigned by GetMetricTypes() implementation 38 | type GetMetricTypesReply struct { 39 | MetricTypes []MetricType 40 | } 41 | -------------------------------------------------------------------------------- /control/plugin/collector_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package plugin 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/control/plugin/cpolicy" 28 | "github.com/intelsdi-x/snap/core" 29 | . "github.com/smartystreets/goconvey/convey" 30 | ) 31 | 32 | type MockPlugin struct { 33 | Meta PluginMeta 34 | } 35 | 36 | func (f *MockPlugin) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) { 37 | return &cpolicy.ConfigPolicy{}, nil 38 | } 39 | 40 | func (f *MockPlugin) CollectMetrics(_ []MetricType) ([]MetricType, error) { 41 | return []MetricType{}, nil 42 | } 43 | 44 | func (c *MockPlugin) GetMetricTypes(_ ConfigType) ([]MetricType, error) { 45 | return []MetricType{ 46 | {Namespace_: core.NewNamespace("foo", "bar")}, 47 | }, nil 48 | } 49 | 50 | func TestStartCollector(t *testing.T) { 51 | Convey("Collector", t, func() { 52 | Convey("start with dynamic port", func() { 53 | m := &PluginMeta{ 54 | RPCType: NativeRPC, 55 | Type: CollectorPluginType, 56 | } 57 | c := new(MockPlugin) 58 | 59 | err, rc := Start(m, c, "{}") 60 | So(err, ShouldBeNil) 61 | So(rc, ShouldEqual, 0) 62 | 63 | Convey("RPC service should not panic", func() { 64 | So(func() { Start(m, c, "{}") }, ShouldNotPanic) 65 | }) 66 | }) 67 | }) 68 | } 69 | -------------------------------------------------------------------------------- /control/plugin/cpolicy/rule.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package cpolicy 21 | 22 | // TODO, make second opts value in New<>Rule be description for rule (used in documentation) 23 | 24 | import ( 25 | "errors" 26 | "fmt" 27 | 28 | "github.com/intelsdi-x/snap/core/ctypes" 29 | ) 30 | 31 | var ( 32 | EmptyKeyError = errors.New("key cannot be empty") 33 | ) 34 | 35 | // A rule used to process ConfigData 36 | type Rule interface { 37 | Key() string 38 | Validate(ctypes.ConfigValue) error 39 | Default() ctypes.ConfigValue 40 | Required() bool 41 | Type() string 42 | Minimum() ctypes.ConfigValue 43 | Maximum() ctypes.ConfigValue 44 | } 45 | 46 | type rule struct { 47 | Description string 48 | } 49 | 50 | func wrongType(key, inType, reqType string) error { 51 | return errors.New(fmt.Sprintf("type mismatch (%s wanted type '%s' but provided type '%s')", key, reqType, inType)) 52 | } 53 | -------------------------------------------------------------------------------- /control/plugin/encoding/encoding.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package encoding 21 | 22 | import "github.com/intelsdi-x/snap/control/plugin/encrypter" 23 | 24 | type Encoder interface { 25 | Encode(interface{}) ([]byte, error) 26 | Decode([]byte, interface{}) error 27 | SetEncrypter(*encrypter.Encrypter) 28 | } 29 | -------------------------------------------------------------------------------- /control/plugin/encoding/gob.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package encoding 21 | 22 | import ( 23 | "bytes" 24 | "encoding/gob" 25 | 26 | "github.com/intelsdi-x/snap/control/plugin/encrypter" 27 | ) 28 | 29 | type gobEncoder struct { 30 | e *encrypter.Encrypter 31 | } 32 | 33 | func NewGobEncoder() *gobEncoder { 34 | return &gobEncoder{} 35 | } 36 | 37 | func (g *gobEncoder) SetEncrypter(e *encrypter.Encrypter) { 38 | g.e = e 39 | } 40 | 41 | func (g *gobEncoder) Encode(in interface{}) ([]byte, error) { 42 | buff := &bytes.Buffer{} 43 | enc := gob.NewEncoder(buff) 44 | err := enc.Encode(in) 45 | if err != nil { 46 | return nil, err 47 | } 48 | 49 | if g.e != nil { 50 | return g.e.Encrypt(buff) 51 | } 52 | 53 | return buff.Bytes(), err 54 | } 55 | 56 | func (g *gobEncoder) Decode(in []byte, out interface{}) error { 57 | var err error 58 | if g.e != nil { 59 | in, err = g.e.Decrypt(bytes.NewReader(in)) 60 | if err != nil { 61 | return err 62 | } 63 | } 64 | dec := gob.NewDecoder(bytes.NewReader(in)) 65 | err = dec.Decode(out) 66 | if err != nil { 67 | return err 68 | } 69 | return nil 70 | } 71 | -------------------------------------------------------------------------------- /control/plugin/encoding/json.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package encoding 21 | 22 | import ( 23 | "bytes" 24 | "encoding/json" 25 | 26 | "github.com/intelsdi-x/snap/control/plugin/encrypter" 27 | ) 28 | 29 | type jsonEncoder struct { 30 | e *encrypter.Encrypter 31 | } 32 | 33 | func NewJsonEncoder() *jsonEncoder { 34 | return &jsonEncoder{} 35 | } 36 | 37 | func (j *jsonEncoder) SetEncrypter(e *encrypter.Encrypter) { 38 | j.e = e 39 | } 40 | 41 | func (j *jsonEncoder) Encode(in interface{}) ([]byte, error) { 42 | out, err := json.Marshal(in) 43 | if err != nil { 44 | return nil, err 45 | } 46 | if j.e != nil { 47 | out, err = j.e.Encrypt(bytes.NewReader(out)) 48 | } 49 | return out, err 50 | } 51 | 52 | func (j *jsonEncoder) Decode(in []byte, out interface{}) error { 53 | var err error 54 | if j.e != nil { 55 | in, err = j.e.Decrypt(bytes.NewReader(in)) 56 | if err != nil { 57 | return err 58 | } 59 | } 60 | return json.Unmarshal(in, out) 61 | } 62 | -------------------------------------------------------------------------------- /control/plugin/encrypter/encrypter_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package encrypter 23 | 24 | import ( 25 | "bytes" 26 | "crypto/rand" 27 | "crypto/rsa" 28 | "testing" 29 | 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | func TestEncrypter(t *testing.T) { 34 | Convey("Encrypter", t, func() { 35 | key, err := rsa.GenerateKey(rand.Reader, 2048) 36 | So(err, ShouldBeNil) 37 | e := New(&key.PublicKey, key) 38 | symkey, err := GenerateKey() 39 | So(err, ShouldBeNil) 40 | e.Key = symkey 41 | Convey("The constructor works", func() { 42 | So(e, ShouldHaveSameTypeAs, &Encrypter{}) 43 | }) 44 | Convey("it can encrypt stuff", func() { 45 | _, err := e.Encrypt(bytes.NewReader([]byte("hello, encrypter"))) 46 | So(err, ShouldBeNil) 47 | }) 48 | Convey("it can decrypt stuff", func() { 49 | out, err := e.Encrypt(bytes.NewReader([]byte("hello, encrypter"))) 50 | So(err, ShouldBeNil) 51 | dec, err := e.Decrypt(bytes.NewReader(out)) 52 | So(err, ShouldBeNil) 53 | So(string(dec), ShouldEqual, "hello, encrypter") 54 | }) 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /control/plugin/processor_deprecated.go: -------------------------------------------------------------------------------- 1 | /* ** DEPRECATED ** 2 | For more information, see our deprecation notice 3 | on Github: https://github.com/intelsdi-x/snap/issues/1289 4 | */ 5 | 6 | /* 7 | http://www.apache.org/licenses/LICENSE-2.0.txt 8 | 9 | 10 | Copyright 2015 Intel Corporation 11 | 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | */ 24 | 25 | package plugin 26 | 27 | import "github.com/intelsdi-x/snap/core/ctypes" 28 | 29 | // Processor plugin 30 | type ProcessorPlugin interface { 31 | Plugin 32 | Process(contentType string, content []byte, config map[string]ctypes.ConfigValue) (string, []byte, error) 33 | } 34 | -------------------------------------------------------------------------------- /control/plugin/processor_proxy.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package plugin 21 | 22 | import "github.com/intelsdi-x/snap/core/ctypes" 23 | 24 | type ProcessorArgs struct { 25 | ContentType string 26 | Content []byte 27 | Config map[string]ctypes.ConfigValue 28 | } 29 | 30 | type ProcessorReply struct { 31 | ContentType string 32 | Content []byte 33 | } 34 | -------------------------------------------------------------------------------- /control/plugin/processor_proxy_deprecated.go: -------------------------------------------------------------------------------- 1 | /* ** DEPRECATED ** 2 | For more information, see our deprecation notice 3 | on Github: https://github.com/intelsdi-x/snap/issues/1289 4 | */ 5 | 6 | /* 7 | http://www.apache.org/licenses/LICENSE-2.0.txt 8 | 9 | 10 | Copyright 2015 Intel Corporation 11 | 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | */ 24 | 25 | package plugin 26 | 27 | import ( 28 | "errors" 29 | "fmt" 30 | ) 31 | 32 | type processorPluginProxy struct { 33 | Plugin ProcessorPlugin 34 | Session Session 35 | } 36 | 37 | func (p *processorPluginProxy) Process(args []byte, reply *[]byte) error { 38 | defer catchPluginPanic(p.Session.Logger()) 39 | p.Session.ResetHeartbeat() 40 | 41 | dargs := &ProcessorArgs{} 42 | err := p.Session.Decode(args, dargs) 43 | if err != nil { 44 | return err 45 | } 46 | 47 | r := ProcessorReply{} 48 | r.ContentType, r.Content, err = p.Plugin.Process(dargs.ContentType, dargs.Content, dargs.Config) 49 | if err != nil { 50 | return errors.New(fmt.Sprintf("Processor call error: %v", err.Error())) 51 | } 52 | 53 | *reply, err = p.Session.Encode(r) 54 | if err != nil { 55 | return err 56 | } 57 | 58 | return nil 59 | } 60 | -------------------------------------------------------------------------------- /control/plugin/publisher_deprecated.go: -------------------------------------------------------------------------------- 1 | /* ** DEPRECATED ** 2 | For more information, see our deprecation notice 3 | on Github: https://github.com/intelsdi-x/snap/issues/1289 4 | */ 5 | 6 | /* 7 | http://www.apache.org/licenses/LICENSE-2.0.txt 8 | 9 | 10 | Copyright 2015 Intel Corporation 11 | 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | */ 24 | 25 | package plugin 26 | 27 | import "github.com/intelsdi-x/snap/core/ctypes" 28 | 29 | // Publisher plugin 30 | type PublisherPlugin interface { 31 | Plugin 32 | Publish(contentType string, content []byte, config map[string]ctypes.ConfigValue) error 33 | } 34 | -------------------------------------------------------------------------------- /control/plugin/publisher_proxy.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package plugin 21 | 22 | import "github.com/intelsdi-x/snap/core/ctypes" 23 | 24 | type PublishArgs struct { 25 | ContentType string 26 | Content []byte 27 | Config map[string]ctypes.ConfigValue 28 | } 29 | -------------------------------------------------------------------------------- /control/plugin/publisher_proxy_deprecated.go: -------------------------------------------------------------------------------- 1 | /* ** DEPRECATED ** 2 | For more information, see our deprecation notice 3 | on Github: https://github.com/intelsdi-x/snap/issues/1289 4 | */ 5 | 6 | /* 7 | http://www.apache.org/licenses/LICENSE-2.0.txt 8 | 9 | 10 | Copyright 2015 Intel Corporation 11 | 12 | Licensed under the Apache License, Version 2.0 (the "License"); 13 | you may not use this file except in compliance with the License. 14 | You may obtain a copy of the License at 15 | 16 | http://www.apache.org/licenses/LICENSE-2.0 17 | 18 | Unless required by applicable law or agreed to in writing, software 19 | distributed under the License is distributed on an "AS IS" BASIS, 20 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | See the License for the specific language governing permissions and 22 | limitations under the License. 23 | */ 24 | 25 | package plugin 26 | 27 | import ( 28 | "errors" 29 | "fmt" 30 | ) 31 | 32 | type PublishReply struct { 33 | } 34 | 35 | type publisherPluginProxy struct { 36 | Plugin PublisherPlugin 37 | Session Session 38 | } 39 | 40 | func (p *publisherPluginProxy) Publish(args []byte, reply *[]byte) error { 41 | defer catchPluginPanic(p.Session.Logger()) 42 | p.Session.ResetHeartbeat() 43 | 44 | dargs := &PublishArgs{} 45 | err := p.Session.Decode(args, dargs) 46 | if err != nil { 47 | return err 48 | } 49 | 50 | err = p.Plugin.Publish(dargs.ContentType, dargs.Content, dargs.Config) 51 | if err != nil { 52 | return errors.New(fmt.Sprintf("Publish call error: %v", err.Error())) 53 | } 54 | return nil 55 | } 56 | -------------------------------------------------------------------------------- /control/plugin/session.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package plugin 21 | 22 | import "github.com/intelsdi-x/snap/control/plugin/cpolicy" 23 | 24 | type KillArgs struct { 25 | Reason string 26 | } 27 | 28 | type GetConfigPolicyReply struct { 29 | Policy *cpolicy.ConfigPolicy 30 | } 31 | 32 | type SetKeyArgs struct { 33 | Key []byte 34 | } 35 | -------------------------------------------------------------------------------- /control/strategy/config_based_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | Copyright 2016 Intel Corporation 7 | 8 | Licensed under the Apache License, Version 2.0 (the "License"); 9 | you may not use this file except in compliance with the License. 10 | You may obtain a copy of the License at 11 | 12 | http://www.apache.org/licenses/LICENSE-2.0 13 | 14 | Unless required by applicable law or agreed to in writing, software 15 | distributed under the License is distributed on an "AS IS" BASIS, 16 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | See the License for the specific language governing permissions and 18 | limitations under the License. 19 | */ 20 | 21 | package strategy 22 | 23 | import ( 24 | "testing" 25 | "time" 26 | 27 | . "github.com/intelsdi-x/snap/control/strategy/fixtures" 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestConfigBasedRouter(t *testing.T) { 32 | Convey("Given a config router", t, func() { 33 | router := NewConfigBased(100 * time.Millisecond) 34 | So(router, ShouldNotBeNil) 35 | So(router.String(), ShouldResemble, "config-based") 36 | Convey("Select a plugin when they are available", func() { 37 | p1 := NewMockAvailablePlugin().WithName("p1") 38 | p2 := NewMockAvailablePlugin().WithName("p2") 39 | // select a plugin, for cfg1, given a config and two available plugins 40 | sp1, err := router.Select([]AvailablePlugin{p1, p2}, "cfg1") 41 | So(err, ShouldBeNil) 42 | So(sp1, ShouldNotBeNil) 43 | So(sp1, ShouldEqual, p1) 44 | // change the order of the plugins provided to the select 45 | sp2, err := router.Select([]AvailablePlugin{p2, p1}, "cfg1") 46 | So(err, ShouldBeNil) 47 | So(sp2, ShouldNotBeNil) 48 | So(sp2, ShouldEqual, p1) 49 | // select the other (last) available plugin for cfg2 50 | sp3, err := router.Select([]AvailablePlugin{p2, p1}, "cfg2") 51 | So(err, ShouldBeNil) 52 | So(sp3, ShouldNotBeNil) 53 | So(sp3, ShouldEqual, p2) 54 | Convey("Select a plugin when there are NONE available", func() { 55 | plugins := []AvailablePlugin{p1, p2} 56 | sp, err := router.Select(plugins, "cfg3") 57 | So(sp, ShouldBeNil) 58 | So(err, ShouldEqual, ErrCouldNotSelect) 59 | }) 60 | }) 61 | 62 | }) 63 | } 64 | -------------------------------------------------------------------------------- /control/strategy/sticky_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package strategy 23 | 24 | import ( 25 | "testing" 26 | "time" 27 | 28 | . "github.com/intelsdi-x/snap/control/strategy/fixtures" 29 | . "github.com/smartystreets/goconvey/convey" 30 | ) 31 | 32 | func TestStickyRouter(t *testing.T) { 33 | Convey("Given a sticky router", t, func() { 34 | router := NewSticky(100 * time.Millisecond) 35 | So(router, ShouldNotBeNil) 36 | So(router.String(), ShouldResemble, "sticky") 37 | Convey("Select a plugin when they are available", func() { 38 | p1 := NewMockAvailablePlugin().WithName("p1") 39 | p2 := NewMockAvailablePlugin().WithName("p2") 40 | // select a plugin, for task1, given a task and two available plugins 41 | sp1, err := router.Select([]AvailablePlugin{p1, p2}, "task1") 42 | So(err, ShouldBeNil) 43 | So(sp1, ShouldNotBeNil) 44 | So(sp1, ShouldEqual, p1) 45 | // change the order of the plugins provided to the select 46 | sp2, err := router.Select([]AvailablePlugin{p2, p1}, "task1") 47 | So(err, ShouldBeNil) 48 | So(sp1, ShouldNotBeNil) 49 | So(sp2, ShouldEqual, p1) 50 | // select the other (last) available plugin for task2 51 | sp3, err := router.Select([]AvailablePlugin{p2, p1}, "task2") 52 | So(err, ShouldBeNil) 53 | So(sp3, ShouldNotBeNil) 54 | So(sp3, ShouldEqual, p2) 55 | Convey("Select a plugin when there are NONE available", func() { 56 | plugins := []AvailablePlugin{p1, p2} 57 | sp, err := router.Select(plugins, "task3") 58 | So(sp, ShouldBeNil) 59 | So(err, ShouldEqual, ErrCouldNotSelect) 60 | }) 61 | }) 62 | 63 | }) 64 | } 65 | -------------------------------------------------------------------------------- /control/strategy/strategy.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Package strategy provides basic interfaces for routing to available 21 | // plugins and caching metric data. 22 | package strategy 23 | 24 | import ( 25 | "errors" 26 | "time" 27 | 28 | "github.com/intelsdi-x/snap/core" 29 | ) 30 | 31 | type MapAvailablePlugin map[uint32]AvailablePlugin 32 | 33 | var ( 34 | ErrCouldNotSelect = errors.New("could not select a plugin") 35 | ) 36 | 37 | type RoutingAndCaching interface { 38 | Select(availablePlugins []AvailablePlugin, id string) (AvailablePlugin, error) 39 | Remove(availablePlugins []AvailablePlugin, id string) (AvailablePlugin, error) 40 | CheckCache(metrics []core.Metric, id string) ([]core.Metric, []core.Metric) 41 | UpdateCache(metrics []core.Metric, id string) 42 | CacheHits(ns string, ver int, id string) (uint64, error) 43 | CacheMisses(ns string, ver int, id string) (uint64, error) 44 | AllCacheHits() uint64 45 | AllCacheMisses() uint64 46 | CacheTTL(taskID string) (time.Duration, error) 47 | String() string 48 | } 49 | 50 | // Values returns slice of map values 51 | func (sm MapAvailablePlugin) Values() []AvailablePlugin { 52 | values := []AvailablePlugin{} 53 | for _, v := range sm { 54 | values = append(values, v) 55 | } 56 | return values 57 | } 58 | -------------------------------------------------------------------------------- /core/cdata/tree.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package cdata 21 | 22 | import ( 23 | "bytes" 24 | "encoding/gob" 25 | 26 | "github.com/intelsdi-x/snap/pkg/ctree" 27 | ) 28 | 29 | // Allows adding of config data by namespace and retrieving of data from tree 30 | // at a specific namespace (merging the relevant hierarchy). Uses pkg.ConfigTree. 31 | type ConfigDataTree struct { 32 | cTree *ctree.ConfigTree 33 | } 34 | 35 | // Returns a new ConfigDataTree. 36 | func NewTree() *ConfigDataTree { 37 | return &ConfigDataTree{ 38 | cTree: ctree.New(), 39 | } 40 | } 41 | 42 | func (c *ConfigDataTree) GobEncode() ([]byte, error) { 43 | w := new(bytes.Buffer) 44 | encoder := gob.NewEncoder(w) 45 | if err := encoder.Encode(c.cTree); err != nil { 46 | return nil, err 47 | } 48 | return w.Bytes(), nil 49 | } 50 | 51 | func (c *ConfigDataTree) GobDecode(buf []byte) error { 52 | r := bytes.NewBuffer(buf) 53 | decoder := gob.NewDecoder(r) 54 | return decoder.Decode(&c.cTree) 55 | } 56 | 57 | // Adds a ConfigDataNode at the provided namespace. 58 | func (c *ConfigDataTree) Add(ns []string, cdn *ConfigDataNode) { 59 | c.cTree.Add(ns, cdn) 60 | } 61 | 62 | // Returns a ConfigDataNode that is a merged version of the namespace provided. 63 | func (c *ConfigDataTree) Get(ns []string) *ConfigDataNode { 64 | n := c.cTree.Get(ns) 65 | if n == nil { 66 | return nil 67 | } 68 | switch t := n.(type) { 69 | case ConfigDataNode: 70 | return &t 71 | default: 72 | return t.(*ConfigDataNode) 73 | 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /core/core.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package core 21 | 22 | const ( 23 | // Separator is the default separator used in strings 24 | Separator = "\U0001f422" 25 | 26 | // Tuple is defined by its prefix, suffix and separator between tuple's items 27 | TuplePrefix = "(" 28 | TupleSuffix = ")" 29 | TupleSeparator = ";" 30 | ) 31 | -------------------------------------------------------------------------------- /core/metric_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | package core 4 | 5 | import ( 6 | "testing" 7 | 8 | "github.com/intelsdi-x/snap/pkg/stringutils" 9 | . "github.com/smartystreets/goconvey/convey" 10 | ) 11 | 12 | func TestMetricSeparator(t *testing.T) { 13 | tc := getTestCases() 14 | Convey("Test namespace separator", t, func() { 15 | for _, c := range tc { 16 | Convey("namespace "+c.input.String(), func() { 17 | firstChar := stringutils.GetFirstChar(c.input.String()) 18 | So(firstChar, ShouldEqual, c.expected) 19 | }) 20 | } 21 | }) 22 | } 23 | 24 | type testCase struct { 25 | input Namespace 26 | expected string 27 | } 28 | 29 | // getTestCases tests the namespace and nsPriorityList. 30 | func getTestCases() []testCase { 31 | tcs := []testCase{ 32 | testCase{ 33 | input: NewNamespace("/hello", "/world"), 34 | expected: "|", 35 | }, 36 | testCase{ 37 | input: NewNamespace("/hello", "/world", "corporate-service|"), 38 | expected: "%", 39 | }, 40 | testCase{ 41 | input: NewNamespace("/hello", "/world", "|corporate-service%", "monday_to_friday"), 42 | expected: ":", 43 | }, 44 | testCase{ 45 | input: NewNamespace("/hello", "/world", "corporate-service/%|-_^><+=:;&", "monday_friday", "㊽ÄA小ヒ☍"), 46 | expected: "大", 47 | }, 48 | testCase{ 49 | input: NewNamespace("A小ヒ☍小㊽%:;", "/hello", "/world大|", "monday_friday", "corporate-service"), 50 | expected: "^", 51 | }, 52 | } 53 | return tcs 54 | } 55 | -------------------------------------------------------------------------------- /core/serror/serror.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package serror 21 | 22 | type SnapError interface { 23 | error 24 | Fields() map[string]interface{} 25 | SetFields(map[string]interface{}) 26 | } 27 | 28 | type Fields map[string]interface{} 29 | 30 | type snapError struct { 31 | err error 32 | fields Fields 33 | } 34 | 35 | // New returns an initialized SnapError. 36 | // The variadic signature allows fields to optionally 37 | // be added at construction. 38 | func New(e error, fields ...map[string]interface{}) *snapError { 39 | // Catch someone trying to wrap a serror around a serror. 40 | // We throw a panic to make them fix this. 41 | if _, ok := e.(SnapError); ok { 42 | panic("You are trying to wrap a snapError around a snapError. Don't do this.") 43 | } 44 | 45 | p := &snapError{ 46 | err: e, 47 | fields: make(map[string]interface{}), 48 | } 49 | 50 | // insert fields into new snapError 51 | for _, f := range fields { 52 | for k, v := range f { 53 | p.fields[k] = v 54 | } 55 | } 56 | 57 | return p 58 | } 59 | 60 | func (p *snapError) SetFields(f map[string]interface{}) { 61 | p.fields = f 62 | } 63 | 64 | func (p *snapError) Fields() map[string]interface{} { 65 | return p.fields 66 | } 67 | 68 | func (p *snapError) Error() string { 69 | return p.err.Error() 70 | } 71 | 72 | func (p *snapError) String() string { 73 | return p.Error() 74 | } 75 | -------------------------------------------------------------------------------- /core/subscription_group.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package core 21 | 22 | import "errors" 23 | 24 | var ( 25 | // ErrSubscriptionGroupAlreadyExists - error message when the subscription 26 | // group already exists 27 | ErrSubscriptionGroupAlreadyExists = errors.New("Subscription already exists") 28 | 29 | // ErrSubscriptionGroupDoesNotExist - error message when the subscription 30 | // group does not exist 31 | ErrSubscriptionGroupDoesNotExist = errors.New("Subscription does not exist") 32 | ) 33 | -------------------------------------------------------------------------------- /core/tribe_event/tribe_event.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package tribe_event 21 | 22 | import "github.com/intelsdi-x/snap/core" 23 | 24 | const ( 25 | PluginAdded = "Tribe.PluginAdded" 26 | ) 27 | 28 | type AddPluginEvent struct { 29 | Agreement struct { 30 | Name string 31 | } 32 | Plugin struct { 33 | Name string 34 | Type core.PluginType 35 | Version int 36 | } 37 | } 38 | 39 | func (e AddPluginEvent) Namespace() string { 40 | return PluginAdded 41 | } 42 | -------------------------------------------------------------------------------- /core/workflow.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package core 21 | 22 | type WorkflowState int 23 | 24 | const ( 25 | WorkflowStopped WorkflowState = iota 26 | WorkflowStarted 27 | ) 28 | 29 | type Workflow interface { 30 | Marshal() ([]byte, error) 31 | Unmarshal([]byte) error 32 | State() WorkflowState 33 | } 34 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | // Package main Snap Restful APIs. 2 | // 3 | // Snap is an open telemetry framework designed to simplify the collection, 4 | // processing and publishing of system data through a single API. 5 | // 6 | // This specification should demonstrate a fully compliant swagger 2.0 spec for Snap. 7 | // It lists all the possible Snap Restful APIs that are available for use, 8 | // testing or generating spec compatible clients. 9 | // 10 | // Terms Of Service: 11 | // 12 | // There are no TOS at this moment, use at your own risk we take no responsibility. 13 | // 14 | // Schemes: http, https 15 | // Host: 127.0.0.1:8181 16 | // BasePath: /v2 17 | // Version: 2.0 18 | // License: Apache 2.0 http://www.apache.org/licenses/ 19 | // Contact: Snap Maintainer https://github.com/intelsdi-x/snap 20 | // 21 | // Consumes: 22 | // - application/json 23 | // 24 | // Produces: 25 | // - application/json 26 | // 27 | // Security: 28 | // - basicAuth: [] 29 | // 30 | // SecurityDefinitions: 31 | // basicAuth: 32 | // type: basic 33 | // description: HTTP basic authentication. 34 | // 35 | // swagger:meta 36 | package main 37 | -------------------------------------------------------------------------------- /docs/AUTHORS.md: -------------------------------------------------------------------------------- 1 | # Initial Authors 2 | 3 | [@andrzej-k](https://github.com/andrzej-k) 4 | [@candysmurf](https://github.com/candysmurf) 5 | [@ConnorDoyle](https://github.com/ConnorDoyle) 6 | [@danielscottt](https://github.com/danielscottt) 7 | [@dasm](https://github.com/dasm) 8 | [@geauxvirtual](https://github.com/geauxvirtual) 9 | [@IzabellaRaulin](https://github.com/IzabellaRaulin) 10 | [@jcooklin](https://github.com/jcooklin) 11 | [@Lactem](https://github.com/Lactem) 12 | [@lmroz](https://github.com/lmroz) 13 | [@lynxbat](https://github.com/lynxbat) 14 | [@marcin-krolik](https://github.com/marcin-krolik) 15 | [@mbbroberg](https://github.com/mbbroberg) 16 | [@nqn](https://github.com/nqn) 17 | [@PatrykMatyjasek](https://github.com/PatrykMatyjasek) 18 | [@ppalucki](https://github.com/ppalucki) 19 | [@sandlbn](https://github.com/sandlbn) 20 | [@shweta1989](https://github.com/shweta1989) 21 | [@skonefal](https://github.com/skonefal) 22 | [@tiffanyfj](https://github.com/tiffanyfj) -------------------------------------------------------------------------------- /docs/DISTRIBUTED_WORKFLOW_ARCHITECTURE.md: -------------------------------------------------------------------------------- 1 | # Distributed Workflow 2 | 3 | A distributed workflow is a workflow where one or more steps have a remote target specified. An example of this is: 4 | 5 | ```yaml 6 | --- 7 | collect: 8 | metrics: 9 | /intel/mock/foo: {} 10 | /intel/mock/bar: {} 11 | /intel/mock/*/baz: {} 12 | config: 13 | /intel/mock: 14 | user: "root" 15 | password: "secret" 16 | process: 17 | - 18 | plugin_name: "passthru" 19 | target: "127.0.0.1:8082" 20 | publish: 21 | - 22 | plugin_name: "file" 23 | target: "127.0.0.1:8082" 24 | config: 25 | file: "/tmp/published" 26 | 27 | ``` 28 | 29 | ## Architecture 30 | 31 | Distributed workflow is accomplished by allowing remote targets to be specified as part of a task workflow. This is done by having a gRPC server running that can handle actions needed by the scheduler to run a task. These are defined in the [managesMetrics](https://github.com/intelsdi-x/snap/blob/master/scheduler/scheduler.go) interface defined in scheduler/scheduler.go. This interface is implemented by both pluginControl in control/control.go and ControlProxy in grpc/controlproxy/controlproxy.go. This allows the scheduler to not know/care where a step in the workflow is running. On task creation, the workflow is walked and the appropriate type is selected or created for each step in the workflow. 32 | 33 | ## Performance considerations 34 | 35 | The main performance penalty for using remote targets is that data is now sent over the network instead of locally. This is minimized since Snap will only make remote calls for steps in the workflow that specify a remote target. 36 | -------------------------------------------------------------------------------- /docs/PLUGIN_PACKAGING.md: -------------------------------------------------------------------------------- 1 | # Plugin Packaging 2 | 3 | Snap supports the ACI (App Container 4 | Image) format defined in the 5 | [App Container spec (appc)](https://github.com/appc/spec) for packaging a 6 | plugin. 7 | 8 | When Snap loads a plugin it detects the plugins type. If the plugin is a binary 9 | the plugin is run by snapteld which handshakes with the plugin via reading its 10 | standard output. If the plugin is packaged as an ACI image it is extracted 11 | and Snap executes the program referenced by the `exec` field. 12 | 13 | ## Why 14 | 15 | In cases where we cannot or do not want to compile our plugin into a statically 16 | linked binary we can load a plugin packaged as an ACI image. This provides 17 | an obvious advantage for plugins written in Python, Ruby, Java, etc where the 18 | plugins dependencies, potentially including an entire Python virtualenv, could 19 | be distributed with the plugin. 20 | 21 | ## How 22 | 23 | Since Snap leverages the appc spec for images we recommend using the 24 | [acbuild](https://github.com/appc/acbuild) tool for creating images. 25 | 26 | In the example below we package one of the mock plugins creating a plugin 27 | package which can be loaded achieving the same result as if we had simply 28 | loaded the binary version of the plugin. 29 | 30 | 1. Get the [acbuild](https://github.com/appc/acbuild) tool 31 | * Download the latest binary 32 | [release](https://github.com/appc/acbuild/releases) and install into your 33 | PATH. 34 | 2. Make Snap 35 | * From the root of snap run: `make` 36 | 4. Using the acbuild tool create an image containing the mock collector plugin. 37 | * From the `build/plugin` directory run the following commands. 38 | ``` 39 | acbuild begin 40 | acbuild set-name intelsdi-x/snap-plugin-collector-mock1 41 | acbuild copy snap-plugin-collector-mock1 /bin/snap-plugin-collector-mock1 42 | acbuild set-exec /bin/snap-plugin-collector-mock1 43 | acbuild write snap-plugin-collector-mock1-linux-x86_64.aci 44 | acbuild end 45 | ``` 46 | ![example](https://cloud.githubusercontent.com/assets/10092554/20983225/8355a382-bc70-11e6-82c6-6ac445e16513.gif) 47 | 48 | That's it! -------------------------------------------------------------------------------- /docs/STAND-ALONE_MODE.md: -------------------------------------------------------------------------------- 1 | # Stand-alone mode 2 | 3 | Stand-alone mode enables plugin launching on different machine than Snap daemon (`snapteld`). 4 | This feature works for plugins written using one of our snap-plugin-libs ([snap-plugin-lib-go](https://github.com/intelsdi-x/snap-plugin-lib-go), 5 | [snap-plugin-lib-py](https://github.com/intelsdi-x/snap-plugin-lib-py), [snap-plugin-lib-cpp](https://github.com/intelsdi-x/snap-plugin-lib-cpp)). 6 | 7 | ## Running a plugin in stand-alone mode 8 | To run a plugin in stand-alone mode, you must start it with the `--stand-alone` flag, e.g.: 9 | ``` 10 | $ ./snap-plugin-collector-psutil --stand-alone 11 | ``` 12 | 13 | A plugin running in stand-alone mode creates a HTTP server for communication with the Snap framework. 14 | By default the plugin listens on port `8182`. 15 | 16 | To specify a different listening port, use the `--stand-alone-port` flag, e.g.: 17 | ``` 18 | $ ./snap-plugin-collector-psutil --stand-alone --stand-alone-port 8183 19 | ``` 20 | ## Loading a plugin 21 | To load a plugin in stand-alone mode, provide a URL to indicate to the machine on which the plugin is running (IP address/hostname with port number), e.g.: 22 | 23 | ``` 24 | $ snaptel plugin load http://127.0.0.1:8182 25 | ``` 26 | 27 | or 28 | 29 | ``` 30 | $ snaptel plugin load http://localhost:8182 31 | ``` 32 | 33 | The rest of operations remains exactly the same as is it for plugins running in regular mode. 34 | 35 | ## Known issues 36 | If some disruption occurs in the connection between Snap and a stand-alone plugin, the running task will be stopped with disabled status and the plugin will be unloaded. Providing the mechanism of reconnecting stand-alone plugins upon network disruption is in our scope, addressed by the [issue #1697](https://github.com/intelsdi-x/snap/issues/1697). 37 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | This directory contains examples for Snap: 21 | 22 | * [configs](./configs) folder contains examples of [the global configuration file](../docs/SNAPTELD_CONFIGURATION.md#snapteld-configuration-file) that powers your plugins. 23 | * [tasks](./tasks) folder contains examples of [Snap tasks](../docs/TASKS.md). 24 | 25 | For additional examples of using Snap, checkout the examples in these repositories: 26 | - [snap-plugin-collector-docker](https://github.com/intelsdi-x/snap-plugin-collector-docker) 27 | - [snap-plugin-collector-ethtool](https://github.com/intelsdi-x/snap-plugin-collector-ethtool) 28 | - [snap-plugin-collector-cpu](https://github.com/intelsdi-x/snap-plugin-collector-cpu) 29 | - [snap-plugin-collector-disk](https://github.com/intelsdi-x/snap-plugin-collector-disk) 30 | - [snap-plugin-collector-psutil](https://github.com/intelsdi-x/snap-plugin-collector-psutil) 31 | - [snap-plugin-collector-meminfo](https://github.com/intelsdi-x/snap-plugin-collector-meminfo) 32 | - [snap-plugin-processor-statistics](https://github.com/intelsdi-x/snap-plugin-processor-statistics) 33 | - [snap-plugin-publisher-influxdb](https://github.com/intelsdi-x/snap-plugin-publisher-influxdb) 34 | - [snap-plugin-publisher-graphite](https://github.com/intelsdi-x/snap-plugin-publisher-graphite) 35 | - [snap-plugin-publisher-file](https://github.com/intelsdi-x/snap-plugin-publisher-file) 36 | - [snap-relay](https://github.com/intelsdi-x/snap-relay) (streaming collector plugin to retrieve data from collectd or statsd and include them into Snap workflow) -------------------------------------------------------------------------------- /examples/configs/README.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | This directory contains examplary global configuration files for Snap: 21 | 22 | * [snapteld.conf](./snapteld.conf), default global config file easy to customize (uncomment needed parameters and adjust their values) 23 | * [snap-config-sample.yaml](./snap-config-sample.yaml), a sample of global config file in YAML format 24 | * [snap-config-sample.json](./snap-config-sample.json), a sample of global config file in JSON format 25 | 26 | * [snaptel-config-sample.json](./snaptel-config-sample.json), snaptel config file. **Notice, it is deprecated and using that is not recommended.** 27 | 28 | Read more about [snapteld configuration file](https://github.com/intelsdi-x/snap/blob/master/docs/SNAPTELD_CONFIGURATION.md#snapteld-configuration-file). 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/configs/snap-config-empty.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | control: 3 | # plugins section contains plugin config settings that will be applied for 4 | # plugins across tasks. 5 | plugins: 6 | collector: 7 | pcm: 8 | # this should not cause a panic 9 | all: 10 | psutil: 11 | all: 12 | path: /usr/local/bin/psutil 13 | # this should not cause a fatal error 14 | versions: 15 | 1: 16 | # this should also not cause a fatal error 17 | myplugin: 18 | -------------------------------------------------------------------------------- /examples/configs/snaptel-config-sample.json: -------------------------------------------------------------------------------- 1 | { 2 | "rest": { 3 | "rest-auth-pwd": "example" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /examples/tasks/psutil-file.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | version: 1 3 | schedule: 4 | type: "simple" 5 | interval: "1s" 6 | count: 5 7 | max-failures: 10 8 | workflow: 9 | collect: 10 | metrics: 11 | /intel/psutil/cpu/cpu-total/user: {} 12 | /intel/psutil/cpu/cpu-total/system: {} 13 | /intel/psutil/cpu/cpu-total/idle: {} 14 | /intel/psutil/load/*: {} 15 | publish: 16 | - plugin_name: "file" 17 | config: 18 | file: "/tmp/psutil_metrics.log" 19 | -------------------------------------------------------------------------------- /glide.yaml: -------------------------------------------------------------------------------- 1 | package: github.com/intelsdi-x/snap 2 | import: 3 | - package: github.com/sirupsen/logrus 4 | version: be52937128b38f1d99787bb476c789e2af1147f1 5 | - package: github.com/appc/spec 6 | version: ^v0.8.10 7 | subpackages: 8 | - aci 9 | - schema 10 | - package: github.com/asaskevich/govalidator 11 | version: 9699ab6b38bee2e02cd3fe8b99ecf67665395c96 12 | - package: github.com/urfave/cli 13 | version: ^1.19.0 14 | - package: github.com/urfave/negroni 15 | version: c7477ad8e330bef55bf1ebe300cf8aa67c492d1b 16 | - package: github.com/ghodss/yaml 17 | version: c3eb24aeea63668ebdac08d2e252f20df8b6b1ae 18 | - package: github.com/golang/protobuf 19 | version: 888eb0692c857ec880338addf316bd662d5e630e 20 | subpackages: 21 | - proto 22 | - package: github.com/hashicorp/go-msgpack 23 | version: fa3f63826f7c23912c15263591e65d54d080b458 24 | subpackages: 25 | - codec 26 | - package: github.com/hashicorp/memberlist 27 | version: a93fbd426dd831f5a66db3adc6a5ffa6f44cc60a 28 | - package: github.com/intelsdi-x/gomit 29 | - package: github.com/julienschmidt/httprouter 30 | version: 8c199fb6259ffc1af525cc3ad52ee60ba8359669 31 | - package: github.com/pborman/uuid 32 | version: ca53cad383cad2479bbba7f7a1a05797ec1386e4 33 | - package: github.com/robfig/cron 34 | version: 32d9c273155a0506d27cf73dd1246e86a470997e 35 | - package: github.com/vrischmann/jsonutil 36 | version: 694784f9315ee9fc763c1d30f28753cba21307aa 37 | - package: github.com/xeipuuv/gojsonschema 38 | version: d3178baac32433047aa76f07317f84fbe2be6cda 39 | - package: golang.org/x/crypto 40 | version: aedad9a179ec1ea11b7064c57cbc6dc30d7724ec 41 | subpackages: 42 | - openpgp 43 | - ssh/terminal 44 | - package: golang.org/x/net 45 | subpackages: 46 | - context 47 | - trace 48 | - http2 49 | - package: google.golang.org/grpc 50 | version: ~v1.5.2 51 | - package: gopkg.in/yaml.v2 52 | version: c1cd2254a6dd314c9d73c338c12688c9325d85c6 53 | - package: github.com/intelsdi-x/snap-plugin-lib-go 54 | - package: github.com/intelsdi-x/snap-plugin-utilities 55 | -------------------------------------------------------------------------------- /grpc/common/common.proto: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | syntax = "proto3"; 20 | 21 | package common; 22 | 23 | message Time{ 24 | int64 sec = 1; 25 | int64 nsec = 2; 26 | } 27 | 28 | message Empty{ 29 | } 30 | 31 | message SnapError { 32 | string error_string = 1; 33 | map error_fields = 2; 34 | } 35 | 36 | message Label { 37 | uint64 index = 1; 38 | string name = 2; 39 | } 40 | // core.Metric 41 | message Metric { 42 | repeated NamespaceElement Namespace = 1; 43 | int64 Version = 2; 44 | ConfigMap Config = 3; 45 | Time LastAdvertisedTime = 4; 46 | map Tags = 5; 47 | Time Timestamp = 6; 48 | string Unit = 7; 49 | string Description = 8; 50 | oneof data { 51 | string string_data = 9; 52 | float float32_data = 10; 53 | double float64_data = 11; 54 | int32 int32_data = 12; 55 | int64 int64_data = 13; 56 | bytes bytes_data = 14; 57 | bool bool_data = 15; 58 | uint32 uint32_data = 16; 59 | uint64 uint64_data = 17; 60 | } 61 | } 62 | 63 | message NamespaceElement { 64 | string Value = 1; 65 | string Description = 2; 66 | string Name = 3; 67 | } 68 | 69 | // core.SubscribedPlugin 70 | message SubscribedPlugin { 71 | string TypeName = 1; 72 | string Name = 2; 73 | int64 Version = 3; 74 | ConfigMap Config = 4; 75 | } 76 | 77 | message ConfigMap { 78 | map IntMap = 1; 79 | map StringMap = 2; 80 | // double is float64 81 | map FloatMap = 3; 82 | map BoolMap = 4; 83 | } 84 | 85 | // core.Plugin 86 | message Plugin { 87 | string TypeName = 1; 88 | string Name = 2; 89 | int64 Version = 3; 90 | } 91 | -------------------------------------------------------------------------------- /mgmt/rest/api/api.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/julienschmidt/httprouter" 5 | ) 6 | 7 | type API interface { 8 | GetRoutes() []Route 9 | BindMetricManager(Metrics) 10 | BindTaskManager(Tasks) 11 | BindTribeManager(Tribe) 12 | BindConfigManager(Config) 13 | } 14 | 15 | type Route struct { 16 | Method, Path string 17 | Handle httprouter.Handle 18 | } 19 | -------------------------------------------------------------------------------- /mgmt/rest/api/config.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/intelsdi-x/snap/core" 5 | "github.com/intelsdi-x/snap/core/cdata" 6 | ) 7 | 8 | type Config interface { 9 | GetPluginConfigDataNode(core.PluginType, string, int) cdata.ConfigDataNode 10 | GetPluginConfigDataNodeAll() cdata.ConfigDataNode 11 | MergePluginConfigDataNode(pluginType core.PluginType, name string, ver int, cdn *cdata.ConfigDataNode) cdata.ConfigDataNode 12 | MergePluginConfigDataNodeAll(cdn *cdata.ConfigDataNode) cdata.ConfigDataNode 13 | DeletePluginConfigDataNodeField(pluginType core.PluginType, name string, ver int, fields ...string) cdata.ConfigDataNode 14 | DeletePluginConfigDataNodeFieldAll(fields ...string) cdata.ConfigDataNode 15 | } 16 | -------------------------------------------------------------------------------- /mgmt/rest/api/metric.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/intelsdi-x/snap/core" 5 | "github.com/intelsdi-x/snap/core/serror" 6 | ) 7 | 8 | type Metrics interface { 9 | MetricCatalog() ([]core.CatalogedMetric, error) 10 | FetchMetrics(core.Namespace, int) ([]core.CatalogedMetric, error) 11 | GetMetricVersions(core.Namespace) ([]core.CatalogedMetric, error) 12 | GetMetric(core.Namespace, int) (core.CatalogedMetric, error) 13 | Load(*core.RequestedPlugin) (core.CatalogedPlugin, serror.SnapError) 14 | Unload(core.Plugin) (core.CatalogedPlugin, serror.SnapError) 15 | PluginCatalog() core.PluginCatalog 16 | AvailablePlugins() []core.AvailablePlugin 17 | GetAutodiscoverPaths() []string 18 | GetTempDir() string 19 | } 20 | -------------------------------------------------------------------------------- /mgmt/rest/api/task.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/intelsdi-x/snap/core" 5 | "github.com/intelsdi-x/snap/core/serror" 6 | "github.com/intelsdi-x/snap/pkg/schedule" 7 | "github.com/intelsdi-x/snap/scheduler/wmap" 8 | ) 9 | 10 | type Tasks interface { 11 | CreateTask(schedule.Schedule, *wmap.WorkflowMap, bool, ...core.TaskOption) (core.Task, core.TaskErrors) 12 | GetTasks() map[string]core.Task 13 | GetTask(string) (core.Task, error) 14 | StartTask(string) []serror.SnapError 15 | StopTask(string) []serror.SnapError 16 | RemoveTask(string) error 17 | WatchTask(string, core.TaskWatcherHandler) (core.TaskWatcherCloser, error) 18 | EnableTask(string) (core.Task, error) 19 | } 20 | -------------------------------------------------------------------------------- /mgmt/rest/api/tribe.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "github.com/intelsdi-x/snap/core/serror" 5 | "github.com/intelsdi-x/snap/mgmt/tribe/agreement" 6 | ) 7 | 8 | type Tribe interface { 9 | GetAgreement(name string) (*agreement.Agreement, serror.SnapError) 10 | GetAgreements() map[string]*agreement.Agreement 11 | AddAgreement(name string) serror.SnapError 12 | RemoveAgreement(name string) serror.SnapError 13 | JoinAgreement(agreementName, memberName string) serror.SnapError 14 | LeaveAgreement(agreementName, memberName string) serror.SnapError 15 | GetMembers() []string 16 | GetMember(name string) *agreement.Member 17 | } 18 | -------------------------------------------------------------------------------- /mgmt/rest/client/README.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | Go snap client 21 | =============== 22 | 23 | Go bindings for snap's REST API 24 | -------------------------------------------------------------------------------- /mgmt/rest/flags.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package rest 21 | 22 | import ( 23 | "fmt" 24 | 25 | "github.com/urfave/cli" 26 | ) 27 | 28 | var ( 29 | flAPIDisabled = cli.BoolFlag{ 30 | Name: "disable-api, d", 31 | Usage: "Disable the agent REST API", 32 | } 33 | flAPIAddr = cli.StringFlag{ 34 | Name: "api-addr, b", 35 | Usage: "API Address[:port] to bind to/listen on. Default: empty string => listen on all interfaces", 36 | EnvVar: "SNAP_ADDR", 37 | } 38 | flAPIPort = cli.StringFlag{ 39 | Name: "api-port, p", 40 | Usage: fmt.Sprintf("API port (default: %v)", defaultPort), 41 | EnvVar: "SNAP_PORT", 42 | } 43 | flRestHTTPS = cli.BoolFlag{ 44 | Name: "rest-https", 45 | Usage: "start Snap's API as https", 46 | } 47 | flRestCert = cli.StringFlag{ 48 | Name: "rest-cert", 49 | Usage: "A path to a certificate to use for HTTPS deployment of Snap's REST API", 50 | } 51 | flRestKey = cli.StringFlag{ 52 | Name: "rest-key", 53 | Usage: "A path to a key file to use for HTTPS deployment of Snap's REST API", 54 | } 55 | flRestAuth = cli.BoolFlag{ 56 | Name: "rest-auth", 57 | Usage: "Enables Snap's REST API authentication", 58 | } 59 | flPProf = cli.BoolFlag{ 60 | Name: "pprof", 61 | Usage: "Enables profiling tools", 62 | } 63 | flCorsd = cli.StringFlag{ 64 | Name: "allowed_origins", 65 | Usage: "Define Cors allowed origins", 66 | } 67 | 68 | // Flags consumed by snapteld 69 | Flags = []cli.Flag{flAPIDisabled, flAPIAddr, flAPIPort, flRestHTTPS, flRestCert, flRestKey, flRestAuth, flPProf, flCorsd} 70 | ) 71 | -------------------------------------------------------------------------------- /mgmt/rest/log_handler.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package rest 21 | 22 | import ( 23 | "net/http" 24 | 25 | log "github.com/sirupsen/logrus" 26 | "github.com/urfave/negroni" 27 | ) 28 | 29 | // Logger is a snap middleware that logs to a logrus facility 30 | type Logger struct { 31 | counter uint 32 | } 33 | 34 | // NewLogger returns a new Logger instance 35 | func NewLogger() *Logger { 36 | return &Logger{} 37 | } 38 | 39 | func (l *Logger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc) { 40 | l.counter++ 41 | restLogger.WithFields(log.Fields{ 42 | "index": l.counter, 43 | "method": r.Method, 44 | "url": r.URL.Path, 45 | }).Debug("API request") 46 | next(rw, r) 47 | res := rw.(negroni.ResponseWriter) 48 | restLogger.WithFields(log.Fields{ 49 | "index": l.counter, 50 | "method": r.Method, 51 | "url": r.URL.Path, 52 | "status-code": res.Status(), 53 | "status": http.StatusText(res.Status()), 54 | }).Debug("API response") 55 | } 56 | -------------------------------------------------------------------------------- /mgmt/rest/pprof.go: -------------------------------------------------------------------------------- 1 | package rest 2 | 3 | import ( 4 | "net/http" 5 | "net/http/pprof" 6 | 7 | "github.com/julienschmidt/httprouter" 8 | ) 9 | 10 | func (s *Server) addPprofRoutes() { 11 | if s.pprof { 12 | s.r.GET("/debug/pprof/", s.index) 13 | s.r.GET("/debug/pprof/block", s.index) 14 | s.r.GET("/debug/pprof/goroutine", s.index) 15 | s.r.GET("/debug/pprof/heap", s.index) 16 | s.r.GET("/debug/pprof/threadcreate", s.index) 17 | s.r.GET("/debug/pprof/cmdline", s.cmdline) 18 | s.r.GET("/debug/pprof/profile", s.profile) 19 | s.r.GET("/debug/pprof/symbol", s.symbol) 20 | s.r.GET("/debug/pprof/trace", s.trace) 21 | } 22 | } 23 | 24 | // profiling tools handlers 25 | 26 | func (s *Server) index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 27 | pprof.Index(w, r) 28 | } 29 | 30 | func (s *Server) cmdline(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 31 | pprof.Cmdline(w, r) 32 | } 33 | 34 | func (s *Server) profile(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 35 | pprof.Profile(w, r) 36 | } 37 | 38 | func (s *Server) symbol(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 39 | pprof.Symbol(w, r) 40 | } 41 | 42 | func (s *Server) trace(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { 43 | pprof.Trace(w, r) 44 | } 45 | -------------------------------------------------------------------------------- /mgmt/rest/v1/metric_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package v1 23 | 24 | import ( 25 | "testing" 26 | 27 | . "github.com/smartystreets/goconvey/convey" 28 | ) 29 | 30 | func TestParseNamespace(t *testing.T) { 31 | tcs := getNsTestCases() 32 | 33 | Convey("Test parseNamespace", t, func() { 34 | for _, c := range tcs { 35 | Convey("Test parseNamespace "+c.input, func() { 36 | So(c.output, ShouldResemble, parseNamespace(c.input)) 37 | }) 38 | } 39 | }) 40 | } 41 | 42 | type nsTestCase struct { 43 | input string 44 | output []string 45 | } 46 | 47 | func getNsTestCases() []nsTestCase { 48 | tcs := []nsTestCase{ 49 | { 50 | input: "小a小b小c", 51 | output: []string{"a", "b", "c"}}, 52 | { 53 | input: "%a%b%c", 54 | output: []string{"a", "b", "c"}}, 55 | { 56 | input: "-aヒ-b/-c|", 57 | output: []string{"aヒ", "b/", "c|"}}, 58 | { 59 | input: ">a>b=>c=", 60 | output: []string{"a", "b=", "c="}}, 61 | { 62 | input: ">a>b<>c<", 63 | output: []string{"a", "b<", "c<"}}, 64 | { 65 | input: "㊽a㊽b%㊽c/|", 66 | output: []string{"a", "b%", "c/|"}}, 67 | } 68 | return tcs 69 | } 70 | -------------------------------------------------------------------------------- /mgmt/rest/v1/rbody/config.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package rbody 21 | 22 | import "github.com/intelsdi-x/snap/core/cdata" 23 | 24 | const ( 25 | PluginConfigItemType = "config_plugin_item_returned" 26 | SetPluginConfigItemType = "config_plugin_item_created" 27 | DeletePluginConfigItemType = "config_plugin_item_deleted" 28 | ) 29 | 30 | type DeletePluginConfigItem PluginConfigItem 31 | 32 | func (t *DeletePluginConfigItem) ResponseBodyMessage() string { 33 | return "Plugin config item field(s) deleted" 34 | } 35 | 36 | func (t *DeletePluginConfigItem) ResponseBodyType() string { 37 | return DeletePluginConfigItemType 38 | } 39 | 40 | type SetPluginConfigItem PluginConfigItem 41 | 42 | func (t *SetPluginConfigItem) ResponseBodyMessage() string { 43 | return "Plugin config item(s) set" 44 | } 45 | 46 | func (t *SetPluginConfigItem) ResponseBodyType() string { 47 | return SetPluginConfigItemType 48 | } 49 | 50 | type PluginConfigItem struct { 51 | cdata.ConfigDataNode 52 | } 53 | 54 | func (t *PluginConfigItem) ResponseBodyMessage() string { 55 | return "Plugin config item retrieved" 56 | } 57 | 58 | func (t *PluginConfigItem) ResponseBodyType() string { 59 | return PluginConfigItemType 60 | } 61 | -------------------------------------------------------------------------------- /mgmt/rest/v1/rbody/error.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package rbody 21 | 22 | import ( 23 | "fmt" 24 | 25 | "github.com/intelsdi-x/snap/core/serror" 26 | ) 27 | 28 | const ( 29 | ErrorType = "error" 30 | ) 31 | 32 | // Unsuccessful generic response to a failed API call 33 | type Error struct { 34 | ErrorMessage string `json:"message"` 35 | Fields map[string]string `json:"fields"` 36 | } 37 | 38 | func FromSnapError(pe serror.SnapError) *Error { 39 | e := &Error{ErrorMessage: pe.Error(), Fields: make(map[string]string)} 40 | // Convert into string format 41 | for k, v := range pe.Fields() { 42 | e.Fields[k] = fmt.Sprint(v) 43 | } 44 | return e 45 | } 46 | 47 | func FromSnapErrors(errs []serror.SnapError) *Error { 48 | fields := make(map[string]string) 49 | var msg string 50 | for i, err := range errs { 51 | for k, v := range err.Fields() { 52 | fields[fmt.Sprintf("%s_err_%d", k, i)] = fmt.Sprint(v) 53 | } 54 | msg = msg + fmt.Sprintf("error %d: %s ", i, err.Error()) 55 | } 56 | return &Error{ 57 | ErrorMessage: msg, 58 | Fields: fields, 59 | } 60 | } 61 | 62 | func FromError(err error) *Error { 63 | e := &Error{ErrorMessage: err.Error(), Fields: make(map[string]string)} 64 | return e 65 | } 66 | 67 | func (e *Error) Error() string { 68 | return e.ErrorMessage 69 | } 70 | 71 | func (e *Error) ResponseBodyMessage() string { 72 | return e.ErrorMessage 73 | } 74 | 75 | func (e *Error) ResponseBodyType() string { 76 | return ErrorType 77 | } 78 | -------------------------------------------------------------------------------- /mgmt/rest/v2/metric_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package v2 23 | 24 | import ( 25 | "testing" 26 | 27 | . "github.com/smartystreets/goconvey/convey" 28 | ) 29 | 30 | func TestParseNamespace(t *testing.T) { 31 | tcs := getNsTestCases() 32 | 33 | Convey("Test parseNamespace", t, func() { 34 | for _, c := range tcs { 35 | Convey("Test parseNamespace "+c.input, func() { 36 | So(c.output, ShouldResemble, parseNamespace(c.input)) 37 | }) 38 | } 39 | }) 40 | } 41 | 42 | type nsTestCase struct { 43 | input string 44 | output []string 45 | } 46 | 47 | func getNsTestCases() []nsTestCase { 48 | tcs := []nsTestCase{ 49 | { 50 | input: "小a小b小c", 51 | output: []string{"a", "b", "c"}}, 52 | { 53 | input: "%a%b%c", 54 | output: []string{"a", "b", "c"}}, 55 | { 56 | input: "-aヒ-b/-c|", 57 | output: []string{"aヒ", "b/", "c|"}}, 58 | { 59 | input: ">a>b=>c=", 60 | output: []string{"a", "b=", "c="}}, 61 | { 62 | input: ">a>b<>c<", 63 | output: []string{"a", "b<", "c<"}}, 64 | { 65 | input: "㊽a㊽b%㊽c/|", 66 | output: []string{"a", "b%", "c/|"}}, 67 | } 68 | return tcs 69 | } 70 | -------------------------------------------------------------------------------- /mgmt/rest/wmap_sample/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "collect": { 3 | "metrics": { 4 | "/intel/mock/foo": {} 5 | }, 6 | "config": { 7 | "/intel/mock/foo": { 8 | "password": "testval" 9 | } 10 | }, 11 | "process": [], 12 | "publish": [ 13 | { 14 | "plugin_name": "mock-file", 15 | "config": { 16 | "file": "/tmp/rest.test" 17 | } 18 | } 19 | ] 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mgmt/rest/wmap_sample/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "collect": { 3 | "metrics": { 4 | "/psutil/load/load1": {} 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /mgmt/rest/wmap_sample/3.json: -------------------------------------------------------------------------------- 1 | { 2 | "collect": { 3 | "metrics": { 4 | "/intel/mock/foo": {"version": 2} 5 | }, 6 | "config": { 7 | "/intel/mock/foo": { 8 | "password": "testval" 9 | } 10 | }, 11 | "process": [], 12 | "publish": [] 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mgmt/rest/wmap_sample/bad.json: -------------------------------------------------------------------------------- 1 | { 2 | "collect": { 3 | "metrics": { 4 | "/intel/mock/foo": {} 5 | }, 6 | "config": {}, 7 | "process": [], 8 | "publish": [ 9 | { 10 | "plugin_name": "mock-file", 11 | "config": { 12 | "file": "/tmp/rest.test" 13 | } 14 | } 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /mgmt/tribe/broadcast.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package tribe 21 | 22 | import "github.com/hashicorp/memberlist" 23 | 24 | // broadcast implements memberlist.Broadcast 25 | type broadcast struct { 26 | msg []byte 27 | notify chan<- struct{} 28 | } 29 | 30 | func (b *broadcast) Invalidates(other memberlist.Broadcast) bool { 31 | return false 32 | } 33 | 34 | func (b *broadcast) Message() []byte { 35 | return b.msg 36 | } 37 | 38 | func (b *broadcast) Finished() { 39 | if b.notify != nil { 40 | close(b.notify) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /mgmt/tribe/clock.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package tribe 21 | 22 | import "sync/atomic" 23 | 24 | type LClock struct { 25 | Inc uint64 26 | } 27 | 28 | type LTime uint64 29 | 30 | //Update 31 | func (l *LClock) Update(lt LTime) { 32 | for { 33 | cur := LTime(atomic.LoadUint64(&l.Inc)) 34 | // If we are newer return now 35 | if lt < cur { 36 | return 37 | } 38 | // If we CAS successfully return else our counter changed 39 | // and we need to try again 40 | if atomic.CompareAndSwapUint64(&l.Inc, uint64(cur), uint64(lt)+1) { 41 | return 42 | } 43 | } 44 | } 45 | 46 | // Increment 47 | func (l *LClock) Increment() LTime { 48 | return LTime(atomic.AddUint64(&l.Inc, 1)) 49 | } 50 | 51 | // Time returns the current value of the clock 52 | func (l *LClock) Time() LTime { 53 | return LTime(atomic.LoadUint64(&l.Inc)) 54 | } 55 | -------------------------------------------------------------------------------- /mgmt/tribe/flags.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package tribe 21 | 22 | import ( 23 | "fmt" 24 | 25 | "github.com/urfave/cli" 26 | ) 27 | 28 | var ( 29 | flTribeNodeName = cli.StringFlag{ 30 | Name: "tribe-node-name", 31 | Usage: "Name of this node in tribe cluster (default: hostname)", 32 | EnvVar: "SNAP_TRIBE_NODE_NAME", 33 | } 34 | 35 | flTribe = cli.BoolFlag{ 36 | Name: "tribe", 37 | Usage: `Enable tribe mode`, 38 | EnvVar: "SNAP_TRIBE", 39 | } 40 | 41 | flTribeSeed = cli.StringFlag{ 42 | Name: "tribe-seed", 43 | Usage: "IP (or hostname) and port of a node to join (e.g. 127.0.0.1:6000)", 44 | EnvVar: "SNAP_TRIBE_SEED", 45 | } 46 | 47 | flTribeAdvertisePort = cli.StringFlag{ 48 | Name: "tribe-port", 49 | Usage: fmt.Sprintf("Port tribe gossips over to maintain membership (default: %v)", defaultBindPort), 50 | EnvVar: "SNAP_TRIBE_PORT", 51 | } 52 | 53 | flTribeAdvertiseAddr = cli.StringFlag{ 54 | Name: "tribe-addr", 55 | Usage: "Addr tribe gossips over to maintain membership", 56 | EnvVar: "SNAP_TRIBE_ADDR", 57 | } 58 | 59 | // Flags consumed by snapteld 60 | Flags = []cli.Flag{flTribeNodeName, flTribe, flTribeSeed, flTribeAdvertiseAddr, flTribeAdvertisePort} 61 | ) 62 | -------------------------------------------------------------------------------- /mgmt/tribe/member_delegate.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package tribe 21 | 22 | import ( 23 | "github.com/hashicorp/memberlist" 24 | ) 25 | 26 | type memberDelegate struct { 27 | tribe *tribe 28 | } 29 | 30 | func (m *memberDelegate) NotifyJoin(n *memberlist.Node) { 31 | m.tribe.handleMemberJoin(n) 32 | } 33 | 34 | func (m *memberDelegate) NotifyLeave(n *memberlist.Node) { 35 | m.tribe.handleMemberLeave(n) 36 | } 37 | 38 | func (m *memberDelegate) NotifyUpdate(n *memberlist.Node) { 39 | m.tribe.handleMemberUpdate(n) 40 | } 41 | -------------------------------------------------------------------------------- /mgmt/tribe/query.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package tribe 21 | 22 | import ( 23 | "sync" 24 | "time" 25 | 26 | "github.com/intelsdi-x/snap/core" 27 | ) 28 | 29 | const ( 30 | TaskStateQueryResponseSizeLimit int = 1024 31 | ) 32 | 33 | type taskStateResponses []taskStateResponse 34 | 35 | type taskStateResponse struct { 36 | From string 37 | State core.TaskState 38 | } 39 | 40 | func (t taskStateResponses) State() core.TaskState { 41 | states := map[core.TaskState]int{} 42 | for _, r := range t { 43 | if _, ok := states[r.State]; !ok { 44 | states[r.State] = 1 45 | } 46 | states[r.State]++ 47 | } 48 | state := struct { 49 | count int 50 | state core.TaskState 51 | }{ 52 | count: 0, 53 | state: core.TaskStopped, 54 | } 55 | for k, v := range states { 56 | if v > state.count { 57 | state.count = v 58 | state.state = k 59 | } 60 | } 61 | return state.state 62 | } 63 | 64 | type taskStateQueryResponse struct { 65 | uuid string 66 | ltime LTime 67 | deadline time.Time 68 | isClosed bool 69 | from map[string]core.TaskState 70 | resp chan taskStateResponse 71 | lock sync.Mutex 72 | } 73 | 74 | func newStateQueryResponse(n int, q *taskStateQueryMsg) *taskStateQueryResponse { 75 | return &taskStateQueryResponse{ 76 | uuid: q.UUID, 77 | ltime: q.LTime, 78 | from: map[string]core.TaskState{}, 79 | resp: make(chan taskStateResponse, n), 80 | } 81 | } 82 | 83 | func (s *taskStateQueryResponse) Close() { 84 | s.lock.Lock() 85 | defer s.lock.Unlock() 86 | if s.isClosed { 87 | return 88 | } 89 | if s.resp != nil { 90 | close(s.resp) 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /pkg/chrono/chrono.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package chrono 21 | 22 | import ( 23 | "time" 24 | ) 25 | 26 | // The chrono structure provides an artificial notion of time that can be 27 | // stopped, forwarded to make testing of timed code deterministic. 28 | type chrono struct { 29 | skew time.Duration 30 | paused bool 31 | pausedAt time.Time 32 | } 33 | 34 | // Now() should replace usage of time.Now(). If chrono has been paused, Now() 35 | // returns the time when it was paused. If there is any skew (due to forwarding 36 | // or reversing), this is always added to the end time. 37 | func (c *chrono) Now() time.Time { 38 | var now time.Time 39 | if c.paused { 40 | now = c.pausedAt 41 | } else { 42 | now = time.Now() 43 | } 44 | return now.Add(c.skew) 45 | } 46 | 47 | // Forwards time of chrono with skew time. This can be used in both running and 48 | // paused mode. 49 | func (c *chrono) Forward(skew time.Duration) { 50 | c.skew = skew 51 | } 52 | 53 | // Resets any previous set clock skew. 54 | func (c *chrono) Reset() { 55 | c.skew = 0 56 | } 57 | 58 | // Pause "Stops" time by recording current time and shortcircuit Now() to return this 59 | // time instead of the actual time (plus skew). 60 | func (c *chrono) Pause() { 61 | c.pausedAt = c.Now() 62 | c.paused = true 63 | } 64 | 65 | // Continues time after having been paused. This has no effect if clock is 66 | // already running. 67 | func (c *chrono) Continue() { 68 | c.paused = false 69 | } 70 | 71 | // Chrono variable 72 | var Chrono chrono 73 | -------------------------------------------------------------------------------- /pkg/fileutils/file.go: -------------------------------------------------------------------------------- 1 | package fileutils 2 | 3 | import ( 4 | "io/ioutil" 5 | "os" 6 | "path/filepath" 7 | "runtime" 8 | 9 | log "github.com/sirupsen/logrus" 10 | ) 11 | 12 | // WriteFile creates a temporary directory for loading plugins 13 | // Plugins loaded by the cli and from the auto-load directory go through this route of copying the plugin binaries to the temp dir and executing from temp 14 | // WriteFile takes the name of the original file (fileName), path to the original file (filePath) and the content of the file (b) 15 | // Returns temporary file path and error 16 | func WriteFile(fileName, filePath string, b []byte) (string, error) { 17 | // Create temporary directory 18 | dir, err := ioutil.TempDir(filePath, "snap-plugin-") 19 | if err != nil { 20 | return "", err 21 | } 22 | 23 | f, err := os.Create(filepath.Join(dir, fileName)) 24 | if err != nil { 25 | return "", err 26 | } 27 | // Close before load 28 | defer f.Close() 29 | 30 | n, err := f.Write(b) 31 | log.Debugf("wrote %v to %v", n, f.Name()) 32 | if err != nil { 33 | return "", err 34 | } 35 | if runtime.GOOS != "windows" { 36 | err = f.Chmod(0700) 37 | if err != nil { 38 | return "", err 39 | } 40 | } 41 | return f.Name(), nil 42 | } 43 | -------------------------------------------------------------------------------- /pkg/netutil/net.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package netutil 21 | 22 | import "net" 23 | 24 | // GetIP returns the first non-loopback ipv4 interface. The loopback interface 25 | // is returned if no other interface is present. 26 | func GetIP() string { 27 | ifaces, err := net.Interfaces() 28 | if err != nil { 29 | return "127.0.0.1" 30 | } 31 | for _, i := range ifaces { 32 | addrs, err := i.Addrs() 33 | if err != nil { 34 | return "127.0.0.1" 35 | } 36 | for _, addr := range addrs { 37 | var ip net.IP 38 | switch v := addr.(type) { 39 | case *net.IPAddr: 40 | ip = v.IP 41 | case *net.IPNet: 42 | ip = v.IP 43 | } 44 | if ip == nil || ip.IsLoopback() { 45 | continue 46 | } 47 | ip = ip.To4() 48 | if ip == nil { 49 | continue // not an ipv4 address 50 | } 51 | return ip.String() 52 | } 53 | } 54 | return "127.0.0.1" 55 | } 56 | -------------------------------------------------------------------------------- /pkg/netutil/net_medium_test.go: -------------------------------------------------------------------------------- 1 | // +build medium 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package netutil 23 | 24 | import ( 25 | "net" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestNetUtil(t *testing.T) { 32 | Convey("Get the first non-loopback ipv4 interface", t, func() { 33 | ip := GetIP() 34 | ifaces, err := net.Interfaces() 35 | So(err, ShouldBeNil) 36 | if len(ifaces) > 1 { 37 | So(ip, ShouldNotResemble, "127.0.0.1") 38 | } else { 39 | So(ip, ShouldResemble, "127.0.0.1") 40 | } 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /pkg/psigning/pubkeys.gpg: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP PUBLIC KEY BLOCK----- 2 | Version: GnuPG v1 3 | 4 | mQENBFY6gd0BCAC7zbfKUxdBvPdhRwXMkit0sGr7K/yLiABBLVUX+qLQMBRS0XL7 5 | Beb3tDZGo7siFHc1K4iAtMAeAawL4ghPxKxfaGW/8fVU2FT0hzXRTvrOhAxFksC1 6 | TzDoFi0/hlPMs/ApV7gat0WDtvuPNjnFdx2XN3vxpHlFfQOSXUS4oXOKqeeArPBu 7 | pXGkDojw1tfy2ZZdYJOcP5TpbsVhHeObridYjpnxxN05Y9MahXnzbXsuQF4vgr/A 8 | SGOiEqFQ5zsU+aSQ9tIrWc1eRzVAXlBNQ6YkQeHviRQBNZydPimLejl8ro1SKgnr 9 | Z4Lq8iYFRlKd/JWGUp6l4/0nIUpuuicxYcRTABEBAAG0QlRpZmZhbnkgSmVybmln 10 | YW4gKFBsdWdpbiBzaWduaW5nIGtleSkgPHRpZmZhbnkuamVybmlnYW5AaW50ZWwu 11 | Y29tPokBOAQTAQIAIgUCVjqB3QIbLwYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AA 12 | CgkQ99N6+P6bXiiddQf/XrSeP7Etfoh+AIZVF/jhpXUHUe7/VoPqwrikRtQaVh3t 13 | 9LlRLgS9DK9np9FHXpioBjx7sTIwIEyWGe9LFM+yus6slglhkbxy6M3VR/HRJ1rd 14 | XiNLYpkTPDf1Ho3TrLRQdmkYpW52UlM64MYs6mP5vrg4xdyNnHa9PUCDZdFo7jh6 15 | 1zKJQkH+qrGgzjNACgMPkuIQb8itADDnWhHc64RR/5FPJ7IE/AFS7mhq3ddasd16 16 | Tvlh5ZbYFVktebxsFvShRSaqwsnhkNku3/0FWoeH2hv11cFdC6ayQF11rx04VFok 17 | zbY43feAvYKXet70WUFfzVs8XfIYyvUaa+mJcJmOP7kBDQRWOoHdAQgAtGteBtGT 18 | qITfMSVZ6wxwCCX5rKNgVajRZgYKOHlcwHVgnYsxOhavi9CTjSs1p/5qKGxQzPAT 19 | tSdzg2fgqpb1BbXt9s5NmJBXaNFwK+ij2iVEHLBng5XOpLbGWvtVnsrchXkuXCbe 20 | n9t7khfEH7m90EOd8kFmazt98kSDEassm2tApwrGUnbwtRWu5mo2Duu2ZX/KiSvb 21 | kddroAf9QByRWmRwLwdfZbckpbAryZ7vx96autUUHBH07pYjJYzjKfY/K5dMMn0d 22 | 8gxFlDhkpAWitm3bNOIW+ykRoC2tAjSNi5EE7vPyl8xvF2Vt10ssVQtn0dCJEy86 23 | FvfXuUdP+0RlAwARAQABiQI+BBgBAgAJBQJWOoHdAhsuASkJEPfTevj+m14owF0g 24 | BBkBAgAGBQJWOoHdAAoJEFaCHaoLxtTX70kH/Rpo5oiEnC1YmLmZ8SYsVWshsWVh 25 | F0b3qnMes+F/SvYxzMRXfzn8ZVLEgSpKGpe/q+sh5PZKOlCLjg6CpV0WZWlGSMB4 26 | 3pBpyYKMurUtTX8dyXPG6kRIJb23thSokT05HSoSh0uWfXVZacvv3GtP9Gt8YHVS 27 | qm29w1k8eNRcq2kBTtxNRA28FNVusysC2/GqLc8l+9AAzQHTAdgOCCSs2TcR2d2V 28 | mZ86yHv/1K2eiwTVbd42Xg2g7/raZvqQFc/dmGDnEtzHAHXd+CW0xHQbpbqCXkQ2 29 | a3e/iDn3YCQ5WEfNxEjmJvEM+rTEs5kKpHq7gVNgblPIUEyivK0FDb5YMckqRwf8 30 | DNK6zDNjlRnB1aZyfqRKGT6ByItHhd6pn2nFn/ESc6karp1hVc2ePq+Aa6y1oK4t 31 | HCv6zsr1Fk4U4gg7SuBg7h5FWhEnXP6Vg+c6lqic8dYMwDHCuMBsIOhlw8fPhwC/ 32 | jrRUnS8ZWf4NqsN9oxGkbVQ8rE1i7qpwOi8uzhBnlfIUYamrHF9rvWLsvehsGHdJ 33 | avTzVExGjzFg3wWZwaT3cDoR+UcscqXvRG9phhDocokgQ3jLjjSQ2CrVheEMIf1v 34 | dflrLySoLOw5aChVMeYfySdio59/HE1569wwOgw0ymj89GKgfbtvuiqhHS1Djocd 35 | Bh1CAy9/NYjYftalzAAmEA== 36 | =NZYf 37 | -----END PGP PUBLIC KEY BLOCK----- 38 | -------------------------------------------------------------------------------- /pkg/psigning/pubring.gpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intelsdi-x/snap/2b64b65fa413a80d28fb88ca993b875649b113e5/pkg/psigning/pubring.gpg -------------------------------------------------------------------------------- /pkg/psigning/snap-plugin-collector-mock1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/intelsdi-x/snap/2b64b65fa413a80d28fb88ca993b875649b113e5/pkg/psigning/snap-plugin-collector-mock1 -------------------------------------------------------------------------------- /pkg/psigning/snap-plugin-collector-mock1.asc: -------------------------------------------------------------------------------- 1 | -----BEGIN PGP SIGNATURE----- 2 | Version: GnuPG v1 3 | 4 | iQEcBAABAgAGBQJWOTB7AAoJEI4SiBUu1A+ywd0IAIfHa2e3f4v8iTgsxel71C8a 5 | X28hF3D9ld177GXfYy5MndP+9wptLLdPzEuYu6jmdIIRJgbKu97FhTREy6gw674M 6 | tkm9fUP14p0V8Mpt6BmKNKFbJGGc4SuU4CuNkONnji3XGCD55f/Hp1ERTrcCXDgT 7 | tOp5l5xwzIzg1UIYy+pjAeCX9pt6WFZZTcTlvwEb3Uo3PMelcFMUxN+XD1UcBLi8 8 | axGQ573+a5MTyh6sGiwCWjFRKNMW/xGKZbZokaszH9xxORcd/GyuocggWRtqlmLW 9 | Zy9q5uyjc6DqRDvYPQwDrAKkws0/K28kh0/3Bm08EOoOblBQIA98UHvniYvJNmw= 10 | =OKFH 11 | -----END PGP SIGNATURE----- 12 | -------------------------------------------------------------------------------- /pkg/rpcutil/rpc.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package rpcutil 21 | 22 | import ( 23 | "fmt" 24 | "time" 25 | 26 | "golang.org/x/net/context" 27 | "google.golang.org/grpc" 28 | "google.golang.org/grpc/credentials" 29 | ) 30 | 31 | // grpcDialDefaultTimeout is the default timeout for initial gRPC dial 32 | const grpcDialDefaultTimeout = 2 * time.Second 33 | 34 | // GetClientConnection returns a grcp.ClientConn that is unsecured 35 | func GetClientConnection(ctx context.Context, addr string, port int) (*grpc.ClientConn, error) { 36 | return GetClientConnectionWithCreds(ctx, addr, port, nil) 37 | } 38 | 39 | // GetClientConnectionWithCreds returns a grcp.ClientConn with optional TLS 40 | // security (if creds != nil) 41 | func GetClientConnectionWithCreds(ctx context.Context, addr string, port int, creds credentials.TransportCredentials) (*grpc.ClientConn, error) { 42 | grpcDialOpts := []grpc.DialOption{ 43 | grpc.WithTimeout(grpcDialDefaultTimeout), 44 | } 45 | if creds != nil { 46 | grpcDialOpts = append(grpcDialOpts, grpc.WithTransportCredentials(creds)) 47 | } else { 48 | grpcDialOpts = append(grpcDialOpts, grpc.WithInsecure()) 49 | } 50 | 51 | conn, err := grpc.DialContext(ctx, fmt.Sprintf("%v:%v", addr, port), grpcDialOpts...) 52 | if err != nil { 53 | return nil, err 54 | } 55 | return conn, nil 56 | } 57 | -------------------------------------------------------------------------------- /pkg/rpcutil/rpc_medium_test.go: -------------------------------------------------------------------------------- 1 | // +build medium 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package rpcutil 23 | 24 | import ( 25 | "context" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestRpcUtil(t *testing.T) { 32 | Convey("Get a client connection", t, func() { 33 | conn, err := GetClientConnection(context.Background(), "127.0.0.1", 8183) 34 | Convey("Provided a valid address, port", func() { 35 | So(err, ShouldBeNil) 36 | So(conn, ShouldNotBeNil) 37 | }) 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /pkg/schedule/streaming_schedule.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2017 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package schedule 21 | 22 | import "time" 23 | 24 | // StreamingSchedule is a schedule that only implements an endless repeating interval 25 | type StreamingSchedule struct { 26 | state ScheduleState 27 | } 28 | 29 | // NewStreamingSchedule returns the SimpleSchedule given the time interval 30 | func NewStreamingSchedule() *StreamingSchedule { 31 | return &StreamingSchedule{} 32 | } 33 | 34 | // GetState returns the schedule state 35 | func (s *StreamingSchedule) GetState() ScheduleState { 36 | return Active 37 | } 38 | 39 | // Validate returns an error if the interval of schedule is less 40 | // or equals zero 41 | func (s *StreamingSchedule) Validate() error { 42 | return nil 43 | } 44 | 45 | // Wait returns the StreamingSchedule state, misses and the last schedule ran 46 | func (s *StreamingSchedule) Wait(last time.Time) Response { 47 | return &StreamingScheduleResponse{} 48 | } 49 | 50 | // StreamingScheduleResponse a response from SimpleSchedule conforming to ScheduleResponse interface 51 | type StreamingScheduleResponse struct{} 52 | 53 | // State returns the state of the Schedule 54 | func (s *StreamingScheduleResponse) State() ScheduleState { 55 | return Active 56 | } 57 | 58 | // Error returns last error 59 | func (s *StreamingScheduleResponse) Error() error { 60 | return nil 61 | } 62 | 63 | // Missed returns any missed intervals 64 | func (s *StreamingScheduleResponse) Missed() uint { 65 | return 0 66 | } 67 | 68 | // LastTime returns the last response time 69 | func (s *StreamingScheduleResponse) LastTime() time.Time { 70 | return time.Time{} 71 | } 72 | -------------------------------------------------------------------------------- /pkg/stringutils/string.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package stringutils 21 | 22 | import "fmt" 23 | 24 | // GetFirstChar returns the first character from the input string. 25 | func GetFirstChar(s string) string { 26 | firstChar := "" 27 | for _, r := range s { 28 | firstChar = fmt.Sprintf("%c", r) 29 | break 30 | } 31 | return firstChar 32 | } 33 | -------------------------------------------------------------------------------- /plugin/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-anothermock1/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-anothermock1/anothermock/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-anothermock1/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "os" 24 | 25 | // Import the snap plugin library 26 | "github.com/intelsdi-x/snap/control/plugin" 27 | // Import our collector plugin implementation 28 | "github.com/intelsdi-x/snap/plugin/collector/snap-plugin-collector-anothermock1/anothermock" 29 | ) 30 | 31 | func main() { 32 | // Provided: 33 | // the definition of the plugin metadata 34 | // the implementation satisfying plugin.CollectorPlugin 35 | 36 | // Define metadata about Plugin 37 | meta := anothermock.Meta() 38 | 39 | // Start a collector 40 | plugin.Start(meta, new(anothermock.AnotherMock), os.Args[1]) 41 | } 42 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-anothermock1/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-anothermock1/main_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/control" 28 | "github.com/intelsdi-x/snap/core" 29 | "github.com/intelsdi-x/snap/plugin/helper" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | var ( 34 | PluginName = "snap-plugin-collector-anothermock1" 35 | PluginType = "collector" 36 | PluginPath = helper.PluginFilePath(PluginName) 37 | ) 38 | 39 | func TestMockPluginLoad(t *testing.T) { 40 | // These tests only work if SNAP_PATH is known. 41 | // It is the responsibility of the testing framework to 42 | // build the plugins first into the build dir. 43 | Convey("make sure plugin has been built", t, func() { 44 | err := helper.PluginFileCheck(PluginName) 45 | So(err, ShouldBeNil) 46 | 47 | Convey("ensure plugin loads and responds", func() { 48 | c := control.New(control.GetDefaultConfig()) 49 | c.Start() 50 | rp, err := core.NewRequestedPlugin(PluginPath, c.GetTempDir(), nil) 51 | Convey("Should not return an error when requested for a plugin", func() { 52 | So(err, ShouldBeNil) 53 | }) 54 | 55 | _, err = c.Load(rp) 56 | Convey("should not return an error when loading a plugin", func() { 57 | So(err, ShouldBeNil) 58 | }) 59 | }) 60 | }) 61 | } 62 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock1/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock1/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "os" 24 | 25 | // Import the snap plugin library 26 | "github.com/intelsdi-x/snap/control/plugin" 27 | // Import our collector plugin implementation 28 | "github.com/intelsdi-x/snap/plugin/collector/snap-plugin-collector-mock1/mock" 29 | ) 30 | 31 | func main() { 32 | // Provided: 33 | // the definition of the plugin metadata 34 | // the implementation satisfying plugin.CollectorPlugin 35 | 36 | // Define metadata about Plugin 37 | meta := mock.Meta() 38 | meta.RPCType = plugin.NativeRPC 39 | // Start a collector 40 | plugin.Start(meta, new(mock.Mock), os.Args[1]) 41 | } 42 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock1/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock1/main_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/control" 28 | "github.com/intelsdi-x/snap/core" 29 | "github.com/intelsdi-x/snap/plugin/helper" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | var ( 34 | PluginName = "snap-plugin-collector-mock1" 35 | PluginType = "collector" 36 | PluginPath = helper.PluginFilePath(PluginName) 37 | ) 38 | 39 | func TestMockPluginLoad(t *testing.T) { 40 | // These tests only work if SNAP_PATH is known. 41 | // It is the responsibility of the testing framework to 42 | // build the plugins first into the build dir. 43 | 44 | Convey("make sure plugin has been built", t, func() { 45 | err := helper.PluginFileCheck(PluginName) 46 | So(err, ShouldBeNil) 47 | 48 | Convey("ensure plugin loads and responds", func() { 49 | c := control.New(control.GetDefaultConfig()) 50 | c.Start() 51 | rp, err := core.NewRequestedPlugin(PluginPath, c.GetTempDir(), nil) 52 | Convey("Should not return an error when requested for a plugin", func() { 53 | So(err, ShouldBeNil) 54 | }) 55 | 56 | _, err = c.Load(rp) 57 | Convey("should not return an error when loading a plugin", func() { 58 | So(err, ShouldBeNil) 59 | }) 60 | 61 | }) 62 | 63 | }) 64 | } 65 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock1/mock/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2-grpc/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2-grpc/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "time" 24 | 25 | // Import the snap plugin library 26 | "github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin" 27 | // Import our collector plugin implementation 28 | "github.com/intelsdi-x/snap/plugin/collector/snap-plugin-collector-mock2-grpc/mock" 29 | ) 30 | 31 | const ( 32 | pluginName = "mock-grpc" 33 | pluginVersion = 1 34 | ) 35 | 36 | func main() { 37 | // Provided: 38 | // the definition of the plugin metadata 39 | // the implementation satisfying plugin.CollectorPlugin 40 | 41 | // Start a collector 42 | plugin.StartCollector( 43 | new(mock.Mock), 44 | pluginName, 45 | pluginVersion, 46 | plugin.CacheTTL(100*time.Millisecond), 47 | plugin.RoutingStrategy(plugin.StickyRouter), 48 | ) 49 | } 50 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2-grpc/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2-grpc/main_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/control" 28 | "github.com/intelsdi-x/snap/core" 29 | "github.com/intelsdi-x/snap/plugin/helper" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | var ( 34 | PluginName = "snap-plugin-collector-mock2-grpc" 35 | PluginType = "collector" 36 | PluginPath = helper.PluginFilePath(PluginName) 37 | ) 38 | 39 | func TestMockPluginLoad(t *testing.T) { 40 | // These tests only work if SNAP_PATH is known. 41 | // It is the responsibility of the testing framework to 42 | // build the plugins first into the build dir. 43 | Convey("make sure plugin has been built", t, func() { 44 | err := helper.PluginFileCheck(PluginName) 45 | So(err, ShouldBeNil) 46 | 47 | Convey("ensure plugin loads and responds", func() { 48 | c := control.New(control.GetDefaultConfig()) 49 | c.Start() 50 | rp, err := core.NewRequestedPlugin(PluginPath, c.GetTempDir(), nil) 51 | Convey("Should not return an error when requested for a plugin", func() { 52 | So(err, ShouldBeNil) 53 | }) 54 | 55 | _, err = c.Load(rp) 56 | Convey("should not return an error when loading a plugin", func() { 57 | So(err, ShouldBeNil) 58 | }) 59 | }) 60 | 61 | }) 62 | } 63 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2-grpc/mock/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "os" 24 | 25 | // Import the snap plugin library 26 | "github.com/intelsdi-x/snap/control/plugin" 27 | // Import our collector plugin implementation 28 | "github.com/intelsdi-x/snap/plugin/collector/snap-plugin-collector-mock2/mock" 29 | ) 30 | 31 | func main() { 32 | // Provided: 33 | // the definition of the plugin metadata 34 | // the implementation satisfying plugin.CollectorPlugin 35 | 36 | // Define metadata about Plugin 37 | meta := mock.Meta() 38 | 39 | // Start a collector 40 | plugin.Start(meta, new(mock.Mock), os.Args[1]) 41 | } 42 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2/main_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/control" 28 | "github.com/intelsdi-x/snap/core" 29 | "github.com/intelsdi-x/snap/plugin/helper" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | var ( 34 | PluginName = "snap-plugin-collector-mock2" 35 | PluginType = "collector" 36 | PluginPath = helper.PluginFilePath(PluginName) 37 | ) 38 | 39 | func TestMockPluginLoad(t *testing.T) { 40 | // These tests only work if SNAP_PATH is known. 41 | // It is the responsibility of the testing framework to 42 | // build the plugins first into the build dir. 43 | Convey("make sure plugin has been built", t, func() { 44 | err := helper.PluginFileCheck(PluginName) 45 | So(err, ShouldBeNil) 46 | 47 | Convey("ensure plugin loads and responds", func() { 48 | c := control.New(control.GetDefaultConfig()) 49 | c.Start() 50 | rp, err := core.NewRequestedPlugin(PluginPath, c.GetTempDir(), nil) 51 | Convey("Should not return an error when requested for a plugin", func() { 52 | So(err, ShouldBeNil) 53 | }) 54 | 55 | _, err = c.Load(rp) 56 | Convey("should not return an error when loading a plugin", func() { 57 | So(err, ShouldBeNil) 58 | }) 59 | }) 60 | 61 | }) 62 | } 63 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-collector-mock2/mock/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/collector/snap-plugin-streaming-collector-rand1/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2017 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin" 24 | "github.com/intelsdi-x/snap/plugin/collector/snap-plugin-streaming-collector-rand1/rand" 25 | ) 26 | 27 | const ( 28 | pluginName = "test-rand-streamer" 29 | pluginVersion = 1 30 | ) 31 | 32 | func main() { 33 | plugin.StartStreamCollector(&rand.RandCollector{}, pluginName, pluginVersion) 34 | } 35 | -------------------------------------------------------------------------------- /plugin/helper/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/helper/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | Copyright 2015 Intel Corporation 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Package helper The test helper for testing plugins 20 | package helper 21 | 22 | import ( 23 | "fmt" 24 | "os" 25 | "path" 26 | "runtime" 27 | ) 28 | 29 | var ( 30 | BuildPath = os.ExpandEnv(os.Getenv("SNAP_PATH")) 31 | ) 32 | 33 | func PluginFileCheck(name string) error { 34 | if BuildPath == "" { 35 | return fmt.Errorf("$SNAP_PATH environment variable not set. Cannot test plugins.\n") 36 | } 37 | 38 | fpath := PluginFilePath(name) 39 | if _, err := os.Stat(fpath); os.IsNotExist(err) { 40 | //the binary has not been built yet 41 | return fmt.Errorf("Error: %s does not exist in %s. Run make to build it.", name, fpath) 42 | } 43 | return nil 44 | } 45 | 46 | func PluginPath() string { 47 | var arch string 48 | if runtime.GOARCH == "amd64" { 49 | arch = "x86_64" 50 | } else { 51 | arch = runtime.GOARCH 52 | } 53 | 54 | fpath := path.Join(BuildPath, runtime.GOOS, arch, "plugins") 55 | return fpath 56 | } 57 | 58 | func PluginFilePath(name string) string { 59 | fpath := path.Join(PluginPath(), name) 60 | return fpath 61 | } 62 | -------------------------------------------------------------------------------- /plugin/processor/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/processor/snap-plugin-processor-passthru-grpc/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin" 24 | "github.com/intelsdi-x/snap/plugin/processor/snap-plugin-processor-passthru-grpc/passthru" 25 | ) 26 | 27 | const ( 28 | pluginName = "passthru-grpc" 29 | pluginVersion = 1 30 | ) 31 | 32 | func main() { 33 | plugin.StartProcessor(passthru.NewPassthruProcessor(), pluginName, pluginVersion) 34 | } 35 | -------------------------------------------------------------------------------- /plugin/processor/snap-plugin-processor-passthru-grpc/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/processor/snap-plugin-processor-passthru-grpc/passthru/passthru.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package passthru 21 | 22 | import ( 23 | log "github.com/sirupsen/logrus" 24 | 25 | "github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin" 26 | ) 27 | 28 | const ( 29 | debug = "debug" 30 | ) 31 | 32 | func NewPassthruProcessor() *passthruProcessor { 33 | return &passthruProcessor{} 34 | } 35 | 36 | type passthruProcessor struct{} 37 | 38 | func (p *passthruProcessor) GetConfigPolicy() (plugin.ConfigPolicy, error) { 39 | policy := plugin.NewConfigPolicy() 40 | return *policy, policy.AddNewBoolRule([]string{""}, debug, false) 41 | } 42 | 43 | func (p *passthruProcessor) Process(metrics []plugin.Metric, config plugin.Config) ([]plugin.Metric, error) { 44 | log.SetFormatter(&log.TextFormatter{DisableTimestamp: true}) 45 | if _, err := config.GetBool(debug); err == nil { 46 | log.SetLevel(log.DebugLevel) 47 | } else { 48 | log.SetLevel(log.InfoLevel) 49 | } 50 | 51 | log.Debug("processing started") 52 | 53 | if _, err := config.GetBool("test"); err == nil { 54 | log.Debug("test configuration found") 55 | for idx, m := range metrics { 56 | if m.Namespace.Strings()[0] == "foo" { 57 | log.Print("found foo metric") 58 | metrics[idx].Data = 2 59 | } 60 | } 61 | } 62 | 63 | return metrics, nil 64 | } 65 | -------------------------------------------------------------------------------- /plugin/processor/snap-plugin-processor-passthru/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/processor/snap-plugin-processor-passthru/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "os" 24 | 25 | "github.com/intelsdi-x/snap/control/plugin" 26 | "github.com/intelsdi-x/snap/plugin/processor/snap-plugin-processor-passthru/passthru" 27 | ) 28 | 29 | func main() { 30 | meta := passthru.Meta() 31 | plugin.Start(meta, passthru.NewPassthruProcessor(), os.Args[1]) 32 | } 33 | -------------------------------------------------------------------------------- /plugin/processor/snap-plugin-processor-passthru/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/processor/snap-plugin-processor-passthru/passthru/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/publisher/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file-grpc/README.md: -------------------------------------------------------------------------------- 1 | 19 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file-grpc/file/file_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package file 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | "time" 28 | 29 | "github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin" 30 | 31 | . "github.com/smartystreets/goconvey/convey" 32 | ) 33 | 34 | func TestFilePublish(t *testing.T) { 35 | metrics := []plugin.Metric{plugin.Metric{Namespace: plugin.NewNamespace("foo"), Timestamp: time.Now(), Data: 99, Tags: nil}} 36 | config := plugin.Config{"file": "/tmp/pub.out"} 37 | Convey("TestFilePublish", t, func() { 38 | fp := NewFilePublisher() 39 | So(fp, ShouldNotBeNil) 40 | err := fp.Publish(metrics, config) 41 | So(err, ShouldBeNil) 42 | filename, _ := config.GetString("file") 43 | _, err = os.Stat(filename) 44 | So(err, ShouldBeNil) 45 | }) 46 | } 47 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file-grpc/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "github.com/intelsdi-x/snap-plugin-lib-go/v1/plugin" 24 | "github.com/intelsdi-x/snap/plugin/publisher/snap-plugin-publisher-mock-file-grpc/file" 25 | ) 26 | 27 | const ( 28 | pluginName = "mock-file-grpc" 29 | pluginVersion = 1 30 | ) 31 | 32 | func main() { 33 | plugin.StartPublisher(file.NewFilePublisher(), pluginName, pluginVersion) 34 | } 35 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file-grpc/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file-grpc/main_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2016 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/control" 28 | "github.com/intelsdi-x/snap/core" 29 | "github.com/intelsdi-x/snap/plugin/helper" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | var ( 34 | PluginName = "snap-plugin-publisher-mock-file-grpc" 35 | PluginType = "publisher" 36 | PluginPath = helper.PluginFilePath(PluginName) 37 | ) 38 | 39 | func TestFilePublisherLoad(t *testing.T) { 40 | // These tests only work if SNAP_PATH is known. 41 | // It is the responsibility of the testing framework to 42 | // build the plugins first into the build dir. 43 | 44 | Convey("make sure plugin has been built", t, func() { 45 | err := helper.PluginFileCheck(PluginName) 46 | So(err, ShouldBeNil) 47 | 48 | Convey("ensure plugin loads and responds", func() { 49 | c := control.New(control.GetDefaultConfig()) 50 | c.Start() 51 | rp, err := core.NewRequestedPlugin(PluginPath, c.GetTempDir(), nil) 52 | Convey("Should not return an error when requested for a plugin", func() { 53 | So(err, ShouldBeNil) 54 | }) 55 | 56 | _, err = c.Load(rp) 57 | Convey("should not return an error when loading a plugin", func() { 58 | So(err, ShouldBeNil) 59 | }) 60 | }) 61 | }) 62 | } 63 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file/file/README.md: -------------------------------------------------------------------------------- 1 | 19 | #PLEASE NOTE: These are not example plugins 20 | 21 | The contents of `plugin/` are used as part of our testing framework. If you are looking for examples of how to write a plugin for Snap, review the [Plugin Authoring documentation](/docs/PLUGIN_AUTHORING.md). 22 | 23 | Curious what plugins are under development? See the `plugin-wishlist` label in [our issue backlog](https://github.com/intelsdi-x/snap/labels/plugin-wishlist). 24 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file/file/file_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package file 23 | 24 | import ( 25 | "bytes" 26 | "encoding/gob" 27 | "errors" 28 | "os" 29 | "testing" 30 | "time" 31 | 32 | "github.com/intelsdi-x/snap/control/plugin" 33 | "github.com/intelsdi-x/snap/core" 34 | "github.com/intelsdi-x/snap/core/ctypes" 35 | 36 | . "github.com/smartystreets/goconvey/convey" 37 | ) 38 | 39 | func TestFilePublish(t *testing.T) { 40 | var buf bytes.Buffer 41 | metrics := []plugin.MetricType{ 42 | *plugin.NewMetricType(core.NewNamespace("foo"), time.Now(), nil, "", 99), 43 | } 44 | config := make(map[string]ctypes.ConfigValue) 45 | enc := gob.NewEncoder(&buf) 46 | enc.Encode(metrics) 47 | 48 | Convey("TestFilePublish", t, func() { 49 | config["file"] = ctypes.ConfigValueStr{Value: "/tmp/pub.out"} 50 | fp := NewFilePublisher() 51 | So(fp, ShouldNotBeNil) 52 | err := fp.Publish("", buf.Bytes(), config) 53 | So(err, ShouldResemble, errors.New("Unknown content type ''")) 54 | err = fp.Publish(plugin.SnapGOBContentType, buf.Bytes(), config) 55 | So(err, ShouldBeNil) 56 | _, err = os.Stat(config["file"].(ctypes.ConfigValueStr).Value) 57 | So(err, ShouldBeNil) 58 | meta := Meta() 59 | So(meta, ShouldNotBeNil) 60 | }) 61 | } 62 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file/main.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package main 21 | 22 | import ( 23 | "os" 24 | 25 | "github.com/intelsdi-x/snap/control/plugin" 26 | "github.com/intelsdi-x/snap/plugin/publisher/snap-plugin-publisher-mock-file/file" 27 | ) 28 | 29 | func main() { 30 | meta := file.Meta() 31 | plugin.Start(meta, file.NewFilePublisher(), os.Args[1]) 32 | } 33 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file/main_small_test.go: -------------------------------------------------------------------------------- 1 | // +build small 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "os" 26 | "testing" 27 | 28 | . "github.com/smartystreets/goconvey/convey" 29 | ) 30 | 31 | func TestMain(t *testing.T) { 32 | Convey("ensure plugin loads and responds", t, func() { 33 | os.Args = []string{"", "{\"NoDaemon\": true}"} 34 | So(func() { main() }, ShouldNotPanic) 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /plugin/publisher/snap-plugin-publisher-mock-file/main_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package main 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/control" 28 | "github.com/intelsdi-x/snap/core" 29 | "github.com/intelsdi-x/snap/plugin/helper" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | var ( 34 | PluginName = "snap-plugin-publisher-mock-file" 35 | PluginType = "publisher" 36 | PluginPath = helper.PluginFilePath(PluginName) 37 | ) 38 | 39 | func TestFilePublisherLoad(t *testing.T) { 40 | // These tests only work if SNAP_PATH is known. 41 | // It is the responsibility of the testing framework to 42 | // build the plugins first into the build dir. 43 | 44 | Convey("make sure plugin has been built", t, func() { 45 | err := helper.PluginFileCheck(PluginName) 46 | So(err, ShouldBeNil) 47 | 48 | Convey("ensure plugin loads and responds", func() { 49 | c := control.New(control.GetDefaultConfig()) 50 | c.Start() 51 | rp, err := core.NewRequestedPlugin(PluginPath, c.GetTempDir(), nil) 52 | Convey("Should not return an error when requested for a plugin", func() { 53 | So(err, ShouldBeNil) 54 | }) 55 | 56 | _, err = c.Load(rp) 57 | Convey("should not return an error when loading a plugin", func() { 58 | So(err, ShouldBeNil) 59 | }) 60 | }) 61 | }) 62 | } 63 | -------------------------------------------------------------------------------- /scheduler/fixtures/fixtures.go: -------------------------------------------------------------------------------- 1 | // + build medium legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2017 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package fixtures 23 | 24 | import "github.com/intelsdi-x/gomit" 25 | import "github.com/intelsdi-x/snap/core/scheduler_event" 26 | 27 | type listenToSchedulerEvent struct { 28 | Ended chan struct{} 29 | UnsubscribedPluginEvents chan *scheduler_event.PluginsUnsubscribedEvent 30 | TaskStoppedEvents chan struct{} 31 | } 32 | 33 | // NewListenToSchedulerEvent 34 | func NewListenToSchedulerEvent() *listenToSchedulerEvent { 35 | return &listenToSchedulerEvent{ 36 | Ended: make(chan struct{}), 37 | UnsubscribedPluginEvents: make(chan *scheduler_event.PluginsUnsubscribedEvent), 38 | TaskStoppedEvents: make(chan struct{}), 39 | } 40 | } 41 | 42 | func (l *listenToSchedulerEvent) HandleGomitEvent(e gomit.Event) { 43 | switch msg := e.Body.(type) { 44 | case *scheduler_event.TaskEndedEvent: 45 | l.Ended <- struct{}{} 46 | case *scheduler_event.PluginsUnsubscribedEvent: 47 | l.UnsubscribedPluginEvents <- msg 48 | case *scheduler_event.TaskStoppedEvent: 49 | l.TaskStoppedEvents <- struct{}{} 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /scheduler/flags.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package scheduler 21 | 22 | import ( 23 | "fmt" 24 | 25 | "github.com/urfave/cli" 26 | ) 27 | 28 | var ( 29 | flSchedulerQueueSize = cli.StringFlag{ 30 | Name: "work-manager-queue-size", 31 | Usage: fmt.Sprintf("Size of the work manager queue (default: %v)", defaultWorkManagerQueueSize), 32 | EnvVar: "WORK_MANAGER_QUEUE_SIZE", 33 | } 34 | 35 | flSchedulerPoolSize = cli.StringFlag{ 36 | Name: "work-manager-pool-size", 37 | Usage: fmt.Sprintf("Size of the work manager pool (default: %v)", defaultWorkManagerPoolSize), 38 | EnvVar: "WORK_MANAGER_POOL_SIZE", 39 | } 40 | 41 | // Flags consumed by snapteld 42 | Flags = []cli.Flag{flSchedulerQueueSize, flSchedulerPoolSize} 43 | ) 44 | -------------------------------------------------------------------------------- /scheduler/managers.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2016 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package scheduler 21 | 22 | import ( 23 | "errors" 24 | "fmt" 25 | "sync" 26 | ) 27 | 28 | type managers struct { 29 | mutex *sync.RWMutex 30 | local managesMetrics 31 | remoteManagers map[string]managesMetrics 32 | } 33 | 34 | func newManagers(mm managesMetrics) managers { 35 | return managers{ 36 | mutex: &sync.RWMutex{}, 37 | remoteManagers: make(map[string]managesMetrics), 38 | local: mm, 39 | } 40 | } 41 | 42 | // Adds the key:value to the remoteManagers map to make them accessible 43 | // via Get() calls. 44 | func (m *managers) Add(key string, val managesMetrics) { 45 | m.mutex.Lock() 46 | if key == "" { 47 | m.local = val 48 | } else { 49 | m.remoteManagers[key] = val 50 | } 51 | m.mutex.Unlock() 52 | } 53 | 54 | // Returns the managesMetric instance that maps to given 55 | // string. If an empty string is given, will instead return 56 | // the local instance passed in on initialization. 57 | func (m *managers) Get(key string) (managesMetrics, error) { 58 | if key == "" { 59 | return m.local, nil 60 | } 61 | m.mutex.RLock() 62 | defer m.mutex.RUnlock() 63 | if val, ok := m.remoteManagers[key]; ok { 64 | return val, nil 65 | } else { 66 | return nil, errors.New(fmt.Sprintf("Client not found for: %v", key)) 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /scheduler/wmap/sample/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "collect": { 3 | "metrics": { 4 | "/foo/bar": { 5 | "version": 1 6 | }, 7 | "/foo/baz": {} 8 | }, 9 | "config": { 10 | "/foo/bar": { 11 | "password": "drowssap", 12 | "user": "root" 13 | } 14 | }, 15 | "tags": { 16 | "/foo/bar": { 17 | "tag1": "val1", 18 | "tag2": "val2" 19 | }, 20 | "/foo/baz": { 21 | "tag3": "val3" 22 | } 23 | }, 24 | "process": [ 25 | { 26 | "plugin_name": "floor", 27 | "plugin_version": 1, 28 | "process": [ 29 | { 30 | "plugin_name": "oslo", 31 | "plugin_version": 1, 32 | "process": null, 33 | "publish": null, 34 | "config": { 35 | "version": "kilo" 36 | } 37 | } 38 | ], 39 | "publish": [ 40 | { 41 | "plugin_name": "rabbitmq", 42 | "plugin_version": 5, 43 | "config": { 44 | "port": 5672, 45 | "server": "localhost" 46 | } 47 | } 48 | ], 49 | "config": { 50 | "something": true, 51 | "somethingelse": false 52 | } 53 | } 54 | ], 55 | "publish": [ 56 | { 57 | "plugin_name": "riemann", 58 | "plugin_version": 3, 59 | "config": { 60 | "port": 8080, 61 | "user": "root" 62 | } 63 | } 64 | ] 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /scheduler/wmap/sample/1.yml: -------------------------------------------------------------------------------- 1 | --- 2 | collect: 3 | metrics: 4 | /foo/bar: 5 | version: 1 6 | /foo/baz: 7 | config: 8 | /foo/bar: 9 | user: "root" 10 | password: "drowssap" 11 | tags: 12 | /foo/bar: 13 | tag1: "val1" 14 | tag2: "val2" 15 | /foo/baz: 16 | tag3: "val3" 17 | process: 18 | - 19 | plugin_name: "floor" 20 | plugin_version: 1 21 | config: 22 | something: true 23 | somethingelse: false 24 | process: 25 | - 26 | plugin_name: oslo 27 | plugin_version: 1 28 | config: 29 | version: kilo 30 | publish: 31 | - 32 | plugin_name: "rabbitmq" 33 | plugin_version: 5 34 | config: 35 | server: "localhost" 36 | port: 5672 37 | publish: 38 | - 39 | plugin_name: "riemann" 40 | plugin_version: 3 41 | config: 42 | user: "root" 43 | port: 8080 -------------------------------------------------------------------------------- /scheduler/wmap/sample/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "collect": { 3 | "metrics": { 4 | "㊽foo㊽bar": { 5 | "version": 1 6 | }, 7 | "大foo大baz": {}, 8 | "/a0/b0": {}, 9 | "-a1-b1": {}, 10 | "_a2_b2": {}, 11 | "㊽a3㊽b3": {}, 12 | "Äa4Äb4": {}, 13 | "大a5大b5": {}, 14 | "小a6小b6": {}, 15 | "ᵹa7ᵹb7": {}, 16 | "☍a8☍b8": {}, 17 | "ヒa9ヒb9": {} 18 | }, 19 | "config": { 20 | "%foo%bar": { 21 | "password": "drowssap", 22 | "user": "root" 23 | } 24 | }, 25 | "tags": { 26 | "㊽foo㊽bar": { 27 | "tag1": "val1", 28 | "tag2": "val2" 29 | }, 30 | "大foo大baz": { 31 | "tag3": "val3" 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /scheduler/wmap/sample/rest-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "collect": { 3 | "metrics": { 4 | "/intel/mock/foo": { 5 | "version": 1 6 | }, 7 | "/intel/mock/bar": {} 8 | }, 9 | "config": { 10 | "/intel/mock": { 11 | "password": "secret", 12 | "user": "root" 13 | } 14 | }, 15 | "process": [ 16 | { 17 | "plugin_name": "passthru", 18 | "plugin_version": 1, 19 | "process": null, 20 | "publish": [ 21 | { 22 | "plugin_name": "file", 23 | "plugin_version": 1, 24 | "config": { 25 | "file": "/tmp/pub.out" 26 | } 27 | } 28 | ], 29 | "config": null 30 | } 31 | ], 32 | "publish": null 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /scheduler/worker.go: -------------------------------------------------------------------------------- 1 | /* 2 | http://www.apache.org/licenses/LICENSE-2.0.txt 3 | 4 | 5 | Copyright 2015 Intel Corporation 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package scheduler 21 | 22 | import ( 23 | "errors" 24 | 25 | "github.com/intelsdi-x/snap/pkg/chrono" 26 | "github.com/pborman/uuid" 27 | ) 28 | 29 | var workerKillChan = make(chan struct{}) 30 | 31 | type worker struct { 32 | id string 33 | rcv <-chan queuedJob 34 | kamikaze chan struct{} 35 | } 36 | 37 | func newWorker(rChan <-chan queuedJob) *worker { 38 | return &worker{ 39 | rcv: rChan, 40 | id: uuid.New(), 41 | kamikaze: make(chan struct{}), 42 | } 43 | } 44 | 45 | // begin a worker 46 | func (w *worker) start() { 47 | for { 48 | select { 49 | case q := <-w.rcv: 50 | // assert that deadline is not exceeded 51 | if chrono.Chrono.Now().Before(q.Job().Deadline()) { 52 | q.Job().Run() 53 | } else { 54 | // the deadline was exceeded and this job will not run 55 | q.Job().AddErrors(errors.New("Worker refused to run overdue job.")) 56 | } 57 | 58 | // mark the job complete 59 | q.Promise().Complete(q.Job().Errors()) 60 | 61 | // the single kill-channel -- used when resizing worker pools 62 | case <-w.kamikaze: 63 | return 64 | 65 | //the broadcast that kills all workers 66 | case <-workerKillChan: 67 | return 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /scheduler/worker_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package scheduler 23 | 24 | import ( 25 | "testing" 26 | "time" 27 | 28 | "github.com/intelsdi-x/snap/pkg/chrono" 29 | log "github.com/sirupsen/logrus" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | func TestWorker(t *testing.T) { 34 | log.SetLevel(log.FatalLevel) 35 | Convey("runs a job sent to the worker", t, func() { 36 | workerKillChan = make(chan struct{}) 37 | rcv := make(chan queuedJob) 38 | w := newWorker(rcv) 39 | go w.start() 40 | mj := newMockJob() 41 | rcv <- newQueuedJob(mj) 42 | mj.Await() 43 | So(mj.worked, ShouldEqual, true) 44 | }) 45 | Convey("replies without running job if deadline is exceeded", t, func() { 46 | // Make sure global clock is restored after test. 47 | defer chrono.Chrono.Reset() 48 | defer chrono.Chrono.Continue() 49 | 50 | // Use artificial time: pause to get base time. 51 | chrono.Chrono.Pause() 52 | 53 | workerKillChan = make(chan struct{}) 54 | rcv := make(chan queuedJob) 55 | w := newWorker(rcv) 56 | go w.start() 57 | mj := newMockJob() 58 | // Time travel 1.5 seconds. 59 | chrono.Chrono.Forward(1500 * time.Millisecond) 60 | qj := newQueuedJob(mj) 61 | rcv <- qj 62 | errors := qj.Promise().Await() 63 | So(errors, ShouldNotBeEmpty) 64 | So(mj.worked, ShouldBeFalse) 65 | }) 66 | Convey("stops the worker if kamikaze chan is closed", t, func() { 67 | workerKillChan = make(chan struct{}) 68 | rcv := make(chan queuedJob) 69 | w := newWorker(rcv) 70 | go func() { close(w.kamikaze) }() 71 | w.start() 72 | So(0, ShouldEqual, 0) 73 | }) 74 | } 75 | -------------------------------------------------------------------------------- /scheduler/workflow_string_test.go: -------------------------------------------------------------------------------- 1 | // +build legacy 2 | 3 | /* 4 | http://www.apache.org/licenses/LICENSE-2.0.txt 5 | 6 | 7 | Copyright 2015 Intel Corporation 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | */ 21 | 22 | package scheduler 23 | 24 | import ( 25 | "testing" 26 | 27 | "github.com/intelsdi-x/snap/scheduler/wmap" 28 | 29 | log "github.com/sirupsen/logrus" 30 | . "github.com/smartystreets/goconvey/convey" 31 | ) 32 | 33 | func TestWorkflowString(t *testing.T) { 34 | log.SetLevel(log.FatalLevel) 35 | Convey("String", t, func() { 36 | w := wmap.NewWorkflowMap() 37 | w.Collect.AddMetric("fall", 1) 38 | pr1 := wmap.NewProcessNode("winter", 1) 39 | pr2 := wmap.NewProcessNode("summer", 1) 40 | pu1 := wmap.NewPublishNode("spring", 1) 41 | pu2 := wmap.NewPublishNode("autumn", 1) 42 | w.Collect.AddConfigItem("/foo/bar", "user", "rain") 43 | pr1.AddConfigItem("leaves", 1) 44 | pr2.AddConfigItem("flowers", 2) 45 | pu2.AddConfigItem("grass", 3) 46 | w.Collect.Add(pr1) 47 | w.Collect.Add(pu1) 48 | w.Collect.Process[0].Add(pr2) 49 | w.Collect.Process[0].Add(pu2) 50 | 51 | wf, err := wmapToWorkflow(w) 52 | So(err, ShouldBeNil) 53 | str := wf.String() 54 | //fmt.Printf("%v", str) 55 | So(str, ShouldNotBeEmpty) 56 | str2 := wf.processNodes[0].String("") 57 | So(str2, ShouldNotBeEmpty) 58 | metricString("", wf.metrics) 59 | }) 60 | } 61 | -------------------------------------------------------------------------------- /scripts/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:latest 2 | 3 | ENV GOPATH=$GOPATH:/go 4 | COPY ./ /go/src/github.com/intelsdi-x/snap 5 | RUN apt-get update \ 6 | && rm -rf /var/lib/apt/lists/* \ 7 | && git clone https://github.com/intelsdi-x/gomit.git /go/src/github.com/intelsdi-x/gomit \ 8 | && /go/src/github.com/intelsdi-x/snap/scripts/deps.sh \ 9 | && make -C /go/src/github.com/intelsdi-x/snap 10 | WORKDIR /go/src/github.com/intelsdi-x/snap 11 | 12 | -------------------------------------------------------------------------------- /scripts/build_all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -e 4 | set -u 5 | set -o pipefail 6 | 7 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 8 | 9 | # shellcheck source=scripts/common.sh 10 | . "${__dir}/common.sh" 11 | 12 | export GOOS=linux 13 | export GOARCH=amd64 14 | "${__dir}/build_snap.sh" & 15 | "${__dir}/build_plugins.sh" & 16 | 17 | export GOOS=darwin 18 | export GOARCH=amd64 19 | "${__dir}/build_snap.sh" & 20 | "${__dir}/build_plugins.sh" & 21 | 22 | export GOOS=windows 23 | export GOARCH=amd64 24 | "${__dir}/build_snap.sh" & 25 | "${__dir}/build_plugins.sh" & 26 | 27 | export GOOS=windows 28 | export GOARCH=386 29 | "${__dir}/build_snap.sh" & 30 | "${__dir}/build_plugins.sh" & 31 | 32 | wait 33 | -------------------------------------------------------------------------------- /scripts/build_plugin.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #http://www.apache.org/licenses/LICENSE-2.0.txt 4 | # 5 | # 6 | #Copyright 2015 Intel Corporation 7 | # 8 | #Licensed under the Apache License, Version 2.0 (the "License"); 9 | #you may not use this file except in compliance with the License. 10 | #You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | #Unless required by applicable law or agreed to in writing, software 15 | #distributed under the License is distributed on an "AS IS" BASIS, 16 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | #See the License for the specific language governing permissions and 18 | #limitations under the License. 19 | 20 | set -e 21 | set -u 22 | set -o pipefail 23 | 24 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 25 | __proj_dir="$(dirname "$__dir")" 26 | 27 | # shellcheck source=scripts/common.sh 28 | . "${__dir}/common.sh" 29 | 30 | if [[ "${GOARCH}" == "amd64" ]]; then 31 | build_dir="${__proj_dir}/build/${GOOS}/x86_64/plugins" 32 | else 33 | build_dir="${__proj_dir}/build/${GOOS}/${GOARCH}/plugins" 34 | fi 35 | 36 | plugin_src_path=$1 37 | plugin_name=$(basename "${plugin_src_path}") 38 | if [[ "${GOOS}" == "windows" ]]; then 39 | plugin_name="${plugin_name}.exe" 40 | fi 41 | go_build=(go build -a -ldflags "-w") 42 | 43 | _debug "plugin source: ${plugin_src_path}" 44 | _info "building ${plugin_name} for ${GOOS}/${GOARCH}" 45 | 46 | (cd "${plugin_src_path}" && "${go_build[@]}" -o "${build_dir}/${plugin_name}" . || exit 1) 47 | -------------------------------------------------------------------------------- /scripts/build_snap.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #http://www.apache.org/licenses/LICENSE-2.0.txt 4 | # 5 | # 6 | #Copyright 2015 Intel Corporation 7 | # 8 | #Licensed under the Apache License, Version 2.0 (the "License"); 9 | #you may not use this file except in compliance with the License. 10 | #You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | #Unless required by applicable law or agreed to in writing, software 15 | #distributed under the License is distributed on an "AS IS" BASIS, 16 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | #See the License for the specific language governing permissions and 18 | #limitations under the License. 19 | 20 | set -e 21 | set -u 22 | set -o pipefail 23 | 24 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 25 | __proj_dir="$(dirname "$__dir")" 26 | 27 | # shellcheck source=scripts/common.sh 28 | . "${__dir}/common.sh" 29 | 30 | _info "project path: ${__proj_dir}" 31 | 32 | git_version=$(_git_version) 33 | go_build=(go build -ldflags "-w -X main.gitversion=${git_version}") 34 | 35 | _info "snap build version: ${git_version}" 36 | _info "git commit: $(git log --pretty=format:"%H" -1)" 37 | 38 | # rebuild binaries: 39 | export GOOS=${GOOS:-$(go env GOOS)} 40 | export GOARCH=${GOARCH:-$(go env GOARCH)} 41 | 42 | # Disable CGO for builds (except freebsd) 43 | if [[ "${GOOS}" == "freebsd" ]]; then 44 | _info "CGO enabled for freebsd" 45 | export CGO_ENABLED=1 46 | else 47 | export CGO_ENABLED=0 48 | fi 49 | 50 | if [[ "${GOARCH}" == "amd64" ]]; then 51 | build_path="${__proj_dir}/build/${GOOS}/x86_64" 52 | else 53 | build_path="${__proj_dir}/build/${GOOS}/${GOARCH}" 54 | fi 55 | 56 | snaptel="snaptel" 57 | snapteld="snapteld" 58 | if [[ "${GOOS}" == "windows" ]]; then 59 | snaptel="${snaptel}.exe" 60 | snapteld="${snapteld}.exe" 61 | fi 62 | 63 | mkdir -p "${build_path}" 64 | _info "building snapteld/${snaptel} for ${GOOS}/${GOARCH}" 65 | "${go_build[@]}" -o "${build_path}/${snapteld}" . || exit 1 66 | (cd "${__proj_dir}/cmd/snaptel" && "${go_build[@]}" -o "${build_path}/${snaptel}" . || exit 1) 67 | -------------------------------------------------------------------------------- /scripts/deps.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #http://www.apache.org/licenses/LICENSE-2.0.txt 4 | # 5 | # 6 | #Copyright 2016 Intel Corporation 7 | # 8 | #Licensed under the Apache License, Version 2.0 (the "License"); 9 | #you may not use this file except in compliance with the License. 10 | #You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | #Unless required by applicable law or agreed to in writing, software 15 | #distributed under the License is distributed on an "AS IS" BASIS, 16 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | #See the License for the specific language governing permissions and 18 | #limitations under the License. 19 | 20 | set -e 21 | set -u 22 | set -o pipefail 23 | 24 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 25 | __proj_dir="$(dirname "$__dir")" 26 | 27 | # shellcheck source=scripts/common.sh 28 | . "${__dir}/common.sh" 29 | 30 | _go_path 31 | 32 | _info "Installing Swagger..." 33 | _go_get github.com/go-swagger/go-swagger/cmd/swagger 34 | _info "Installing Glide..." 35 | _go_get github.com/Masterminds/glide 36 | 37 | _debug "$(glide --version)" 38 | _info "restoring dependency with glide" 39 | (cd "${__proj_dir}" && glide install) 40 | -------------------------------------------------------------------------------- /scripts/gitcookie.sh: -------------------------------------------------------------------------------- 1 | touch ~/.gitcookies 2 | chmod 0600 ~/.gitcookies 3 | 4 | git config --global http.cookiefile ~/.gitcookies 5 | 6 | tr , \\t <<\__END__ >>~/.gitcookies 7 | go.googlesource.com,FALSE,/,TRUE,2147483647,o,git-snappytheturtle1202.gmail.com=1/4zg9qf0zy1bmnMpEnqT7IL-rcL5_y8XP7bpfYE5DzN0 8 | go-review.googlesource.com,FALSE,/,TRUE,2147483647,o,git-snappytheturtle1202.gmail.com=1/4zg9qf0zy1bmnMpEnqT7IL-rcL5_y8XP7bpfYE5DzN0 9 | __END__ 10 | -------------------------------------------------------------------------------- /scripts/pre_deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # File managed by pluginsync 3 | 4 | # http://www.apache.org/licenses/LICENSE-2.0.txt 5 | # 6 | # 7 | # Copyright 2016 Intel Corporation 8 | # 9 | # Licensed under the Apache License, Version 2.0 (the "License"); 10 | # you may not use this file except in compliance with the License. 11 | # You may obtain a copy of the License at 12 | # 13 | # http://www.apache.org/licenses/LICENSE-2.0 14 | # 15 | # Unless required by applicable law or agreed to in writing, software 16 | # distributed under the License is distributed on an "AS IS" BASIS, 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | # See the License for the specific language governing permissions and 19 | # limitations under the License. 20 | 21 | set -e 22 | set -u 23 | set -o pipefail 24 | 25 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 26 | __proj_dir="$(dirname "$__dir")" 27 | 28 | # shellcheck source=scripts/common.sh 29 | . "${__dir}/common.sh" 30 | 31 | build_path="${__proj_dir}/build" 32 | _info "build_path: ${build_path}" 33 | _debug "$(find "${build_path}")" 34 | 35 | plugin_name="${__proj_dir##*/}" 36 | git_sha=$(git log --pretty=format:"%H" -1) 37 | s3_path="${__proj_dir}/s3/${plugin_name}" 38 | 39 | set +u 40 | if [ -z "$TRAVIS_TAG" ]; then 41 | set -u 42 | git_path="${s3_path}/${git_sha}" 43 | latest_path="${s3_path}/latest_build" 44 | mkdir -p "${git_path}" 45 | mkdir -p "${latest_path}" 46 | 47 | _info "copying plugin binaries to ${git_path}" 48 | cp -rp "${build_path}/"* "${git_path}" 49 | _info "copying plugin binaries to ${latest_path}" 50 | cp -rp "${build_path}/"* "${latest_path}" 51 | 52 | find "${s3_path}" -type d -name 'plugins' -exec sh -c 'mv $1/* $1/..' _ {} \; -delete 53 | else 54 | set -u 55 | tag_path="${s3_path}/${TRAVIS_TAG}" 56 | latest_path="${s3_path}/latest" 57 | mkdir -p "${tag_path}" 58 | mkdir -p "${latest_path}" 59 | 60 | _info "copying plugin binaries to ${tag_path}" 61 | cp -rp "${build_path}/"* "${tag_path}" 62 | _info "copying plugin binaries to ${latest_path}" 63 | cp -rp "${build_path}/"* "${latest_path}" 64 | 65 | find "${s3_path}" -type d -name 'plugins' -exec sh -c 'mv $1/* $1/..' _ {} \; -delete 66 | fi 67 | 68 | _debug "$(find "${build_path}")" 69 | _debug "$(find "${s3_path}")" 70 | -------------------------------------------------------------------------------- /scripts/run_tests_with_docker.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #http://www.apache.org/licenses/LICENSE-2.0.txt 4 | # 5 | # 6 | #Copyright 2015 Intel Corporation 7 | # 8 | #Licensed under the Apache License, Version 2.0 (the "License"); 9 | #you may not use this file except in compliance with the License. 10 | #You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | #Unless required by applicable law or agreed to in writing, software 15 | #distributed under the License is distributed on an "AS IS" BASIS, 16 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | #See the License for the specific language governing permissions and 18 | #limitations under the License. 19 | 20 | SNAP_TEST_TYPE="${SNAP_TEST_TYPE:-$1}" 21 | 22 | UNIT_TEST="${UNIT_TEST:-"gofmt goimports go_test go_cover"}" 23 | 24 | set -e 25 | set -u 26 | set -o pipefail 27 | 28 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 29 | __proj_dir="$(dirname "$__dir")" 30 | 31 | # shellcheck source=scripts/common.sh 32 | . "${__dir}/common.sh" 33 | 34 | _debug "script directory ${__dir}" 35 | _debug "project directory ${__proj_dir}" 36 | 37 | [[ "$SNAP_TEST_TYPE" =~ ^(small|medium|large|legacy)$ ]] || _error "invalid TEST_TYPE (value must be 'small', 'medium', 'large', or 'legacy', received:${SNAP_TEST_TYPE}" 38 | 39 | (cd ${__proj_dir} && docker build -t intelsdi-x/snap-test -f "${__dir}/Dockerfile" .) 40 | docker run -it intelsdi-x/snap-test scripts/test.sh "${SNAP_TEST_TYPE}" 41 | -------------------------------------------------------------------------------- /scripts/swagger.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | #http://www.apache.org/licenses/LICENSE-2.0.txt 4 | # 5 | # 6 | #Copyright 2017 Intel Corporation 7 | # 8 | #Licensed under the Apache License, Version 2.0 (the "License"); 9 | #you may not use this file except in compliance with the License. 10 | #You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | #Unless required by applicable law or agreed to in writing, software 15 | #distributed under the License is distributed on an "AS IS" BASIS, 16 | #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | #See the License for the specific language governing permissions and 18 | #limitations under the License. 19 | 20 | __dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" 21 | . "${__dir}/common.sh" 22 | 23 | if ! type swagger 2> /dev/null; then 24 | _error "No Swagger found. Your API specification might be out-of-date. Please run 'make deps' to install all dependencies. For more info, see https://github.com/intelsdi-x/snap#system-requirements" 25 | fi 26 | 27 | _info "Updating API specification file..." 28 | swagger generate spec -o ${__dir}/../swagger.json 29 | _info "Validating API specification file..." 30 | swagger validate ${__dir}/../swagger.json 31 | -------------------------------------------------------------------------------- /third_party_licenses/README.md: -------------------------------------------------------------------------------- 1 | # Third Party Licenses 2 | 3 | This directory contains licenses of 3rd party components which are used in [Snap](https://github.com/intelsdi-x/snap). 4 | 5 | Below is the list of 3rd party components grouped by licenses. 6 | 7 | ## Components under Apache 2.0 license 8 | 9 | - [App Container](https://github.com/appc/spec) 10 | - [gojsonschema](https://github.com/xeipuuv/gojsonschema) 11 | - [gRPC-Go](https://github.com/grpc/grpc-go) 12 | - [yaml.v2](https://github.com/go-yaml/yaml) (not all files, for details please see [license](yaml_v2_license.txt)) 13 | 14 | ## Components under BSD 3-clause license 15 | 16 | - [Go Cryptography libraries](https://github.com/golang/crypto) 17 | - [Go networking libraries](https://github.com/golang/net) 18 | - [HttpRouter](https://github.com/julienschmidt/httprouter) 19 | - [go-msgpack](https://github.com/hashicorp/go-msgpack) 20 | - [protobuf](https://github.com/golang/protobuf) 21 | - [uuid](https://github.com/pborman/uuid) 22 | 23 | ## Components under MIT license 24 | 25 | - [cli](https://github.com/urfave/cli) 26 | - [cron](https://github.com/robfig/cron) 27 | - [govalidator](https://github.com/asaskevich/govalidator) 28 | - [jsonutil](https://github.com/vrischmann/jsonutil) 29 | - [Logrus](https://github.com/sirupsen/logrus) 30 | - [Negroni](https://github.com/urfave/negroni) 31 | - [YAML](https://github.com/ghodss/yaml) (not all files, for details please see [license](yaml_license.txt)) 32 | 33 | ## Components under Mozilla Public License 2.0 34 | 35 | - [memberlist](https://github.com/hashicorp/memberlist) -------------------------------------------------------------------------------- /third_party_licenses/cli_license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Jeremy Saenz & Contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /third_party_licenses/cron_license.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 Rob Figueiredo 2 | All Rights Reserved. 3 | 4 | MIT LICENSE 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 10 | the Software, and to permit persons to whom the Software is furnished to do so, 11 | subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 18 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 19 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 20 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /third_party_licenses/go_cryptography_license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /third_party_licenses/go_msgpack_license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, 2013 Ugorji Nwoke. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | * Neither the name of the author nor the names of its contributors may be used 13 | to endorse or promote products derived from this software 14 | without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 23 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /third_party_licenses/go_networking_licenses.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /third_party_licenses/govalidator_license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Alex Saskevich 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /third_party_licenses/httprouter_license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Julien Schmidt. All rights reserved. 2 | 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * The names of the contributors may not be used to endorse or promote 12 | products derived from this software without specific prior written 13 | permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL JULIEN SCHMIDT BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /third_party_licenses/jsonutil_license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Vincent Rischmann 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /third_party_licenses/logrus_license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Simon Eskildsen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /third_party_licenses/negroni_license.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jeremy Saenz 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /third_party_licenses/protobuf_license.txt: -------------------------------------------------------------------------------- 1 | Go support for Protocol Buffers - Google's data interchange format 2 | 3 | Copyright 2010 The Go Authors. All rights reserved. 4 | https://github.com/golang/protobuf 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are 8 | met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following disclaimer 14 | in the documentation and/or other materials provided with the 15 | distribution. 16 | * Neither the name of Google Inc. nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | -------------------------------------------------------------------------------- /third_party_licenses/uuid_license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009,2014 Google Inc. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --------------------------------------------------------------------------------