{"action":"created","comment":{"url":"https://api.github.com/repos/twosigma/Cook/pulls/comments/216462039","pull_request_review_id":153942886,"id":216462039,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNjQ2MjAzOQ==","diff_hunk":"@@ -1,48 +1,200 @@\n (ns cook.mesos.data-locality\n-  (:require [cook.config :as config]\n+  (:require [cheshire.core :as cheshire]\n+            [clj-http.client :as http]\n+            [clj-time.coerce :as tc]\n+            [clj-time.core :as t]\n+            [clj-time.format :as tf]\n+            [clojure.set :as set]\n+            [clojure.tools.logging :as log]\n+            [cook.config :as config]\n+            [cook.mesos.util :as util]\n+            [datomic.api :as d]\n+            [metrics.histograms :as histograms]\n+            [metrics.timers :as timers]\n             [plumbing.core :as pc])\n-  (:import com.netflix.fenzo.VMTaskFitnessCalculator\n-           com.netflix.fenzo.plugins.BinPackingFitnessCalculators))\n+  (:import com.google.common.cache.Cache\n+           com.netflix.fenzo.VMTaskFitnessCalculator\n+           com.netflix.fenzo.plugins.BinPackingFitnessCalculators\n+           java.util.UUID))\n+\n+(def partition-date-format (:basic-date tf/formatters))\n+\n+(defonce ^Cache job-uuid->dataset-maps-cache (util/new-cache))\n+\n+(defn- make-partition-map\n+  [partition-type partition]\n+  (let [format-date (fn format-date [date] (tf/unparse partition-date-format (tc/from-date date)))]\n+    (case partition-type\n+      \"date\" {\"begin\" (format-date (:dataset.partition/begin partition))\n+              \"end\" (format-date (:dataset.partition/end partition))})))\n+\n+(defn- make-dataset-maps\n+  [job]\n+  (->> job\n+       :job/datasets\n+       (map (fn [{:keys [dataset/partitions dataset/partition-type dataset/parameters]}]\n+              (let [partitions (when (not (empty? partitions))\n+                                 (->> partitions\n+                                      (map (partial make-partition-map partition-type))\n+                                      (into #{})))]\n+                (cond-> {:dataset (into {} (map (fn [p] [(:dataset.parameter/key p) (:dataset.parameter/value p)])\n+                                                parameters))}\n+                  partitions (assoc :partitions partitions)))))\n+       (into #{})))\n+\n+(defn get-dataset-maps\n+  \"Returns the (possibly cached) datasets for the given job\"\n+  [job]\n+  (util/lookup-cache! job-uuid->dataset-maps-cache\n+                      :job/uuid\n+                      make-dataset-maps\n+                      job))\n+\n+(histograms/defhistogram [cook-mesos data-locality cost-staleness])\n+\n+(let [datasets->host-name->cost-atom (atom {})\n+      datasets->last-update-time-atom (atom {})]\n+\n+  (defn reset-data-local-costs! []\n+    (reset! datasets->host-name->cost-atom {})\n+    (reset! datasets->last-update-time-atom {}))\n \n-(let [data-local-costs (atom {})]\n   (defn update-data-local-costs\n     \"Updates the current data local costs. Costs larger than the configured max-cost will be capped at max-cost\n      and negative costs will be reset to 0.\"\n-    [job->host->cost]\n-    (let [{:keys [maximum-cost]} (config/data-local-fitness-config)]\n-      (->> job->host->cost\n-           (pc/map-vals (fn [host->cost]\n-                          (pc/map-vals (fn [cost] (-> cost (min maximum-cost) (max 0)))\n-                                       host->cost)))\n-           (reset! data-local-costs))))\n+    [datasets->host->cost stale-datasets]\n+    (let [{:keys [cache-ttl-ms]} (config/data-local-fitness-config)\n+          datasets->last-update-time @datasets->last-update-time-atom\n+          current-time (t/now)\n+          datasets-to-remove (filter (fn [datasets]\n+                                       (when-let [update-time (datasets->last-update-time datasets nil)]\n+                                         (< cache-ttl-ms\n+                                            (t/in-millis (t/interval update-time current-time)))))\n+                                     stale-datasets)\n+          clean-datasets->host->cost (pc/map-vals (fn [host->cost]\n+                                                    (pc/map-vals (fn [cost] (-> cost (min 1.0) (max 0)))\n+                                                                 host->cost))\n+                                                  datasets->host->cost)]\n+      (doseq [[_ update-time] (apply dissoc datasets->last-update-time stale-datasets)]\n+        (histograms/update! cost-staleness (t/in-millis (t/interval update-time current-time))))","path":"scheduler/src/cook/mesos/data_locality.clj","position":null,"original_position":90,"commit_id":"a65f69e41886b8456a329fb96431973db87ae266","original_commit_id":"3d7adaaf2ca203f674360bd04f60e7ff1e2eba07","user":{"login":"pschorf","id":88803,"node_id":"MDQ6VXNlcjg4ODAz","avatar_url":"https://avatars0.githubusercontent.com/u/88803?v=4","gravatar_id":"","url":"https://api.github.com/users/pschorf","html_url":"https://github.com/pschorf","followers_url":"https://api.github.com/users/pschorf/followers","following_url":"https://api.github.com/users/pschorf/following{/other_user}","gists_url":"https://api.github.com/users/pschorf/gists{/gist_id}","starred_url":"https://api.github.com/users/pschorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pschorf/subscriptions","organizations_url":"https://api.github.com/users/pschorf/orgs","repos_url":"https://api.github.com/users/pschorf/repos","events_url":"https://api.github.com/users/pschorf/events{/privacy}","received_events_url":"https://api.github.com/users/pschorf/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2018-09-10T20:31:14Z","updated_at":"2018-09-10T20:38:05Z","html_url":"https://github.com/twosigma/Cook/pull/941#discussion_r216462039","pull_request_url":"https://api.github.com/repos/twosigma/Cook/pulls/941","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/comments/216462039"},"html":{"href":"https://github.com/twosigma/Cook/pull/941#discussion_r216462039"},"pull_request":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/941"}},"in_reply_to_id":216450424},"pull_request":{"url":"https://api.github.com/repos/twosigma/Cook/pulls/941","id":210835181,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEwODM1MTgx","html_url":"https://github.com/twosigma/Cook/pull/941","diff_url":"https://github.com/twosigma/Cook/pull/941.diff","patch_url":"https://github.com/twosigma/Cook/pull/941.patch","issue_url":"https://api.github.com/repos/twosigma/Cook/issues/941","number":941,"state":"open","locked":false,"title":"Adds integration with data local service","user":{"login":"pschorf","id":88803,"node_id":"MDQ6VXNlcjg4ODAz","avatar_url":"https://avatars0.githubusercontent.com/u/88803?v=4","gravatar_id":"","url":"https://api.github.com/users/pschorf","html_url":"https://github.com/pschorf","followers_url":"https://api.github.com/users/pschorf/followers","following_url":"https://api.github.com/users/pschorf/following{/other_user}","gists_url":"https://api.github.com/users/pschorf/gists{/gist_id}","starred_url":"https://api.github.com/users/pschorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pschorf/subscriptions","organizations_url":"https://api.github.com/users/pschorf/orgs","repos_url":"https://api.github.com/users/pschorf/repos","events_url":"https://api.github.com/users/pschorf/events{/privacy}","received_events_url":"https://api.github.com/users/pschorf/received_events","type":"User","site_admin":false},"body":"## Changes proposed in this PR\r\n- Adds \"datasets\" field to jobs\r\n- Adds support for contacting a data local service to obtain cost data for scheduling\r\n\r\n## Why are we making these changes?\r\nThis allows users to configure a Cook cluster to use an external data local cost service to supply cook with cost information, which it can use to prioritize scheduling tasks.\r\n\r\n","created_at":"2018-08-24T20:00:08Z","updated_at":"2018-09-10T20:38:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e69e64e242d41dd08bca2c4c5faf760363408fd8","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/twosigma/Cook/pulls/941/commits","review_comments_url":"https://api.github.com/repos/twosigma/Cook/pulls/941/comments","review_comment_url":"https://api.github.com/repos/twosigma/Cook/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twosigma/Cook/issues/941/comments","statuses_url":"https://api.github.com/repos/twosigma/Cook/statuses/a65f69e41886b8456a329fb96431973db87ae266","head":{"label":"pschorf:data-local-service","ref":"data-local-service","sha":"a65f69e41886b8456a329fb96431973db87ae266","user":{"login":"pschorf","id":88803,"node_id":"MDQ6VXNlcjg4ODAz","avatar_url":"https://avatars0.githubusercontent.com/u/88803?v=4","gravatar_id":"","url":"https://api.github.com/users/pschorf","html_url":"https://github.com/pschorf","followers_url":"https://api.github.com/users/pschorf/followers","following_url":"https://api.github.com/users/pschorf/following{/other_user}","gists_url":"https://api.github.com/users/pschorf/gists{/gist_id}","starred_url":"https://api.github.com/users/pschorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pschorf/subscriptions","organizations_url":"https://api.github.com/users/pschorf/orgs","repos_url":"https://api.github.com/users/pschorf/repos","events_url":"https://api.github.com/users/pschorf/events{/privacy}","received_events_url":"https://api.github.com/users/pschorf/received_events","type":"User","site_admin":false},"repo":{"id":81490196,"node_id":"MDEwOlJlcG9zaXRvcnk4MTQ5MDE5Ng==","name":"Cook","full_name":"pschorf/Cook","owner":{"login":"pschorf","id":88803,"node_id":"MDQ6VXNlcjg4ODAz","avatar_url":"https://avatars0.githubusercontent.com/u/88803?v=4","gravatar_id":"","url":"https://api.github.com/users/pschorf","html_url":"https://github.com/pschorf","followers_url":"https://api.github.com/users/pschorf/followers","following_url":"https://api.github.com/users/pschorf/following{/other_user}","gists_url":"https://api.github.com/users/pschorf/gists{/gist_id}","starred_url":"https://api.github.com/users/pschorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pschorf/subscriptions","organizations_url":"https://api.github.com/users/pschorf/orgs","repos_url":"https://api.github.com/users/pschorf/repos","events_url":"https://api.github.com/users/pschorf/events{/privacy}","received_events_url":"https://api.github.com/users/pschorf/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pschorf/Cook","description":"Fair job scheduler on Mesos for batch workloads and Spark","fork":true,"url":"https://api.github.com/repos/pschorf/Cook","forks_url":"https://api.github.com/repos/pschorf/Cook/forks","keys_url":"https://api.github.com/repos/pschorf/Cook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pschorf/Cook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pschorf/Cook/teams","hooks_url":"https://api.github.com/repos/pschorf/Cook/hooks","issue_events_url":"https://api.github.com/repos/pschorf/Cook/issues/events{/number}","events_url":"https://api.github.com/repos/pschorf/Cook/events","assignees_url":"https://api.github.com/repos/pschorf/Cook/assignees{/user}","branches_url":"https://api.github.com/repos/pschorf/Cook/branches{/branch}","tags_url":"https://api.github.com/repos/pschorf/Cook/tags","blobs_url":"https://api.github.com/repos/pschorf/Cook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pschorf/Cook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pschorf/Cook/git/refs{/sha}","trees_url":"https://api.github.com/repos/pschorf/Cook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pschorf/Cook/statuses/{sha}","languages_url":"https://api.github.com/repos/pschorf/Cook/languages","stargazers_url":"https://api.github.com/repos/pschorf/Cook/stargazers","contributors_url":"https://api.github.com/repos/pschorf/Cook/contributors","subscribers_url":"https://api.github.com/repos/pschorf/Cook/subscribers","subscription_url":"https://api.github.com/repos/pschorf/Cook/subscription","commits_url":"https://api.github.com/repos/pschorf/Cook/commits{/sha}","git_commits_url":"https://api.github.com/repos/pschorf/Cook/git/commits{/sha}","comments_url":"https://api.github.com/repos/pschorf/Cook/comments{/number}","issue_comment_url":"https://api.github.com/repos/pschorf/Cook/issues/comments{/number}","contents_url":"https://api.github.com/repos/pschorf/Cook/contents/{+path}","compare_url":"https://api.github.com/repos/pschorf/Cook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pschorf/Cook/merges","archive_url":"https://api.github.com/repos/pschorf/Cook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pschorf/Cook/downloads","issues_url":"https://api.github.com/repos/pschorf/Cook/issues{/number}","pulls_url":"https://api.github.com/repos/pschorf/Cook/pulls{/number}","milestones_url":"https://api.github.com/repos/pschorf/Cook/milestones{/number}","notifications_url":"https://api.github.com/repos/pschorf/Cook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pschorf/Cook/labels{/name}","releases_url":"https://api.github.com/repos/pschorf/Cook/releases{/id}","deployments_url":"https://api.github.com/repos/pschorf/Cook/deployments","created_at":"2017-02-09T20:07:17Z","updated_at":"2017-02-09T20:07:19Z","pushed_at":"2018-09-10T20:38:00Z","git_url":"git://github.com/pschorf/Cook.git","ssh_url":"git@github.com:pschorf/Cook.git","clone_url":"https://github.com/pschorf/Cook.git","svn_url":"https://github.com/pschorf/Cook","homepage":"","size":42921,"stargazers_count":0,"watchers_count":0,"language":"Clojure","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":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"twosigma:master","ref":"master","sha":"9071a1d0a4a63488d4c27f5d79a03d8ab2bee74f","user":{"login":"twosigma","id":4049181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwNDkxODE=","avatar_url":"https://avatars3.githubusercontent.com/u/4049181?v=4","gravatar_id":"","url":"https://api.github.com/users/twosigma","html_url":"https://github.com/twosigma","followers_url":"https://api.github.com/users/twosigma/followers","following_url":"https://api.github.com/users/twosigma/following{/other_user}","gists_url":"https://api.github.com/users/twosigma/gists{/gist_id}","starred_url":"https://api.github.com/users/twosigma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twosigma/subscriptions","organizations_url":"https://api.github.com/users/twosigma/orgs","repos_url":"https://api.github.com/users/twosigma/repos","events_url":"https://api.github.com/users/twosigma/events{/privacy}","received_events_url":"https://api.github.com/users/twosigma/received_events","type":"Organization","site_admin":false},"repo":{"id":42325066,"node_id":"MDEwOlJlcG9zaXRvcnk0MjMyNTA2Ng==","name":"Cook","full_name":"twosigma/Cook","owner":{"login":"twosigma","id":4049181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwNDkxODE=","avatar_url":"https://avatars3.githubusercontent.com/u/4049181?v=4","gravatar_id":"","url":"https://api.github.com/users/twosigma","html_url":"https://github.com/twosigma","followers_url":"https://api.github.com/users/twosigma/followers","following_url":"https://api.github.com/users/twosigma/following{/other_user}","gists_url":"https://api.github.com/users/twosigma/gists{/gist_id}","starred_url":"https://api.github.com/users/twosigma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twosigma/subscriptions","organizations_url":"https://api.github.com/users/twosigma/orgs","repos_url":"https://api.github.com/users/twosigma/repos","events_url":"https://api.github.com/users/twosigma/events{/privacy}","received_events_url":"https://api.github.com/users/twosigma/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/twosigma/Cook","description":"Fair job scheduler on Mesos for batch workloads and Spark","fork":false,"url":"https://api.github.com/repos/twosigma/Cook","forks_url":"https://api.github.com/repos/twosigma/Cook/forks","keys_url":"https://api.github.com/repos/twosigma/Cook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twosigma/Cook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twosigma/Cook/teams","hooks_url":"https://api.github.com/repos/twosigma/Cook/hooks","issue_events_url":"https://api.github.com/repos/twosigma/Cook/issues/events{/number}","events_url":"https://api.github.com/repos/twosigma/Cook/events","assignees_url":"https://api.github.com/repos/twosigma/Cook/assignees{/user}","branches_url":"https://api.github.com/repos/twosigma/Cook/branches{/branch}","tags_url":"https://api.github.com/repos/twosigma/Cook/tags","blobs_url":"https://api.github.com/repos/twosigma/Cook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twosigma/Cook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twosigma/Cook/git/refs{/sha}","trees_url":"https://api.github.com/repos/twosigma/Cook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twosigma/Cook/statuses/{sha}","languages_url":"https://api.github.com/repos/twosigma/Cook/languages","stargazers_url":"https://api.github.com/repos/twosigma/Cook/stargazers","contributors_url":"https://api.github.com/repos/twosigma/Cook/contributors","subscribers_url":"https://api.github.com/repos/twosigma/Cook/subscribers","subscription_url":"https://api.github.com/repos/twosigma/Cook/subscription","commits_url":"https://api.github.com/repos/twosigma/Cook/commits{/sha}","git_commits_url":"https://api.github.com/repos/twosigma/Cook/git/commits{/sha}","comments_url":"https://api.github.com/repos/twosigma/Cook/comments{/number}","issue_comment_url":"https://api.github.com/repos/twosigma/Cook/issues/comments{/number}","contents_url":"https://api.github.com/repos/twosigma/Cook/contents/{+path}","compare_url":"https://api.github.com/repos/twosigma/Cook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twosigma/Cook/merges","archive_url":"https://api.github.com/repos/twosigma/Cook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twosigma/Cook/downloads","issues_url":"https://api.github.com/repos/twosigma/Cook/issues{/number}","pulls_url":"https://api.github.com/repos/twosigma/Cook/pulls{/number}","milestones_url":"https://api.github.com/repos/twosigma/Cook/milestones{/number}","notifications_url":"https://api.github.com/repos/twosigma/Cook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twosigma/Cook/labels{/name}","releases_url":"https://api.github.com/repos/twosigma/Cook/releases{/id}","deployments_url":"https://api.github.com/repos/twosigma/Cook/deployments","created_at":"2015-09-11T18:20:08Z","updated_at":"2018-09-10T19:53:37Z","pushed_at":"2018-09-10T20:38:02Z","git_url":"git://github.com/twosigma/Cook.git","ssh_url":"git@github.com:twosigma/Cook.git","clone_url":"https://github.com/twosigma/Cook.git","svn_url":"https://github.com/twosigma/Cook","homepage":"","size":42722,"stargazers_count":266,"watchers_count":266,"language":"Clojure","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":47,"mirror_url":null,"archived":false,"open_issues_count":94,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":47,"open_issues":94,"watchers":266,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/941"},"html":{"href":"https://github.com/twosigma/Cook/pull/941"},"issue":{"href":"https://api.github.com/repos/twosigma/Cook/issues/941"},"comments":{"href":"https://api.github.com/repos/twosigma/Cook/issues/941/comments"},"review_comments":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/941/comments"},"review_comment":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/941/commits"},"statuses":{"href":"https://api.github.com/repos/twosigma/Cook/statuses/a65f69e41886b8456a329fb96431973db87ae266"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"pschorf"}}