{"action":"created","issue":{"url":"https://api.github.com/repos/Yelp/fullerite/issues/126","labels_url":"https://api.github.com/repos/Yelp/fullerite/issues/126/labels{/name}","comments_url":"https://api.github.com/repos/Yelp/fullerite/issues/126/comments","events_url":"https://api.github.com/repos/Yelp/fullerite/issues/126/events","html_url":"https://github.com/Yelp/fullerite/pull/126","id":123044723,"number":126,"title":"Add asynchronous collector interval exec","user":{"login":"tiras-j","id":6816898,"avatar_url":"https://avatars.githubusercontent.com/u/6816898?v=3","gravatar_id":"","url":"https://api.github.com/users/tiras-j","html_url":"https://github.com/tiras-j","followers_url":"https://api.github.com/users/tiras-j/followers","following_url":"https://api.github.com/users/tiras-j/following{/other_user}","gists_url":"https://api.github.com/users/tiras-j/gists{/gist_id}","starred_url":"https://api.github.com/users/tiras-j/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tiras-j/subscriptions","organizations_url":"https://api.github.com/users/tiras-j/orgs","repos_url":"https://api.github.com/users/tiras-j/repos","events_url":"https://api.github.com/users/tiras-j/events{/privacy}","received_events_url":"https://api.github.com/users/tiras-j/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-18T23:43:56Z","updated_at":"2015-12-19T02:49:20Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Yelp/fullerite/pulls/126","html_url":"https://github.com/Yelp/fullerite/pull/126","diff_url":"https://github.com/Yelp/fullerite/pull/126.diff","patch_url":"https://github.com/Yelp/fullerite/pull/126.patch"},"body":"This is a bit messy, and if there is a better way to asynchronously monitor execution of a go routine I'd be happy to learn about it, but this should solve two issues that were present:\r\n\r\n1. We were not executing collections at the correct intervals. Before we would execute the collector and then sleep for the duration *sequentially*. Such that the time it takes to execute the collector was not factored into the duration of the interval we'd wait before running it again. As such rather than running the collector on the exact interval every time, we'd wait an interval's worth of time between the end of one collection and the start of the next. However a simple ticker would solve that issue alone and this code is much more messy than that, so on to numero dos --\r\n\r\n2. Running the go collection in a separate go routine with a boolean channel to indicate completion allows us to tick exactly at every interval (since we won't be blocking on the collector.Collect() call) and let's us see if we've overrun the collection interval. Thus we can add some kind of handler code there. What we want to do, I have no idea, but this will give us the option, whether it's simply logging that we are overrunning our interval or stopping the ticker and exiting this collector altogether at least we have the option. \r\n\r\nI'm very unfamiliar with Go, so I'm mostly presenting this PR to get some feedback and spawn some discussion on the current sequential way we do collection intervals.\r\n\r\nEDIT:\r\nAlso the simple solution for the first case above would simply be to use a ticker and block on the collection call directly. This would look as so:\r\n```go\r\nticker := time.NewTicker(time.Duration(collector.Interval()) * time.Second)\r\nfor t := range ticker.C {\r\n    collector.Collect()\r\n}\r\n```\r\nI'm not certain whether the ticker channel will drop ticks that are not ready to be received but I *think* that they will. Meaning if we were to overrun a given collection interval we'd miss the next tick altogether.\r\n\r\nEdit 2:\r\nIndeed it does drop ticks when client is not ready. From source:\r\n> \t// Give the channel a 1-element time buffer.\r\n>\t// If the client falls behind while reading, we drop ticks\r\n>      // on the floor until the client catches up."},"comment":{"url":"https://api.github.com/repos/Yelp/fullerite/issues/comments/165938992","html_url":"https://github.com/Yelp/fullerite/pull/126#issuecomment-165938992","issue_url":"https://api.github.com/repos/Yelp/fullerite/issues/126","id":165938992,"user":{"login":"gnufied","id":278,"avatar_url":"https://avatars.githubusercontent.com/u/278?v=3","gravatar_id":"","url":"https://api.github.com/users/gnufied","html_url":"https://github.com/gnufied","followers_url":"https://api.github.com/users/gnufied/followers","following_url":"https://api.github.com/users/gnufied/following{/other_user}","gists_url":"https://api.github.com/users/gnufied/gists{/gist_id}","starred_url":"https://api.github.com/users/gnufied/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gnufied/subscriptions","organizations_url":"https://api.github.com/users/gnufied/orgs","repos_url":"https://api.github.com/users/gnufied/repos","events_url":"https://api.github.com/users/gnufied/events{/privacy}","received_events_url":"https://api.github.com/users/gnufied/received_events","type":"User","site_admin":false},"created_at":"2015-12-19T02:49:20Z","updated_at":"2015-12-19T02:49:20Z","body":"Yep, trying to factor in collection time into interval and letting same collector run concurrently multiple times is dangerous. It will causes all sort of problems since same collector is not meant to be executed paralley or in other words is not re-entrant. "}}