{"action":"created","comment":{"url":"https://api.github.com/repos/square/misk/pulls/comments/227179203","pull_request_review_id":167157226,"id":227179203,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNzE3OTIwMw==","diff_hunk":"@@ -0,0 +1,182 @@\n+package misk.digester\n+\n+import java.time.Clock\n+import java.time.ZonedDateTime\n+\n+/** WindowDigest holds a t-digest whose data points are scoped to a specific time window. */\n+data class WindowDigest(\n+  val window: Window,\n+  val Digest: TDigest<*>\n+)\n+\n+/** Snapshot is the state of a SlidingWindowDigest at a point in time. */\n+data class Snapshot(\n+  val quantileVals: DoubleArray,  // Values of specific quantiles.\n+  val count: Long,                // Count of observations.\n+  val sum: Double                 // Sum of observations.\n+)\n+\n+/**\n+ * SlidingWindowDigest approximates quantiles of data for a trailing time period. It is thread-safe.\n+ *\n+ * To efficiently store observed data in a mergeable way, t-openDigests are used.\n+ * As t-openDigests do not support discarding older data points, the sliding window\n+ * aspect is approximated by keeping multiple separate t-openDigests scoped to discrete\n+ * overlapping time windows. As a result, quantile data is reported from the most recent window that has ended.\n+ *\n+ * The following example creates a 1 minute sliding window where there are 6 overlapping windows at a given time.\n+ * Reported quantiles are at most 10 seconds out of date.\n+ * NewSlidingWindowDigest(time.Now, NewDefaultVeneurDigest, NewWindower(60, 6))\n+ *\n+ * The following example creates a 10 second sliding window where there are 2 overlapping windows at a given time.\n+ * Reported quantiles are at most 5 seconds out of date:\n+ * NewSlidingWindowDigest(time.Now, NewDefaultVeneurDigest, NewWindower(10, 2))\n+ */\n+class SlidingWindowDigest constructor(\n+  internal var utcNowClock: Clock,\n+  internal val windower: Windower,\n+  internal val tDigest: ()-> TDigest<*>\n+) {\n+\n+  internal val windows: MutableList<WindowDigest> = mutableListOf()\n+  /**\n+   * Adds the given value to all currently open t-openDigests.\n+   * It is important to note that an observed value is not immediately\n+   * reflected in calls to Quantile.\n+   */\n+  @Synchronized fun observe(value: Double) {\n+    for (digest in openDigests(true)) {\n+      digest.Digest.add(value)\n+    }\n+  }\n+\n+  /**\n+   * Returns estimated value for a quantile. The returned value\n+   * may not include recently observed values due to how sliding windows are approximated.\n+   * If no data has been observed then NaN is returned.\n+   */\n+  @Synchronized fun quantile(quantile: Double): Double {\n+    val now = ZonedDateTime.now(utcNowClock)\n+    for (window in windows.reversed()) {","path":"misk/src/main/kotlin/misk/digester/SlidingWindowDigest.kt","position":60,"original_position":60,"commit_id":"3a5541722048c349f953a940d677a91124a2bb8f","original_commit_id":"3a5541722048c349f953a940d677a91124a2bb8f","user":{"login":"alecholmes","id":179268,"node_id":"MDQ6VXNlcjE3OTI2OA==","avatar_url":"https://avatars2.githubusercontent.com/u/179268?v=4","gravatar_id":"","url":"https://api.github.com/users/alecholmes","html_url":"https://github.com/alecholmes","followers_url":"https://api.github.com/users/alecholmes/followers","following_url":"https://api.github.com/users/alecholmes/following{/other_user}","gists_url":"https://api.github.com/users/alecholmes/gists{/gist_id}","starred_url":"https://api.github.com/users/alecholmes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alecholmes/subscriptions","organizations_url":"https://api.github.com/users/alecholmes/orgs","repos_url":"https://api.github.com/users/alecholmes/repos","events_url":"https://api.github.com/users/alecholmes/events{/privacy}","received_events_url":"https://api.github.com/users/alecholmes/received_events","type":"User","site_admin":false},"body":"Does this copy the list? If so, better to iterate in reverse.","created_at":"2018-10-23T00:06:10Z","updated_at":"2018-10-23T00:15:52Z","html_url":"https://github.com/square/misk/pull/566#discussion_r227179203","pull_request_url":"https://api.github.com/repos/square/misk/pulls/566","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/square/misk/pulls/comments/227179203"},"html":{"href":"https://github.com/square/misk/pull/566#discussion_r227179203"},"pull_request":{"href":"https://api.github.com/repos/square/misk/pulls/566"}}},"pull_request":{"url":"https://api.github.com/repos/square/misk/pulls/566","id":224083312,"node_id":"MDExOlB1bGxSZXF1ZXN0MjI0MDgzMzEy","html_url":"https://github.com/square/misk/pull/566","diff_url":"https://github.com/square/misk/pull/566.diff","patch_url":"https://github.com/square/misk/pull/566.patch","issue_url":"https://api.github.com/repos/square/misk/issues/566","number":566,"state":"open","locked":false,"title":"Dweisberg.implement window slider","user":{"login":"danw5050","id":8979437,"node_id":"MDQ6VXNlcjg5Nzk0Mzc=","avatar_url":"https://avatars3.githubusercontent.com/u/8979437?v=4","gravatar_id":"","url":"https://api.github.com/users/danw5050","html_url":"https://github.com/danw5050","followers_url":"https://api.github.com/users/danw5050/followers","following_url":"https://api.github.com/users/danw5050/following{/other_user}","gists_url":"https://api.github.com/users/danw5050/gists{/gist_id}","starred_url":"https://api.github.com/users/danw5050/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danw5050/subscriptions","organizations_url":"https://api.github.com/users/danw5050/orgs","repos_url":"https://api.github.com/users/danw5050/repos","events_url":"https://api.github.com/users/danw5050/events{/privacy}","received_events_url":"https://api.github.com/users/danw5050/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-10-18T20:09:42Z","updated_at":"2018-10-23T00:15:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"388ccef4b52ff7818e5b1a085947977906b6fd80","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/square/misk/pulls/566/commits","review_comments_url":"https://api.github.com/repos/square/misk/pulls/566/comments","review_comment_url":"https://api.github.com/repos/square/misk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/square/misk/issues/566/comments","statuses_url":"https://api.github.com/repos/square/misk/statuses/3a5541722048c349f953a940d677a91124a2bb8f","head":{"label":"square:dweisberg.implement-window-slider","ref":"dweisberg.implement-window-slider","sha":"3a5541722048c349f953a940d677a91124a2bb8f","user":{"login":"square","id":82592,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyNTky","avatar_url":"https://avatars0.githubusercontent.com/u/82592?v=4","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"repo":{"id":113107217,"node_id":"MDEwOlJlcG9zaXRvcnkxMTMxMDcyMTc=","name":"misk","full_name":"square/misk","private":false,"owner":{"login":"square","id":82592,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyNTky","avatar_url":"https://avatars0.githubusercontent.com/u/82592?v=4","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/square/misk","description":null,"fork":false,"url":"https://api.github.com/repos/square/misk","forks_url":"https://api.github.com/repos/square/misk/forks","keys_url":"https://api.github.com/repos/square/misk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/square/misk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/square/misk/teams","hooks_url":"https://api.github.com/repos/square/misk/hooks","issue_events_url":"https://api.github.com/repos/square/misk/issues/events{/number}","events_url":"https://api.github.com/repos/square/misk/events","assignees_url":"https://api.github.com/repos/square/misk/assignees{/user}","branches_url":"https://api.github.com/repos/square/misk/branches{/branch}","tags_url":"https://api.github.com/repos/square/misk/tags","blobs_url":"https://api.github.com/repos/square/misk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/square/misk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/square/misk/git/refs{/sha}","trees_url":"https://api.github.com/repos/square/misk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/square/misk/statuses/{sha}","languages_url":"https://api.github.com/repos/square/misk/languages","stargazers_url":"https://api.github.com/repos/square/misk/stargazers","contributors_url":"https://api.github.com/repos/square/misk/contributors","subscribers_url":"https://api.github.com/repos/square/misk/subscribers","subscription_url":"https://api.github.com/repos/square/misk/subscription","commits_url":"https://api.github.com/repos/square/misk/commits{/sha}","git_commits_url":"https://api.github.com/repos/square/misk/git/commits{/sha}","comments_url":"https://api.github.com/repos/square/misk/comments{/number}","issue_comment_url":"https://api.github.com/repos/square/misk/issues/comments{/number}","contents_url":"https://api.github.com/repos/square/misk/contents/{+path}","compare_url":"https://api.github.com/repos/square/misk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/square/misk/merges","archive_url":"https://api.github.com/repos/square/misk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/square/misk/downloads","issues_url":"https://api.github.com/repos/square/misk/issues{/number}","pulls_url":"https://api.github.com/repos/square/misk/pulls{/number}","milestones_url":"https://api.github.com/repos/square/misk/milestones{/number}","notifications_url":"https://api.github.com/repos/square/misk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/square/misk/labels{/name}","releases_url":"https://api.github.com/repos/square/misk/releases{/id}","deployments_url":"https://api.github.com/repos/square/misk/deployments","created_at":"2017-12-04T23:31:52Z","updated_at":"2018-10-20T02:28:54Z","pushed_at":"2018-10-23T00:12:47Z","git_url":"git://github.com/square/misk.git","ssh_url":"git@github.com:square/misk.git","clone_url":"https://github.com/square/misk.git","svn_url":"https://github.com/square/misk","homepage":null,"size":3206,"stargazers_count":114,"watchers_count":114,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":14,"mirror_url":null,"archived":false,"open_issues_count":95,"license":null,"forks":14,"open_issues":95,"watchers":114,"default_branch":"master"}},"base":{"label":"square:master","ref":"master","sha":"9fd4574b2ccd3407a047d3b5e819e34819732866","user":{"login":"square","id":82592,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyNTky","avatar_url":"https://avatars0.githubusercontent.com/u/82592?v=4","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"repo":{"id":113107217,"node_id":"MDEwOlJlcG9zaXRvcnkxMTMxMDcyMTc=","name":"misk","full_name":"square/misk","private":false,"owner":{"login":"square","id":82592,"node_id":"MDEyOk9yZ2FuaXphdGlvbjgyNTky","avatar_url":"https://avatars0.githubusercontent.com/u/82592?v=4","gravatar_id":"","url":"https://api.github.com/users/square","html_url":"https://github.com/square","followers_url":"https://api.github.com/users/square/followers","following_url":"https://api.github.com/users/square/following{/other_user}","gists_url":"https://api.github.com/users/square/gists{/gist_id}","starred_url":"https://api.github.com/users/square/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/square/subscriptions","organizations_url":"https://api.github.com/users/square/orgs","repos_url":"https://api.github.com/users/square/repos","events_url":"https://api.github.com/users/square/events{/privacy}","received_events_url":"https://api.github.com/users/square/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/square/misk","description":null,"fork":false,"url":"https://api.github.com/repos/square/misk","forks_url":"https://api.github.com/repos/square/misk/forks","keys_url":"https://api.github.com/repos/square/misk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/square/misk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/square/misk/teams","hooks_url":"https://api.github.com/repos/square/misk/hooks","issue_events_url":"https://api.github.com/repos/square/misk/issues/events{/number}","events_url":"https://api.github.com/repos/square/misk/events","assignees_url":"https://api.github.com/repos/square/misk/assignees{/user}","branches_url":"https://api.github.com/repos/square/misk/branches{/branch}","tags_url":"https://api.github.com/repos/square/misk/tags","blobs_url":"https://api.github.com/repos/square/misk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/square/misk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/square/misk/git/refs{/sha}","trees_url":"https://api.github.com/repos/square/misk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/square/misk/statuses/{sha}","languages_url":"https://api.github.com/repos/square/misk/languages","stargazers_url":"https://api.github.com/repos/square/misk/stargazers","contributors_url":"https://api.github.com/repos/square/misk/contributors","subscribers_url":"https://api.github.com/repos/square/misk/subscribers","subscription_url":"https://api.github.com/repos/square/misk/subscription","commits_url":"https://api.github.com/repos/square/misk/commits{/sha}","git_commits_url":"https://api.github.com/repos/square/misk/git/commits{/sha}","comments_url":"https://api.github.com/repos/square/misk/comments{/number}","issue_comment_url":"https://api.github.com/repos/square/misk/issues/comments{/number}","contents_url":"https://api.github.com/repos/square/misk/contents/{+path}","compare_url":"https://api.github.com/repos/square/misk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/square/misk/merges","archive_url":"https://api.github.com/repos/square/misk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/square/misk/downloads","issues_url":"https://api.github.com/repos/square/misk/issues{/number}","pulls_url":"https://api.github.com/repos/square/misk/pulls{/number}","milestones_url":"https://api.github.com/repos/square/misk/milestones{/number}","notifications_url":"https://api.github.com/repos/square/misk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/square/misk/labels{/name}","releases_url":"https://api.github.com/repos/square/misk/releases{/id}","deployments_url":"https://api.github.com/repos/square/misk/deployments","created_at":"2017-12-04T23:31:52Z","updated_at":"2018-10-20T02:28:54Z","pushed_at":"2018-10-23T00:12:47Z","git_url":"git://github.com/square/misk.git","ssh_url":"git@github.com:square/misk.git","clone_url":"https://github.com/square/misk.git","svn_url":"https://github.com/square/misk","homepage":null,"size":3206,"stargazers_count":114,"watchers_count":114,"language":"Kotlin","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":14,"mirror_url":null,"archived":false,"open_issues_count":95,"license":null,"forks":14,"open_issues":95,"watchers":114,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/square/misk/pulls/566"},"html":{"href":"https://github.com/square/misk/pull/566"},"issue":{"href":"https://api.github.com/repos/square/misk/issues/566"},"comments":{"href":"https://api.github.com/repos/square/misk/issues/566/comments"},"review_comments":{"href":"https://api.github.com/repos/square/misk/pulls/566/comments"},"review_comment":{"href":"https://api.github.com/repos/square/misk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/square/misk/pulls/566/commits"},"statuses":{"href":"https://api.github.com/repos/square/misk/statuses/3a5541722048c349f953a940d677a91124a2bb8f"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"alecholmes"}}