GitHub PullRequestReviewCommentEvent at 2014-05-12 10:11:04
Repository: pushgateway
Actor: juliusv
Payload: {"comment":{"url":"https://api.github.com/repos/prometheus/pushgateway/pulls/comments/12521275","id":12521275,"diff_hunk":"@@ -0,0 +1,299 @@\n+package storage\n+\n+import (\n+\t\"encoding/gob\"\n+\t\"io\"\n+\t\"io/ioutil\"\n+\t\"log\"\n+\t\"os\"\n+\t\"path\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"code.google.com/p/goprotobuf/proto\"\n+\n+\tdto \"github.com/prometheus/client_model/go\"\n+)\n+\n+const (\n+\twriteQueueCapacity = 1000\n+)\n+\n+type jobToInstanceMap map[string]instanceToNameMap\n+type instanceToNameMap map[string]nameToTimestampedMetricFamilyMap\n+type nameToTimestampedMetricFamilyMap map[string]timestampedMetricFamily\n+\n+// DiskMetricStore is an implementation of MetricStore that persists metrics to\n+// disk.\n+type DiskMetricStore struct {\n+\tlock            sync.RWMutex\n+\twriteQueue      chan WriteRequest\n+\tdrain           chan struct{}\n+\tdone            chan error\n+\tmetricFamilies  jobToInstanceMap\n+\tpersistenceFile string\n+}\n+\n+// NewDiskMetricStore returns a DiskMetricStore ready to use. To cleanly shut it\n+// down and free resources, the Shutdown() method has to be called.  If\n+// persistenceFile is the empty string, no persisting to disk will\n+// happen. Otherwise, a file of that name is used for persisting metrics to\n+// disk. If the file already exists, metrics are read from it as part of the\n+// start-up. Persisting is happening upon shutdown and after every write action,\n+// but the latter will only happen persistenceDuration after the previous\n+// persisting.\n+func NewDiskMetricStore(\n+\tpersistenceFile string,\n+\tpersistenceDuration time.Duration,\n+) *DiskMetricStore {\n+\tdms := &DiskMetricStore{\n+\t\twriteQueue:      make(chan WriteRequest, writeQueueCapacity),\n+\t\tdrain:           make(chan struct{}),\n+\t\tdone:            make(chan error),\n+\t\tmetricFamilies:  jobToInstanceMap{},\n+\t\tpersistenceFile: persistenceFile,\n+\t}\n+\tif err := dms.restore(); err != nil {\n+\t\tlog.Print(\"Could not load persisted metrics: \", err)\n+\t}\n+\tgo dms.loop(persistenceDuration)","path":"storage/diskmetricstore.go","position":59,"original_position":59,"commit_id":"62c95fd49e9a4ebfb64bdd84abe8c5656c239c56","original_commit_id":"62c95fd49e9a4ebfb64bdd84abe8c5656c239c56","user":{"login":"juliusv","id":538008,"avatar_url":"https://avatars.githubusercontent.com/u/538008?","gravatar_id":"60d05309d93979e15117f3dfbda6a15f","url":"https://api.github.com/users/juliusv","html_url":"https://github.com/juliusv","followers_url":"https://api.github.com/users/juliusv/followers","following_url":"https://api.github.com/users/juliusv/following{/other_user}","gists_url":"https://api.github.com/users/juliusv/gists{/gist_id}","starred_url":"https://api.github.com/users/juliusv/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juliusv/subscriptions","organizations_url":"https://api.github.com/users/juliusv/orgs","repos_url":"https://api.github.com/users/juliusv/repos","events_url":"https://api.github.com/users/juliusv/events{/privacy}","received_events_url":"https://api.github.com/users/juliusv/received_events","type":"User","site_admin":false},"body":"See the \"Leave concurrency up to the caller\" section in our \"patterns and pitfalls\" document. I'd not start goroutines from a constructor, and instead let the caller run `go dms.Loop()`.","created_at":"2014-05-12T10:11:04Z","updated_at":"2014-05-12T10:11:04Z","html_url":"https://github.com/prometheus/pushgateway/pull/2#discussion_r12521275","pull_request_url":"https://api.github.com/repos/prometheus/pushgateway/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/prometheus/pushgateway/pulls/comments/12521275"},"html":{"href":"https://github.com/prometheus/pushgateway/pull/2#discussion_r12521275"},"pull_request":{"href":"https://api.github.com/repos/prometheus/pushgateway/pulls/2"}}}}