{"action":"created","comment":{"url":"https://api.github.com/repos/monasca/monasca-watchers/pulls/comments/157672345","pull_request_review_id":84351708,"id":157672345,"diff_hunk":"@@ -0,0 +1,205 @@\n+// Copyright 2017 Hewlett Packard Enterprise Development LP\n+//\n+//    Licensed under the Apache License, Version 2.0 (the \"License\"); you may\n+//    not use this file except in compliance with the License. You may obtain\n+//    a copy of the License at\n+//\n+//         http://www.apache.org/licenses/LICENSE-2.0\n+//\n+//    Unless required by applicable law or agreed to in writing, software\n+//    distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n+//    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n+//    License for the specific language governing permissions and limitations\n+//    under the License.\n+\n+package main\n+\n+import (\n+\t\"encoding/json\"\n+\t\"fmt\"\n+\t\"net/http\"\n+\t\"os\"\n+\t\"os/signal\"\n+\t\"sync\"\n+\t\"syscall\"\n+\t\"time\"\n+\n+\tconfigEnv \"github.com/caarlos0/env\"\n+\t\"github.com/influxdata/influxdb/client/v2\"\n+\t\"github.com/monasca/monasca-watchers/watcher\"\n+\t\"github.com/prometheus/client_golang/prometheus/promhttp\"\n+\tlog \"github.com/sirupsen/logrus\"\n+)\n+\n+type watcherConfiguration struct {\n+\tInfluxdbAddress    string `env:\"INFLUXDB_ADDRESS\" envDefault:\"http://influxdb:8086\"`\n+\tUsername           string `env:\"INFLUXDB_USERNAME\" envDefault:\"influxdb_watcher\"`\n+\tPassword           string `env:\"INFLUXDB_PASSWORD\" envDefault:\"password\"`\n+\tPrometheusEndpoint string `env:\"PROMETHEUS_ENDPOINT\" envDefault:\"0.0.0.0:8080\"`\n+\tPeriod             int64  `env:\"WATCHER_PERIOD\" envDefault:\"600\"`\n+\tTimeout            int64  `env:\"WATCHER_TIMEOUT\" envDefault:\"60\"`\n+}\n+\n+// InfluxdbBroker Watcher for InfluxDB\n+type InfluxdbBroker struct {\n+\tMonascaDB  string\n+\tConnection client.Client\n+}\n+\n+// Message the values Watcher is expecting to send and receive\n+type Message struct {\n+\tUUID     string\n+\tSentTime string\n+}\n+\n+// WriteMessage Write a point to Influxdb with UUID and SentTime\n+func (broker *InfluxdbBroker) WriteMessage(byteMessage []byte) error {\n+\tvar message Message\n+\terr := json.Unmarshal(byteMessage, &message)\n+\tif err != nil {\n+\t\tlog.Error(err)\n+\t\treturn err\n+\t}\n+\n+\t// Create a new point batch\n+\tbp, err := client.NewBatchPoints(client.BatchPointsConfig{\n+\t\tDatabase:  broker.MonascaDB,\n+\t\tPrecision: \"s\",\n+\t})\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t\treturn err\n+\t}\n+\n+\t// Create a point and add to batch\n+\ttags := map[string]string{\"watcher\": \"influxdb\"}\n+\tfields := map[string]interface{}{\n+\t\t\"uuid\":      message.UUID,\n+\t\t\"startTime\": message.SentTime,\n+\t}\n+\n+\tpt, err := client.NewPoint(\"watcher.influxdb\", tags, fields, time.Now())\n+\tif err != nil {\n+\t\tlog.Fatal(err)\n+\t\treturn err\n+\t}\n+\n+\tbp.AddPoint(pt)\n+\n+\t// Write the batch\n+\tif err := broker.Connection.Write(bp); err != nil {\n+\t\tlog.Fatal(err)\n+\t\treturn err\n+\t}\n+\treturn nil\n+}\n+\n+// ReadMessage query InfluxDB for latest measurement\n+func (broker *InfluxdbBroker) ReadMessage(timeout time.Duration) (*[]byte, error) {\n+\tcmd := fmt.Sprintf(\"SELECT last(startTime), last(uuid) FROM \\\"%s\\\"\", \"watcher.influxdb\")\n+\tres, err := queryDB(broker, cmd)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tmessage := Message{\n+\t\tUUID:     res[0].Series[0].Values[0][2].(string),\n+\t\tSentTime: res[0].Series[0].Values[0][1].(string),\n+\t}\n+\tbytes, err := json.Marshal(message)\n+\tif err != nil {\n+\t\tpanic(\"json encoding failed\")","path":"main/influxdb_watcher.go","position":111,"original_position":111,"commit_id":"39918ffee4cb3c73b455b97974164707db2bfe50","original_commit_id":"39918ffee4cb3c73b455b97974164707db2bfe50","user":{"login":"craigbr","id":7059727,"avatar_url":"https://avatars1.githubusercontent.com/u/7059727?v=4","gravatar_id":"","url":"https://api.github.com/users/craigbr","html_url":"https://github.com/craigbr","followers_url":"https://api.github.com/users/craigbr/followers","following_url":"https://api.github.com/users/craigbr/following{/other_user}","gists_url":"https://api.github.com/users/craigbr/gists{/gist_id}","starred_url":"https://api.github.com/users/craigbr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/craigbr/subscriptions","organizations_url":"https://api.github.com/users/craigbr/orgs","repos_url":"https://api.github.com/users/craigbr/repos","events_url":"https://api.github.com/users/craigbr/events{/privacy}","received_events_url":"https://api.github.com/users/craigbr/received_events","type":"User","site_admin":false},"body":"This will also kill the watcher. You should instead return the err","created_at":"2017-12-19T06:23:10Z","updated_at":"2017-12-19T06:31:33Z","html_url":"https://github.com/monasca/monasca-watchers/pull/8#discussion_r157672345","pull_request_url":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/monasca/monasca-watchers/pulls/comments/157672345"},"html":{"href":"https://github.com/monasca/monasca-watchers/pull/8#discussion_r157672345"},"pull_request":{"href":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8","id":158481272,"html_url":"https://github.com/monasca/monasca-watchers/pull/8","diff_url":"https://github.com/monasca/monasca-watchers/pull/8.diff","patch_url":"https://github.com/monasca/monasca-watchers/pull/8.patch","issue_url":"https://api.github.com/repos/monasca/monasca-watchers/issues/8","number":8,"state":"open","locked":false,"title":"Add Influx Watcher","user":{"login":"aadams19","id":19737016,"avatar_url":"https://avatars2.githubusercontent.com/u/19737016?v=4","gravatar_id":"","url":"https://api.github.com/users/aadams19","html_url":"https://github.com/aadams19","followers_url":"https://api.github.com/users/aadams19/followers","following_url":"https://api.github.com/users/aadams19/following{/other_user}","gists_url":"https://api.github.com/users/aadams19/gists{/gist_id}","starred_url":"https://api.github.com/users/aadams19/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aadams19/subscriptions","organizations_url":"https://api.github.com/users/aadams19/orgs","repos_url":"https://api.github.com/users/aadams19/repos","events_url":"https://api.github.com/users/aadams19/events{/privacy}","received_events_url":"https://api.github.com/users/aadams19/received_events","type":"User","site_admin":false},"body":"https://github.com/monasca/monasca-docker/pull/375","created_at":"2017-12-14T22:40:19Z","updated_at":"2017-12-19T06:31:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8783da19ebddbaf2dd342348c497631e9d5c474b","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8/commits","review_comments_url":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8/comments","review_comment_url":"https://api.github.com/repos/monasca/monasca-watchers/pulls/comments{/number}","comments_url":"https://api.github.com/repos/monasca/monasca-watchers/issues/8/comments","statuses_url":"https://api.github.com/repos/monasca/monasca-watchers/statuses/39918ffee4cb3c73b455b97974164707db2bfe50","head":{"label":"aadams19:feature/influx_watcher","ref":"feature/influx_watcher","sha":"39918ffee4cb3c73b455b97974164707db2bfe50","user":{"login":"aadams19","id":19737016,"avatar_url":"https://avatars2.githubusercontent.com/u/19737016?v=4","gravatar_id":"","url":"https://api.github.com/users/aadams19","html_url":"https://github.com/aadams19","followers_url":"https://api.github.com/users/aadams19/followers","following_url":"https://api.github.com/users/aadams19/following{/other_user}","gists_url":"https://api.github.com/users/aadams19/gists{/gist_id}","starred_url":"https://api.github.com/users/aadams19/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aadams19/subscriptions","organizations_url":"https://api.github.com/users/aadams19/orgs","repos_url":"https://api.github.com/users/aadams19/repos","events_url":"https://api.github.com/users/aadams19/events{/privacy}","received_events_url":"https://api.github.com/users/aadams19/received_events","type":"User","site_admin":false},"repo":{"id":113246761,"name":"monasca-watchers","full_name":"aadams19/monasca-watchers","owner":{"login":"aadams19","id":19737016,"avatar_url":"https://avatars2.githubusercontent.com/u/19737016?v=4","gravatar_id":"","url":"https://api.github.com/users/aadams19","html_url":"https://github.com/aadams19","followers_url":"https://api.github.com/users/aadams19/followers","following_url":"https://api.github.com/users/aadams19/following{/other_user}","gists_url":"https://api.github.com/users/aadams19/gists{/gist_id}","starred_url":"https://api.github.com/users/aadams19/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aadams19/subscriptions","organizations_url":"https://api.github.com/users/aadams19/orgs","repos_url":"https://api.github.com/users/aadams19/repos","events_url":"https://api.github.com/users/aadams19/events{/privacy}","received_events_url":"https://api.github.com/users/aadams19/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/aadams19/monasca-watchers","description":"Watchers to check health of Monasca components","fork":true,"url":"https://api.github.com/repos/aadams19/monasca-watchers","forks_url":"https://api.github.com/repos/aadams19/monasca-watchers/forks","keys_url":"https://api.github.com/repos/aadams19/monasca-watchers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/aadams19/monasca-watchers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/aadams19/monasca-watchers/teams","hooks_url":"https://api.github.com/repos/aadams19/monasca-watchers/hooks","issue_events_url":"https://api.github.com/repos/aadams19/monasca-watchers/issues/events{/number}","events_url":"https://api.github.com/repos/aadams19/monasca-watchers/events","assignees_url":"https://api.github.com/repos/aadams19/monasca-watchers/assignees{/user}","branches_url":"https://api.github.com/repos/aadams19/monasca-watchers/branches{/branch}","tags_url":"https://api.github.com/repos/aadams19/monasca-watchers/tags","blobs_url":"https://api.github.com/repos/aadams19/monasca-watchers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/aadams19/monasca-watchers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/aadams19/monasca-watchers/git/refs{/sha}","trees_url":"https://api.github.com/repos/aadams19/monasca-watchers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/aadams19/monasca-watchers/statuses/{sha}","languages_url":"https://api.github.com/repos/aadams19/monasca-watchers/languages","stargazers_url":"https://api.github.com/repos/aadams19/monasca-watchers/stargazers","contributors_url":"https://api.github.com/repos/aadams19/monasca-watchers/contributors","subscribers_url":"https://api.github.com/repos/aadams19/monasca-watchers/subscribers","subscription_url":"https://api.github.com/repos/aadams19/monasca-watchers/subscription","commits_url":"https://api.github.com/repos/aadams19/monasca-watchers/commits{/sha}","git_commits_url":"https://api.github.com/repos/aadams19/monasca-watchers/git/commits{/sha}","comments_url":"https://api.github.com/repos/aadams19/monasca-watchers/comments{/number}","issue_comment_url":"https://api.github.com/repos/aadams19/monasca-watchers/issues/comments{/number}","contents_url":"https://api.github.com/repos/aadams19/monasca-watchers/contents/{+path}","compare_url":"https://api.github.com/repos/aadams19/monasca-watchers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/aadams19/monasca-watchers/merges","archive_url":"https://api.github.com/repos/aadams19/monasca-watchers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/aadams19/monasca-watchers/downloads","issues_url":"https://api.github.com/repos/aadams19/monasca-watchers/issues{/number}","pulls_url":"https://api.github.com/repos/aadams19/monasca-watchers/pulls{/number}","milestones_url":"https://api.github.com/repos/aadams19/monasca-watchers/milestones{/number}","notifications_url":"https://api.github.com/repos/aadams19/monasca-watchers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/aadams19/monasca-watchers/labels{/name}","releases_url":"https://api.github.com/repos/aadams19/monasca-watchers/releases{/id}","deployments_url":"https://api.github.com/repos/aadams19/monasca-watchers/deployments","created_at":"2017-12-06T00:03:10Z","updated_at":"2017-12-06T00:03:11Z","pushed_at":"2017-12-18T21:52:13Z","git_url":"git://github.com/aadams19/monasca-watchers.git","ssh_url":"git@github.com:aadams19/monasca-watchers.git","clone_url":"https://github.com/aadams19/monasca-watchers.git","svn_url":"https://github.com/aadams19/monasca-watchers","homepage":null,"size":41,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"monasca:master","ref":"master","sha":"50f49554af1c203d881dd127b5ea0067a16b930d","user":{"login":"monasca","id":13634047,"avatar_url":"https://avatars0.githubusercontent.com/u/13634047?v=4","gravatar_id":"","url":"https://api.github.com/users/monasca","html_url":"https://github.com/monasca","followers_url":"https://api.github.com/users/monasca/followers","following_url":"https://api.github.com/users/monasca/following{/other_user}","gists_url":"https://api.github.com/users/monasca/gists{/gist_id}","starred_url":"https://api.github.com/users/monasca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monasca/subscriptions","organizations_url":"https://api.github.com/users/monasca/orgs","repos_url":"https://api.github.com/users/monasca/repos","events_url":"https://api.github.com/users/monasca/events{/privacy}","received_events_url":"https://api.github.com/users/monasca/received_events","type":"Organization","site_admin":false},"repo":{"id":110720767,"name":"monasca-watchers","full_name":"monasca/monasca-watchers","owner":{"login":"monasca","id":13634047,"avatar_url":"https://avatars0.githubusercontent.com/u/13634047?v=4","gravatar_id":"","url":"https://api.github.com/users/monasca","html_url":"https://github.com/monasca","followers_url":"https://api.github.com/users/monasca/followers","following_url":"https://api.github.com/users/monasca/following{/other_user}","gists_url":"https://api.github.com/users/monasca/gists{/gist_id}","starred_url":"https://api.github.com/users/monasca/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/monasca/subscriptions","organizations_url":"https://api.github.com/users/monasca/orgs","repos_url":"https://api.github.com/users/monasca/repos","events_url":"https://api.github.com/users/monasca/events{/privacy}","received_events_url":"https://api.github.com/users/monasca/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/monasca/monasca-watchers","description":"Watchers to check health of Monasca components","fork":false,"url":"https://api.github.com/repos/monasca/monasca-watchers","forks_url":"https://api.github.com/repos/monasca/monasca-watchers/forks","keys_url":"https://api.github.com/repos/monasca/monasca-watchers/keys{/key_id}","collaborators_url":"https://api.github.com/repos/monasca/monasca-watchers/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/monasca/monasca-watchers/teams","hooks_url":"https://api.github.com/repos/monasca/monasca-watchers/hooks","issue_events_url":"https://api.github.com/repos/monasca/monasca-watchers/issues/events{/number}","events_url":"https://api.github.com/repos/monasca/monasca-watchers/events","assignees_url":"https://api.github.com/repos/monasca/monasca-watchers/assignees{/user}","branches_url":"https://api.github.com/repos/monasca/monasca-watchers/branches{/branch}","tags_url":"https://api.github.com/repos/monasca/monasca-watchers/tags","blobs_url":"https://api.github.com/repos/monasca/monasca-watchers/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/monasca/monasca-watchers/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/monasca/monasca-watchers/git/refs{/sha}","trees_url":"https://api.github.com/repos/monasca/monasca-watchers/git/trees{/sha}","statuses_url":"https://api.github.com/repos/monasca/monasca-watchers/statuses/{sha}","languages_url":"https://api.github.com/repos/monasca/monasca-watchers/languages","stargazers_url":"https://api.github.com/repos/monasca/monasca-watchers/stargazers","contributors_url":"https://api.github.com/repos/monasca/monasca-watchers/contributors","subscribers_url":"https://api.github.com/repos/monasca/monasca-watchers/subscribers","subscription_url":"https://api.github.com/repos/monasca/monasca-watchers/subscription","commits_url":"https://api.github.com/repos/monasca/monasca-watchers/commits{/sha}","git_commits_url":"https://api.github.com/repos/monasca/monasca-watchers/git/commits{/sha}","comments_url":"https://api.github.com/repos/monasca/monasca-watchers/comments{/number}","issue_comment_url":"https://api.github.com/repos/monasca/monasca-watchers/issues/comments{/number}","contents_url":"https://api.github.com/repos/monasca/monasca-watchers/contents/{+path}","compare_url":"https://api.github.com/repos/monasca/monasca-watchers/compare/{base}...{head}","merges_url":"https://api.github.com/repos/monasca/monasca-watchers/merges","archive_url":"https://api.github.com/repos/monasca/monasca-watchers/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/monasca/monasca-watchers/downloads","issues_url":"https://api.github.com/repos/monasca/monasca-watchers/issues{/number}","pulls_url":"https://api.github.com/repos/monasca/monasca-watchers/pulls{/number}","milestones_url":"https://api.github.com/repos/monasca/monasca-watchers/milestones{/number}","notifications_url":"https://api.github.com/repos/monasca/monasca-watchers/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/monasca/monasca-watchers/labels{/name}","releases_url":"https://api.github.com/repos/monasca/monasca-watchers/releases{/id}","deployments_url":"https://api.github.com/repos/monasca/monasca-watchers/deployments","created_at":"2017-11-14T17:12:10Z","updated_at":"2017-11-16T07:04:14Z","pushed_at":"2017-12-18T21:52:15Z","git_url":"git://github.com/monasca/monasca-watchers.git","ssh_url":"git@github.com:monasca/monasca-watchers.git","clone_url":"https://github.com/monasca/monasca-watchers.git","svn_url":"https://github.com/monasca/monasca-watchers","homepage":null,"size":32,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":2,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8"},"html":{"href":"https://github.com/monasca/monasca-watchers/pull/8"},"issue":{"href":"https://api.github.com/repos/monasca/monasca-watchers/issues/8"},"comments":{"href":"https://api.github.com/repos/monasca/monasca-watchers/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/monasca/monasca-watchers/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/monasca/monasca-watchers/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/monasca/monasca-watchers/statuses/39918ffee4cb3c73b455b97974164707db2bfe50"}},"author_association":"NONE"}}
{"actor":{"display_login":"craigbr"}}