paasta-tools 1.21.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (348) hide show
  1. k8s_itests/__init__.py +0 -0
  2. k8s_itests/test_autoscaling.py +23 -0
  3. k8s_itests/utils.py +38 -0
  4. paasta_tools/__init__.py +20 -0
  5. paasta_tools/adhoc_tools.py +142 -0
  6. paasta_tools/api/__init__.py +13 -0
  7. paasta_tools/api/api.py +330 -0
  8. paasta_tools/api/api_docs/swagger.json +2323 -0
  9. paasta_tools/api/client.py +106 -0
  10. paasta_tools/api/settings.py +33 -0
  11. paasta_tools/api/tweens/__init__.py +6 -0
  12. paasta_tools/api/tweens/auth.py +125 -0
  13. paasta_tools/api/tweens/profiling.py +108 -0
  14. paasta_tools/api/tweens/request_logger.py +124 -0
  15. paasta_tools/api/views/__init__.py +13 -0
  16. paasta_tools/api/views/autoscaler.py +100 -0
  17. paasta_tools/api/views/exception.py +45 -0
  18. paasta_tools/api/views/flink.py +73 -0
  19. paasta_tools/api/views/instance.py +395 -0
  20. paasta_tools/api/views/pause_autoscaler.py +71 -0
  21. paasta_tools/api/views/remote_run.py +113 -0
  22. paasta_tools/api/views/resources.py +76 -0
  23. paasta_tools/api/views/service.py +35 -0
  24. paasta_tools/api/views/version.py +25 -0
  25. paasta_tools/apply_external_resources.py +79 -0
  26. paasta_tools/async_utils.py +109 -0
  27. paasta_tools/autoscaling/__init__.py +0 -0
  28. paasta_tools/autoscaling/autoscaling_service_lib.py +57 -0
  29. paasta_tools/autoscaling/forecasting.py +106 -0
  30. paasta_tools/autoscaling/max_all_k8s_services.py +41 -0
  31. paasta_tools/autoscaling/pause_service_autoscaler.py +77 -0
  32. paasta_tools/autoscaling/utils.py +52 -0
  33. paasta_tools/bounce_lib.py +184 -0
  34. paasta_tools/broadcast_log_to_services.py +62 -0
  35. paasta_tools/cassandracluster_tools.py +210 -0
  36. paasta_tools/check_autoscaler_max_instances.py +212 -0
  37. paasta_tools/check_cassandracluster_services_replication.py +35 -0
  38. paasta_tools/check_flink_services_health.py +203 -0
  39. paasta_tools/check_kubernetes_api.py +57 -0
  40. paasta_tools/check_kubernetes_services_replication.py +141 -0
  41. paasta_tools/check_oom_events.py +244 -0
  42. paasta_tools/check_services_replication_tools.py +324 -0
  43. paasta_tools/check_spark_jobs.py +234 -0
  44. paasta_tools/cleanup_kubernetes_cr.py +138 -0
  45. paasta_tools/cleanup_kubernetes_crd.py +145 -0
  46. paasta_tools/cleanup_kubernetes_jobs.py +344 -0
  47. paasta_tools/cleanup_tron_namespaces.py +96 -0
  48. paasta_tools/cli/__init__.py +13 -0
  49. paasta_tools/cli/authentication.py +85 -0
  50. paasta_tools/cli/cli.py +260 -0
  51. paasta_tools/cli/cmds/__init__.py +13 -0
  52. paasta_tools/cli/cmds/autoscale.py +143 -0
  53. paasta_tools/cli/cmds/check.py +334 -0
  54. paasta_tools/cli/cmds/cook_image.py +147 -0
  55. paasta_tools/cli/cmds/get_docker_image.py +76 -0
  56. paasta_tools/cli/cmds/get_image_version.py +172 -0
  57. paasta_tools/cli/cmds/get_latest_deployment.py +93 -0
  58. paasta_tools/cli/cmds/info.py +155 -0
  59. paasta_tools/cli/cmds/itest.py +117 -0
  60. paasta_tools/cli/cmds/list.py +66 -0
  61. paasta_tools/cli/cmds/list_clusters.py +42 -0
  62. paasta_tools/cli/cmds/list_deploy_queue.py +171 -0
  63. paasta_tools/cli/cmds/list_namespaces.py +84 -0
  64. paasta_tools/cli/cmds/local_run.py +1396 -0
  65. paasta_tools/cli/cmds/logs.py +1601 -0
  66. paasta_tools/cli/cmds/mark_for_deployment.py +1988 -0
  67. paasta_tools/cli/cmds/mesh_status.py +174 -0
  68. paasta_tools/cli/cmds/pause_service_autoscaler.py +107 -0
  69. paasta_tools/cli/cmds/push_to_registry.py +275 -0
  70. paasta_tools/cli/cmds/remote_run.py +252 -0
  71. paasta_tools/cli/cmds/rollback.py +347 -0
  72. paasta_tools/cli/cmds/secret.py +549 -0
  73. paasta_tools/cli/cmds/security_check.py +59 -0
  74. paasta_tools/cli/cmds/spark_run.py +1400 -0
  75. paasta_tools/cli/cmds/start_stop_restart.py +401 -0
  76. paasta_tools/cli/cmds/status.py +2302 -0
  77. paasta_tools/cli/cmds/validate.py +1012 -0
  78. paasta_tools/cli/cmds/wait_for_deployment.py +275 -0
  79. paasta_tools/cli/fsm/__init__.py +13 -0
  80. paasta_tools/cli/fsm/autosuggest.py +82 -0
  81. paasta_tools/cli/fsm/template/README.md +8 -0
  82. paasta_tools/cli/fsm/template/cookiecutter.json +7 -0
  83. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/kubernetes-PROD.yaml +91 -0
  84. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/monitoring.yaml +20 -0
  85. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/service.yaml +8 -0
  86. paasta_tools/cli/fsm/template/{{cookiecutter.service}}/smartstack.yaml +6 -0
  87. paasta_tools/cli/fsm_cmd.py +121 -0
  88. paasta_tools/cli/paasta_tabcomplete.sh +23 -0
  89. paasta_tools/cli/schemas/adhoc_schema.json +199 -0
  90. paasta_tools/cli/schemas/autoscaling_schema.json +91 -0
  91. paasta_tools/cli/schemas/autotuned_defaults/cassandracluster_schema.json +37 -0
  92. paasta_tools/cli/schemas/autotuned_defaults/kubernetes_schema.json +89 -0
  93. paasta_tools/cli/schemas/deploy_schema.json +173 -0
  94. paasta_tools/cli/schemas/eks_schema.json +970 -0
  95. paasta_tools/cli/schemas/kubernetes_schema.json +970 -0
  96. paasta_tools/cli/schemas/rollback_schema.json +160 -0
  97. paasta_tools/cli/schemas/service_schema.json +25 -0
  98. paasta_tools/cli/schemas/smartstack_schema.json +322 -0
  99. paasta_tools/cli/schemas/tron_schema.json +699 -0
  100. paasta_tools/cli/utils.py +1118 -0
  101. paasta_tools/clusterman.py +21 -0
  102. paasta_tools/config_utils.py +385 -0
  103. paasta_tools/contrib/__init__.py +0 -0
  104. paasta_tools/contrib/bounce_log_latency_parser.py +68 -0
  105. paasta_tools/contrib/check_manual_oapi_changes.sh +24 -0
  106. paasta_tools/contrib/check_orphans.py +306 -0
  107. paasta_tools/contrib/create_dynamodb_table.py +35 -0
  108. paasta_tools/contrib/create_paasta_playground.py +105 -0
  109. paasta_tools/contrib/emit_allocated_cpu_metrics.py +50 -0
  110. paasta_tools/contrib/get_running_task_allocation.py +346 -0
  111. paasta_tools/contrib/habitat_fixer.py +86 -0
  112. paasta_tools/contrib/ide_helper.py +316 -0
  113. paasta_tools/contrib/is_pod_healthy_in_proxy.py +139 -0
  114. paasta_tools/contrib/is_pod_healthy_in_smartstack.py +50 -0
  115. paasta_tools/contrib/kill_bad_containers.py +109 -0
  116. paasta_tools/contrib/mass-deploy-tag.sh +44 -0
  117. paasta_tools/contrib/mock_patch_checker.py +86 -0
  118. paasta_tools/contrib/paasta_update_soa_memcpu.py +520 -0
  119. paasta_tools/contrib/render_template.py +129 -0
  120. paasta_tools/contrib/rightsizer_soaconfigs_update.py +348 -0
  121. paasta_tools/contrib/service_shard_remove.py +157 -0
  122. paasta_tools/contrib/service_shard_update.py +373 -0
  123. paasta_tools/contrib/shared_ip_check.py +77 -0
  124. paasta_tools/contrib/timeouts_metrics_prom.py +64 -0
  125. paasta_tools/delete_kubernetes_deployments.py +89 -0
  126. paasta_tools/deployment_utils.py +44 -0
  127. paasta_tools/docker_wrapper.py +234 -0
  128. paasta_tools/docker_wrapper_imports.py +13 -0
  129. paasta_tools/drain_lib.py +351 -0
  130. paasta_tools/dump_locally_running_services.py +71 -0
  131. paasta_tools/eks_tools.py +119 -0
  132. paasta_tools/envoy_tools.py +373 -0
  133. paasta_tools/firewall.py +504 -0
  134. paasta_tools/firewall_logging.py +154 -0
  135. paasta_tools/firewall_update.py +172 -0
  136. paasta_tools/flink_tools.py +345 -0
  137. paasta_tools/flinkeks_tools.py +90 -0
  138. paasta_tools/frameworks/__init__.py +0 -0
  139. paasta_tools/frameworks/adhoc_scheduler.py +71 -0
  140. paasta_tools/frameworks/constraints.py +87 -0
  141. paasta_tools/frameworks/native_scheduler.py +652 -0
  142. paasta_tools/frameworks/native_service_config.py +301 -0
  143. paasta_tools/frameworks/task_store.py +245 -0
  144. paasta_tools/generate_all_deployments +9 -0
  145. paasta_tools/generate_authenticating_services.py +94 -0
  146. paasta_tools/generate_deployments_for_service.py +255 -0
  147. paasta_tools/generate_services_file.py +114 -0
  148. paasta_tools/generate_services_yaml.py +30 -0
  149. paasta_tools/hacheck.py +76 -0
  150. paasta_tools/instance/__init__.py +0 -0
  151. paasta_tools/instance/hpa_metrics_parser.py +122 -0
  152. paasta_tools/instance/kubernetes.py +1362 -0
  153. paasta_tools/iptables.py +240 -0
  154. paasta_tools/kafkacluster_tools.py +143 -0
  155. paasta_tools/kubernetes/__init__.py +0 -0
  156. paasta_tools/kubernetes/application/__init__.py +0 -0
  157. paasta_tools/kubernetes/application/controller_wrappers.py +476 -0
  158. paasta_tools/kubernetes/application/tools.py +90 -0
  159. paasta_tools/kubernetes/bin/__init__.py +0 -0
  160. paasta_tools/kubernetes/bin/kubernetes_remove_evicted_pods.py +164 -0
  161. paasta_tools/kubernetes/bin/paasta_cleanup_remote_run_resources.py +135 -0
  162. paasta_tools/kubernetes/bin/paasta_cleanup_stale_nodes.py +181 -0
  163. paasta_tools/kubernetes/bin/paasta_secrets_sync.py +758 -0
  164. paasta_tools/kubernetes/remote_run.py +558 -0
  165. paasta_tools/kubernetes_tools.py +4679 -0
  166. paasta_tools/list_kubernetes_service_instances.py +128 -0
  167. paasta_tools/list_tron_namespaces.py +60 -0
  168. paasta_tools/long_running_service_tools.py +678 -0
  169. paasta_tools/mac_address.py +44 -0
  170. paasta_tools/marathon_dashboard.py +0 -0
  171. paasta_tools/mesos/__init__.py +0 -0
  172. paasta_tools/mesos/cfg.py +46 -0
  173. paasta_tools/mesos/cluster.py +60 -0
  174. paasta_tools/mesos/exceptions.py +59 -0
  175. paasta_tools/mesos/framework.py +77 -0
  176. paasta_tools/mesos/log.py +48 -0
  177. paasta_tools/mesos/master.py +306 -0
  178. paasta_tools/mesos/mesos_file.py +169 -0
  179. paasta_tools/mesos/parallel.py +52 -0
  180. paasta_tools/mesos/slave.py +115 -0
  181. paasta_tools/mesos/task.py +94 -0
  182. paasta_tools/mesos/util.py +69 -0
  183. paasta_tools/mesos/zookeeper.py +37 -0
  184. paasta_tools/mesos_maintenance.py +848 -0
  185. paasta_tools/mesos_tools.py +1051 -0
  186. paasta_tools/metrics/__init__.py +0 -0
  187. paasta_tools/metrics/metastatus_lib.py +1110 -0
  188. paasta_tools/metrics/metrics_lib.py +217 -0
  189. paasta_tools/monitoring/__init__.py +13 -0
  190. paasta_tools/monitoring/check_k8s_api_performance.py +110 -0
  191. paasta_tools/monitoring_tools.py +652 -0
  192. paasta_tools/monkrelaycluster_tools.py +146 -0
  193. paasta_tools/nrtsearchservice_tools.py +143 -0
  194. paasta_tools/nrtsearchserviceeks_tools.py +68 -0
  195. paasta_tools/oom_logger.py +321 -0
  196. paasta_tools/paasta_deploy_tron_jobs +3 -0
  197. paasta_tools/paasta_execute_docker_command.py +123 -0
  198. paasta_tools/paasta_native_serviceinit.py +21 -0
  199. paasta_tools/paasta_service_config_loader.py +201 -0
  200. paasta_tools/paastaapi/__init__.py +29 -0
  201. paasta_tools/paastaapi/api/__init__.py +3 -0
  202. paasta_tools/paastaapi/api/autoscaler_api.py +302 -0
  203. paasta_tools/paastaapi/api/default_api.py +569 -0
  204. paasta_tools/paastaapi/api/remote_run_api.py +604 -0
  205. paasta_tools/paastaapi/api/resources_api.py +157 -0
  206. paasta_tools/paastaapi/api/service_api.py +1736 -0
  207. paasta_tools/paastaapi/api_client.py +818 -0
  208. paasta_tools/paastaapi/apis/__init__.py +22 -0
  209. paasta_tools/paastaapi/configuration.py +455 -0
  210. paasta_tools/paastaapi/exceptions.py +137 -0
  211. paasta_tools/paastaapi/model/__init__.py +5 -0
  212. paasta_tools/paastaapi/model/adhoc_launch_history.py +176 -0
  213. paasta_tools/paastaapi/model/autoscaler_count_msg.py +176 -0
  214. paasta_tools/paastaapi/model/deploy_queue.py +178 -0
  215. paasta_tools/paastaapi/model/deploy_queue_service_instance.py +194 -0
  216. paasta_tools/paastaapi/model/envoy_backend.py +185 -0
  217. paasta_tools/paastaapi/model/envoy_location.py +184 -0
  218. paasta_tools/paastaapi/model/envoy_status.py +181 -0
  219. paasta_tools/paastaapi/model/flink_cluster_overview.py +188 -0
  220. paasta_tools/paastaapi/model/flink_config.py +173 -0
  221. paasta_tools/paastaapi/model/flink_job.py +186 -0
  222. paasta_tools/paastaapi/model/flink_job_details.py +192 -0
  223. paasta_tools/paastaapi/model/flink_jobs.py +175 -0
  224. paasta_tools/paastaapi/model/float_and_error.py +173 -0
  225. paasta_tools/paastaapi/model/hpa_metric.py +176 -0
  226. paasta_tools/paastaapi/model/inline_object.py +170 -0
  227. paasta_tools/paastaapi/model/inline_response200.py +170 -0
  228. paasta_tools/paastaapi/model/inline_response2001.py +170 -0
  229. paasta_tools/paastaapi/model/instance_bounce_status.py +200 -0
  230. paasta_tools/paastaapi/model/instance_mesh_status.py +186 -0
  231. paasta_tools/paastaapi/model/instance_status.py +220 -0
  232. paasta_tools/paastaapi/model/instance_status_adhoc.py +187 -0
  233. paasta_tools/paastaapi/model/instance_status_cassandracluster.py +173 -0
  234. paasta_tools/paastaapi/model/instance_status_flink.py +173 -0
  235. paasta_tools/paastaapi/model/instance_status_kafkacluster.py +173 -0
  236. paasta_tools/paastaapi/model/instance_status_kubernetes.py +263 -0
  237. paasta_tools/paastaapi/model/instance_status_kubernetes_autoscaling_status.py +187 -0
  238. paasta_tools/paastaapi/model/instance_status_kubernetes_v2.py +197 -0
  239. paasta_tools/paastaapi/model/instance_status_tron.py +204 -0
  240. paasta_tools/paastaapi/model/instance_tasks.py +182 -0
  241. paasta_tools/paastaapi/model/integer_and_error.py +173 -0
  242. paasta_tools/paastaapi/model/kubernetes_container.py +178 -0
  243. paasta_tools/paastaapi/model/kubernetes_container_v2.py +219 -0
  244. paasta_tools/paastaapi/model/kubernetes_healthcheck.py +176 -0
  245. paasta_tools/paastaapi/model/kubernetes_pod.py +201 -0
  246. paasta_tools/paastaapi/model/kubernetes_pod_event.py +176 -0
  247. paasta_tools/paastaapi/model/kubernetes_pod_v2.py +213 -0
  248. paasta_tools/paastaapi/model/kubernetes_replica_set.py +185 -0
  249. paasta_tools/paastaapi/model/kubernetes_version.py +202 -0
  250. paasta_tools/paastaapi/model/remote_run_outcome.py +189 -0
  251. paasta_tools/paastaapi/model/remote_run_start.py +185 -0
  252. paasta_tools/paastaapi/model/remote_run_stop.py +176 -0
  253. paasta_tools/paastaapi/model/remote_run_token.py +173 -0
  254. paasta_tools/paastaapi/model/resource.py +187 -0
  255. paasta_tools/paastaapi/model/resource_item.py +187 -0
  256. paasta_tools/paastaapi/model/resource_value.py +176 -0
  257. paasta_tools/paastaapi/model/smartstack_backend.py +191 -0
  258. paasta_tools/paastaapi/model/smartstack_location.py +181 -0
  259. paasta_tools/paastaapi/model/smartstack_status.py +181 -0
  260. paasta_tools/paastaapi/model/task_tail_lines.py +176 -0
  261. paasta_tools/paastaapi/model_utils.py +1879 -0
  262. paasta_tools/paastaapi/models/__init__.py +62 -0
  263. paasta_tools/paastaapi/rest.py +287 -0
  264. paasta_tools/prune_completed_pods.py +220 -0
  265. paasta_tools/puppet_service_tools.py +59 -0
  266. paasta_tools/py.typed +1 -0
  267. paasta_tools/remote_git.py +127 -0
  268. paasta_tools/run-paasta-api-in-dev-mode.py +57 -0
  269. paasta_tools/run-paasta-api-playground.py +51 -0
  270. paasta_tools/secret_providers/__init__.py +66 -0
  271. paasta_tools/secret_providers/vault.py +214 -0
  272. paasta_tools/secret_tools.py +277 -0
  273. paasta_tools/setup_istio_mesh.py +353 -0
  274. paasta_tools/setup_kubernetes_cr.py +412 -0
  275. paasta_tools/setup_kubernetes_crd.py +138 -0
  276. paasta_tools/setup_kubernetes_internal_crd.py +154 -0
  277. paasta_tools/setup_kubernetes_job.py +353 -0
  278. paasta_tools/setup_prometheus_adapter_config.py +1028 -0
  279. paasta_tools/setup_tron_namespace.py +248 -0
  280. paasta_tools/slack.py +75 -0
  281. paasta_tools/smartstack_tools.py +676 -0
  282. paasta_tools/spark_tools.py +283 -0
  283. paasta_tools/synapse_srv_namespaces_fact.py +42 -0
  284. paasta_tools/tron/__init__.py +0 -0
  285. paasta_tools/tron/client.py +158 -0
  286. paasta_tools/tron/tron_command_context.py +194 -0
  287. paasta_tools/tron/tron_timeutils.py +101 -0
  288. paasta_tools/tron_tools.py +1448 -0
  289. paasta_tools/utils.py +4307 -0
  290. paasta_tools/yaml_tools.py +44 -0
  291. paasta_tools-1.21.3.data/scripts/apply_external_resources.py +79 -0
  292. paasta_tools-1.21.3.data/scripts/bounce_log_latency_parser.py +68 -0
  293. paasta_tools-1.21.3.data/scripts/check_autoscaler_max_instances.py +212 -0
  294. paasta_tools-1.21.3.data/scripts/check_cassandracluster_services_replication.py +35 -0
  295. paasta_tools-1.21.3.data/scripts/check_flink_services_health.py +203 -0
  296. paasta_tools-1.21.3.data/scripts/check_kubernetes_api.py +57 -0
  297. paasta_tools-1.21.3.data/scripts/check_kubernetes_services_replication.py +141 -0
  298. paasta_tools-1.21.3.data/scripts/check_manual_oapi_changes.sh +24 -0
  299. paasta_tools-1.21.3.data/scripts/check_oom_events.py +244 -0
  300. paasta_tools-1.21.3.data/scripts/check_orphans.py +306 -0
  301. paasta_tools-1.21.3.data/scripts/check_spark_jobs.py +234 -0
  302. paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_cr.py +138 -0
  303. paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_crd.py +145 -0
  304. paasta_tools-1.21.3.data/scripts/cleanup_kubernetes_jobs.py +344 -0
  305. paasta_tools-1.21.3.data/scripts/create_dynamodb_table.py +35 -0
  306. paasta_tools-1.21.3.data/scripts/create_paasta_playground.py +105 -0
  307. paasta_tools-1.21.3.data/scripts/delete_kubernetes_deployments.py +89 -0
  308. paasta_tools-1.21.3.data/scripts/emit_allocated_cpu_metrics.py +50 -0
  309. paasta_tools-1.21.3.data/scripts/generate_all_deployments +9 -0
  310. paasta_tools-1.21.3.data/scripts/generate_authenticating_services.py +94 -0
  311. paasta_tools-1.21.3.data/scripts/generate_deployments_for_service.py +255 -0
  312. paasta_tools-1.21.3.data/scripts/generate_services_file.py +114 -0
  313. paasta_tools-1.21.3.data/scripts/generate_services_yaml.py +30 -0
  314. paasta_tools-1.21.3.data/scripts/get_running_task_allocation.py +346 -0
  315. paasta_tools-1.21.3.data/scripts/habitat_fixer.py +86 -0
  316. paasta_tools-1.21.3.data/scripts/ide_helper.py +316 -0
  317. paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_proxy.py +139 -0
  318. paasta_tools-1.21.3.data/scripts/is_pod_healthy_in_smartstack.py +50 -0
  319. paasta_tools-1.21.3.data/scripts/kill_bad_containers.py +109 -0
  320. paasta_tools-1.21.3.data/scripts/kubernetes_remove_evicted_pods.py +164 -0
  321. paasta_tools-1.21.3.data/scripts/mass-deploy-tag.sh +44 -0
  322. paasta_tools-1.21.3.data/scripts/mock_patch_checker.py +86 -0
  323. paasta_tools-1.21.3.data/scripts/paasta_cleanup_remote_run_resources.py +135 -0
  324. paasta_tools-1.21.3.data/scripts/paasta_cleanup_stale_nodes.py +181 -0
  325. paasta_tools-1.21.3.data/scripts/paasta_deploy_tron_jobs +3 -0
  326. paasta_tools-1.21.3.data/scripts/paasta_execute_docker_command.py +123 -0
  327. paasta_tools-1.21.3.data/scripts/paasta_secrets_sync.py +758 -0
  328. paasta_tools-1.21.3.data/scripts/paasta_tabcomplete.sh +23 -0
  329. paasta_tools-1.21.3.data/scripts/paasta_update_soa_memcpu.py +520 -0
  330. paasta_tools-1.21.3.data/scripts/render_template.py +129 -0
  331. paasta_tools-1.21.3.data/scripts/rightsizer_soaconfigs_update.py +348 -0
  332. paasta_tools-1.21.3.data/scripts/service_shard_remove.py +157 -0
  333. paasta_tools-1.21.3.data/scripts/service_shard_update.py +373 -0
  334. paasta_tools-1.21.3.data/scripts/setup_istio_mesh.py +353 -0
  335. paasta_tools-1.21.3.data/scripts/setup_kubernetes_cr.py +412 -0
  336. paasta_tools-1.21.3.data/scripts/setup_kubernetes_crd.py +138 -0
  337. paasta_tools-1.21.3.data/scripts/setup_kubernetes_internal_crd.py +154 -0
  338. paasta_tools-1.21.3.data/scripts/setup_kubernetes_job.py +353 -0
  339. paasta_tools-1.21.3.data/scripts/setup_prometheus_adapter_config.py +1028 -0
  340. paasta_tools-1.21.3.data/scripts/shared_ip_check.py +77 -0
  341. paasta_tools-1.21.3.data/scripts/synapse_srv_namespaces_fact.py +42 -0
  342. paasta_tools-1.21.3.data/scripts/timeouts_metrics_prom.py +64 -0
  343. paasta_tools-1.21.3.dist-info/LICENSE +201 -0
  344. paasta_tools-1.21.3.dist-info/METADATA +74 -0
  345. paasta_tools-1.21.3.dist-info/RECORD +348 -0
  346. paasta_tools-1.21.3.dist-info/WHEEL +5 -0
  347. paasta_tools-1.21.3.dist-info/entry_points.txt +20 -0
  348. paasta_tools-1.21.3.dist-info/top_level.txt +2 -0
@@ -0,0 +1,676 @@
1
+ # Copyright 2015-2016 Yelp Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ import abc
15
+ import collections
16
+ import csv
17
+ import logging
18
+ import random
19
+ from typing import Any
20
+ from typing import cast
21
+ from typing import Collection
22
+ from typing import DefaultDict
23
+ from typing import Dict
24
+ from typing import Iterable
25
+ from typing import List
26
+ from typing import MutableMapping
27
+ from typing import NamedTuple
28
+ from typing import Optional
29
+ from typing import Sequence
30
+ from typing import Tuple
31
+ from typing import TypeVar
32
+ from typing import Union
33
+
34
+ import requests
35
+ from kubernetes.client import V1Node
36
+ from kubernetes.client import V1Pod
37
+ from mypy_extensions import TypedDict
38
+
39
+ from paasta_tools import envoy_tools
40
+ from paasta_tools import kubernetes_tools
41
+ from paasta_tools import long_running_service_tools
42
+ from paasta_tools import mesos_tools
43
+ from paasta_tools.long_running_service_tools import LongRunningServiceConfig
44
+ from paasta_tools.mesos.exceptions import NoSlavesAvailableError
45
+ from paasta_tools.monitoring_tools import ReplicationChecker
46
+ from paasta_tools.utils import compose_job_id
47
+ from paasta_tools.utils import DEFAULT_SOA_DIR
48
+ from paasta_tools.utils import DeployBlacklist
49
+ from paasta_tools.utils import get_user_agent
50
+ from paasta_tools.utils import SystemPaastaConfig
51
+
52
+
53
+ class HaproxyBackend(TypedDict, total=False):
54
+ check_code: str
55
+ check_duration: str
56
+ check_status: str
57
+ lastchg: str
58
+ pxname: str
59
+ svname: str
60
+ status: str
61
+
62
+
63
+ log = logging.getLogger(__name__)
64
+
65
+
66
+ def retrieve_haproxy_csv(
67
+ synapse_host: str, synapse_port: int, synapse_haproxy_url_format: str, scope: str
68
+ ) -> Iterable[Dict[str, str]]:
69
+ """Retrieves the haproxy csv from the haproxy web interface
70
+
71
+ :param synapse_host: A host that this check should contact for replication information.
72
+ :param synapse_port: A integer that this check should contact for replication information.
73
+ :param synapse_haproxy_url_format: The format of the synapse haproxy URL.
74
+ :param scope: scope
75
+ :returns reader: a csv.DictReader object
76
+ """
77
+ synapse_uri = synapse_haproxy_url_format.format(
78
+ host=synapse_host, port=synapse_port, scope=scope
79
+ )
80
+
81
+ # timeout after 1 second and retry 3 times
82
+ haproxy_request = requests.Session()
83
+ haproxy_request.headers.update({"User-Agent": get_user_agent()})
84
+ haproxy_request.mount("http://", requests.adapters.HTTPAdapter(max_retries=3))
85
+ haproxy_request.mount("https://", requests.adapters.HTTPAdapter(max_retries=3))
86
+ haproxy_response = haproxy_request.get(synapse_uri, timeout=1)
87
+ haproxy_data = haproxy_response.text
88
+ reader = csv.DictReader(haproxy_data.splitlines())
89
+ return reader
90
+
91
+
92
+ def get_backends(
93
+ service: str, synapse_host: str, synapse_port: int, synapse_haproxy_url_format: str
94
+ ) -> List[HaproxyBackend]:
95
+ """Fetches the CSV from haproxy and returns a list of backends,
96
+ regardless of their state.
97
+
98
+ :param service: If None, return backends for all services, otherwise only return backends for this particular
99
+ service.
100
+ :param synapse_host: A host that this check should contact for replication information.
101
+ :param synapse_port: A integer that this check should contact for replication information.
102
+ :param synapse_haproxy_url_format: The format of the synapse haproxy URL.
103
+ :returns backends: A list of dicts representing the backends of all
104
+ services or the requested service
105
+ """
106
+ if service:
107
+ services = [service]
108
+ else:
109
+ services = None
110
+ return get_multiple_backends(
111
+ services,
112
+ synapse_host=synapse_host,
113
+ synapse_port=synapse_port,
114
+ synapse_haproxy_url_format=synapse_haproxy_url_format,
115
+ )
116
+
117
+
118
+ def get_multiple_backends(
119
+ services: Optional[Collection[str]],
120
+ synapse_host: str,
121
+ synapse_port: int,
122
+ synapse_haproxy_url_format: str,
123
+ ) -> List[HaproxyBackend]:
124
+ """Fetches the CSV from haproxy and returns a list of backends,
125
+ regardless of their state.
126
+
127
+ :param services: If None, return backends for all services, otherwise only return backends for these particular
128
+ services.
129
+ :param synapse_host: A host that this check should contact for replication information.
130
+ :param synapse_port: A integer that this check should contact for replication information.
131
+ :param synapse_haproxy_url_format: The format of the synapse haproxy URL.
132
+ :returns backends: A list of dicts representing the backends of all
133
+ services or the requested service
134
+ """
135
+
136
+ if services is not None and len(services) == 1:
137
+ (scope,) = services
138
+ else:
139
+ # Maybe if there's like two or three services we could make two queries, or find the longest common substring.
140
+ # For now let's just hope this is rare and fetch all data.
141
+ scope = ""
142
+
143
+ reader = retrieve_haproxy_csv(
144
+ synapse_host,
145
+ synapse_port,
146
+ synapse_haproxy_url_format=synapse_haproxy_url_format,
147
+ scope=scope,
148
+ )
149
+ backends = []
150
+
151
+ for line in reader:
152
+ # clean up two irregularities of the CSV output, relative to
153
+ # DictReader's behavior there's a leading "# " for no good reason:
154
+ line["pxname"] = line.pop("# pxname")
155
+ # and there's a trailing comma on every line:
156
+ line.pop("")
157
+
158
+ # Look for the service in question and ignore the fictional
159
+ # FRONTEND/BACKEND hosts, use starts_with so that hosts that are UP
160
+ # with 1/X healthchecks to go before going down get counted as UP:
161
+ ha_slave, ha_service = line["svname"], line["pxname"]
162
+ if (services is None or ha_service in services) and ha_slave not in (
163
+ "FRONTEND",
164
+ "BACKEND",
165
+ ):
166
+ backends.append(cast(HaproxyBackend, line))
167
+
168
+ return backends
169
+
170
+
171
+ def load_smartstack_info_for_service(
172
+ service: str,
173
+ namespace: str,
174
+ blacklist: DeployBlacklist,
175
+ system_paasta_config: SystemPaastaConfig,
176
+ soa_dir: str = DEFAULT_SOA_DIR,
177
+ ) -> Dict[str, Dict[str, int]]:
178
+ """Retrieves number of available backends for given service
179
+
180
+ :param service: A service name
181
+ :param namespace: A Smartstack namespace
182
+ :param blacklist: A list of blacklisted location tuples in the form (location, value)
183
+ :param system_paasta_config: A SystemPaastaConfig object representing the system configuration.
184
+ :param soa_dir: SOA dir
185
+ :returns: a dictionary of the form
186
+
187
+ ::
188
+
189
+ {
190
+ 'location_type': {
191
+ 'unique_location_name': {
192
+ 'service.instance': <# ofavailable backends>
193
+ },
194
+ 'other_unique_location_name': ...
195
+ }
196
+ }
197
+
198
+ """
199
+ service_namespace_config = long_running_service_tools.load_service_namespace_config(
200
+ service=service, namespace=namespace, soa_dir=soa_dir
201
+ )
202
+ discover_location_type = service_namespace_config.get_discover()
203
+ return get_smartstack_replication_for_attribute(
204
+ attribute=discover_location_type,
205
+ service=service,
206
+ namespace=namespace,
207
+ blacklist=blacklist,
208
+ system_paasta_config=system_paasta_config,
209
+ )
210
+
211
+
212
+ def get_smartstack_replication_for_attribute(
213
+ attribute: str,
214
+ service: str,
215
+ namespace: str,
216
+ blacklist: DeployBlacklist,
217
+ system_paasta_config: SystemPaastaConfig,
218
+ ) -> Dict[str, Dict[str, int]]:
219
+ """Loads smartstack replication from a host with the specified attribute
220
+
221
+ :param attribute: a Mesos attribute
222
+ :param service: A service name, like 'example_service'
223
+ :param namespace: A particular smartstack namespace to inspect, like 'main'
224
+ :param blacklist: A list of blacklisted location tuples in the form of (location, value)
225
+ :param system_paasta_config: A SystemPaastaConfig object representing the system configuration.
226
+ :returns: a dictionary of the form {'<unique_attribute_value>': <smartstack replication hash>}
227
+ (the dictionary will contain keys for unique all attribute values)
228
+ """
229
+ replication_info = {}
230
+ filtered_slaves = mesos_tools.get_all_slaves_for_blacklist_whitelist(
231
+ blacklist=blacklist, whitelist=None
232
+ )
233
+ if not filtered_slaves:
234
+ raise NoSlavesAvailableError
235
+
236
+ attribute_slave_dict = mesos_tools.get_mesos_slaves_grouped_by_attribute(
237
+ slaves=filtered_slaves, attribute=attribute
238
+ )
239
+
240
+ full_name = compose_job_id(service, namespace)
241
+
242
+ for value, hosts in attribute_slave_dict.items():
243
+ # arbitrarily choose the first host with a given attribute to query for replication stats
244
+ synapse_host = hosts[0]["hostname"]
245
+ repl_info = get_replication_for_services(
246
+ synapse_host=synapse_host,
247
+ synapse_port=system_paasta_config.get_synapse_port(),
248
+ synapse_haproxy_url_format=system_paasta_config.get_synapse_haproxy_url_format(),
249
+ services=[full_name],
250
+ )
251
+ replication_info[value] = repl_info
252
+
253
+ return replication_info
254
+
255
+
256
+ def get_replication_for_all_services(
257
+ synapse_host: str, synapse_port: int, synapse_haproxy_url_format: str
258
+ ) -> Dict[str, int]:
259
+ """Returns the replication level for all services known to this synapse haproxy
260
+
261
+ :param synapse_host: The host that this check should contact for replication information.
262
+ :param synapse_port: The port that this check should contact for replication information.
263
+ :param synapse_haproxy_url_format: The format of the synapse haproxy URL.
264
+ :returns available_instance_counts: A dictionary mapping the service names
265
+ to an integer number of available replicas.
266
+ """
267
+ backends = get_multiple_backends(
268
+ services=None,
269
+ synapse_host=synapse_host,
270
+ synapse_port=synapse_port,
271
+ synapse_haproxy_url_format=synapse_haproxy_url_format,
272
+ )
273
+ return collections.Counter([b["pxname"] for b in backends if backend_is_up(b)])
274
+
275
+
276
+ def get_replication_for_services(
277
+ synapse_host: str,
278
+ synapse_port: int,
279
+ synapse_haproxy_url_format: str,
280
+ services: Collection[str],
281
+ ) -> Dict[str, int]:
282
+ """Returns the replication level for the provided services
283
+
284
+ This check is intended to be used with an haproxy load balancer, and
285
+ relies on the implementation details of that choice.
286
+
287
+ :param synapse_host: The host that this check should contact for replication information.
288
+ :param synapse_port: The port that this check should contact for replication information.
289
+ :param synapse_haproxy_url_format: The format of the synapse haproxy URL.
290
+ :param services: A list of strings that are the service names
291
+ that should be checked for replication.
292
+
293
+ :returns available_instance_counts: A dictionary mapping the service names
294
+ to an integer number of available
295
+ replicas
296
+ :returns None: If it cannot connect to the specified synapse host and port
297
+ """
298
+ backends = get_multiple_backends(
299
+ services=services,
300
+ synapse_host=synapse_host,
301
+ synapse_port=synapse_port,
302
+ synapse_haproxy_url_format=synapse_haproxy_url_format,
303
+ )
304
+
305
+ counter = collections.Counter([b["pxname"] for b in backends if backend_is_up(b)])
306
+ return {sn: counter[sn] for sn in services}
307
+
308
+
309
+ def backend_is_up(backend: HaproxyBackend) -> bool:
310
+ """Returns whether a server is receiving traffic in HAProxy.
311
+
312
+ :param backend: backend dict, like one of those returned by smartstack_tools.get_multiple_backends.
313
+
314
+ :returns is_up: Whether the backend is in a state that receives traffic.
315
+ """
316
+ return str(backend["status"]).startswith("UP")
317
+
318
+
319
+ def ip_port_hostname_from_svname(svname: str) -> Tuple[str, int, str]:
320
+ """This parses the haproxy svname that smartstack creates.
321
+ In old versions of synapse, this is in the format ip:port_hostname.
322
+ In versions newer than dd5843c987740a5d5ce1c83b12b258b7253784a8 it is
323
+ hostname_ip:port
324
+
325
+ :param svname: A svname, in either of the formats described above
326
+ :returns ip_port_hostname: A tuple of ip, port, hostname.
327
+ """
328
+ # split into parts
329
+ parts = set(svname.split("_"))
330
+
331
+ # find those that can be split by : - this is the ip:port
332
+ # there will only be 1 of these
333
+ ip_ports = {part for part in parts if len(part.split(":")) == 2}
334
+
335
+ # the one *not* in the list is the hostname
336
+ hostname = parts.difference(ip_ports).pop()
337
+
338
+ ip, port = ip_ports.pop().split(":")
339
+ return ip, int(port), hostname
340
+
341
+
342
+ def are_services_up_on_ip_port(
343
+ synapse_host: str,
344
+ synapse_port: int,
345
+ synapse_haproxy_url_format: str,
346
+ services: Collection[str],
347
+ host_ip: str,
348
+ host_port: int,
349
+ ) -> bool:
350
+ backends = get_multiple_backends(
351
+ services,
352
+ synapse_host=synapse_host,
353
+ synapse_port=synapse_port,
354
+ synapse_haproxy_url_format=synapse_haproxy_url_format,
355
+ )
356
+ backends_by_ip_port: DefaultDict[
357
+ Tuple[str, int], List[HaproxyBackend]
358
+ ] = collections.defaultdict(list)
359
+
360
+ for backend in backends:
361
+ ip, port, _ = ip_port_hostname_from_svname(backend["svname"])
362
+ backends_by_ip_port[ip, port].append(backend)
363
+
364
+ backends_on_ip = backends_by_ip_port[host_ip, host_port]
365
+ # any backend being up is okay because a previous backend
366
+ # may have had the same IP and synapse only removes them completely
367
+ # after some time
368
+ services_with_atleast_one_backend_up = {service: False for service in services}
369
+ for service in services:
370
+ for be in backends_on_ip:
371
+ if be["pxname"] == service and backend_is_up(be):
372
+ services_with_atleast_one_backend_up[service] = True
373
+ return all(services_with_atleast_one_backend_up.values())
374
+
375
+
376
+ def match_backends_and_pods(
377
+ backends: Iterable[HaproxyBackend], pods: Iterable[V1Pod]
378
+ ) -> List[Tuple[Optional[HaproxyBackend], Optional[V1Pod]]]:
379
+ """Returns tuples of matching (backend, pod) pairs, as matched by IP. Each backend will be listed exactly
380
+ once. If a backend does not match with a pod, (backend, None) will be included.
381
+ If a pod's IP does not match with any backends, (None, pod) will be included.
382
+
383
+ :param backends: An iterable of haproxy backend dictionaries, e.g. the list returned by
384
+ smartstack_tools.get_multiple_backends.
385
+ :param pods: An iterable of V1Pod objects.
386
+ """
387
+
388
+ # { ip : [backend1, backend2], ... }
389
+ backends_by_ip: DefaultDict[str, List[HaproxyBackend]] = collections.defaultdict(
390
+ list
391
+ )
392
+ backend_pod_pairs = []
393
+
394
+ for backend in backends:
395
+ ip, port, _ = ip_port_hostname_from_svname(backend["svname"])
396
+ backends_by_ip[ip].append(backend)
397
+
398
+ for pod in pods:
399
+ ip = pod.status.pod_ip
400
+ for backend in backends_by_ip.pop(ip, [None]):
401
+ backend_pod_pairs.append((backend, pod))
402
+
403
+ # we've been popping in the above loop, so anything left didn't match a k8s pod.
404
+ for backends in backends_by_ip.values():
405
+ for backend in backends:
406
+ backend_pod_pairs.append((backend, None))
407
+
408
+ return backend_pod_pairs
409
+
410
+
411
+ _MesosSlaveDict = TypeVar(
412
+ "_MesosSlaveDict", bound=Dict
413
+ ) # no type has been defined in mesos_tools for these yet.
414
+
415
+
416
+ class DiscoveredHost(NamedTuple):
417
+ hostname: str
418
+ pool: str
419
+
420
+
421
+ class ServiceDiscoveryProvider(abc.ABC):
422
+
423
+ NAME = "..."
424
+
425
+ @abc.abstractmethod
426
+ def get_replication_for_all_services(self, hostname: str) -> Dict[str, int]:
427
+ ...
428
+
429
+
430
+ class SmartstackServiceDiscovery(ServiceDiscoveryProvider):
431
+
432
+ NAME = "Smartstack"
433
+
434
+ def __init__(self, system_paasta_config: SystemPaastaConfig) -> None:
435
+ self._synapse_port = system_paasta_config.get_synapse_port()
436
+ self._synapse_haproxy_url_format = (
437
+ system_paasta_config.get_synapse_haproxy_url_format()
438
+ )
439
+
440
+ def get_replication_for_all_services(self, hostname: str) -> Dict[str, int]:
441
+ return get_replication_for_all_services(
442
+ synapse_host=hostname,
443
+ synapse_port=self._synapse_port,
444
+ synapse_haproxy_url_format=self._synapse_haproxy_url_format,
445
+ )
446
+
447
+
448
+ class EnvoyServiceDiscovery(ServiceDiscoveryProvider):
449
+
450
+ NAME = "Envoy"
451
+
452
+ def __init__(self, system_paasta_config: SystemPaastaConfig) -> None:
453
+ self._envoy_admin_port = system_paasta_config.get_envoy_admin_port()
454
+ self._envoy_admin_endpoint_format = (
455
+ system_paasta_config.get_envoy_admin_endpoint_format()
456
+ )
457
+
458
+ def get_replication_for_all_services(self, hostname: str) -> Dict[str, int]:
459
+ return envoy_tools.get_replication_for_all_services(
460
+ envoy_host=hostname,
461
+ envoy_admin_port=self._envoy_admin_port,
462
+ envoy_admin_endpoint_format=self._envoy_admin_endpoint_format,
463
+ )
464
+
465
+
466
+ def get_service_discovery_providers(
467
+ system_paasta_config: SystemPaastaConfig,
468
+ ) -> List[ServiceDiscoveryProvider]:
469
+ providers: List[ServiceDiscoveryProvider] = []
470
+ for name, _ in system_paasta_config.get_service_discovery_providers().items():
471
+ if name == "smartstack":
472
+ providers.append(SmartstackServiceDiscovery(system_paasta_config))
473
+ elif name == "envoy":
474
+ providers.append(EnvoyServiceDiscovery(system_paasta_config))
475
+ else:
476
+ log.warn("unknown provider")
477
+ return providers
478
+
479
+
480
+ class BaseReplicationChecker(ReplicationChecker):
481
+ """Base class for checking replication. Extendable for different frameworks.
482
+
483
+ Optimized for multiple queries. Gets the list of backends from service
484
+ discovery provider only once per location and reuse it in all subsequent
485
+ calls of BaseReplicationChecker.get_replication_for_instance().
486
+
487
+ get_allowed_locations_and_hosts must be implemented in sub class
488
+
489
+ A list of service discovery providers to collect information about
490
+ instances and their status must be provided as
491
+ `service_discovery_providers`.
492
+ """
493
+
494
+ def __init__(
495
+ self,
496
+ system_paasta_config: SystemPaastaConfig,
497
+ service_discovery_providers: Iterable[ServiceDiscoveryProvider],
498
+ ) -> None:
499
+ self._system_paasta_config = system_paasta_config
500
+ self._cache: Dict[Tuple[str, str], Dict[str, int]] = {}
501
+ self._service_discovery_providers = service_discovery_providers
502
+
503
+ @abc.abstractmethod
504
+ def get_allowed_locations_and_hosts(
505
+ self, instance_config: LongRunningServiceConfig
506
+ ) -> Dict[str, Sequence[DiscoveredHost]]:
507
+ ...
508
+
509
+ def get_replication_for_instance(
510
+ self, instance_config: LongRunningServiceConfig
511
+ ) -> Dict[str, Dict[str, Dict[str, int]]]:
512
+ """Returns the number of registered instances in each discoverable
513
+ location for each service dicrovery provider.
514
+
515
+ :param instance_config: An instance of LongRunningServiceConfig.
516
+ :returns: a dict {'service_discovery_provider': {'location_type': {'service.instance': int}}}
517
+ """
518
+ replication_infos = {}
519
+ for provider in self._service_discovery_providers:
520
+ replication_info = {}
521
+ attribute_host_dict = self.get_allowed_locations_and_hosts(instance_config)
522
+ instance_pool = instance_config.get_pool()
523
+ for location, hosts in attribute_host_dict.items():
524
+ # Try to get information from all available hosts in the pool before giving up
525
+ hostnames = self.get_hostnames_in_pool(hosts, instance_pool)
526
+ for hostname in hostnames:
527
+ try:
528
+ replication_info[location] = self._get_replication_info(
529
+ location, hostname, instance_config, provider
530
+ )
531
+ break
532
+ except Exception as e:
533
+ log.warn(
534
+ f"Error while getting replication info for {location} from {hostname}: {e}"
535
+ )
536
+ if hostname == hostnames[-1]:
537
+ # Last hostname failed, giving up
538
+ raise
539
+ replication_infos[provider.NAME] = replication_info
540
+ return replication_infos
541
+
542
+ def get_first_host_in_pool(self, hosts: Sequence[DiscoveredHost], pool: str) -> str:
543
+ for host in hosts:
544
+ if host.pool == pool:
545
+ return host.hostname
546
+ return hosts[0].hostname
547
+
548
+ def get_hostname_in_pool(self, hosts: Sequence[DiscoveredHost], pool: str) -> str:
549
+ return random.choice(self.get_hostnames_in_pool(hosts, pool))
550
+
551
+ def get_hostnames_in_pool(
552
+ self, hosts: Sequence[DiscoveredHost], pool: str
553
+ ) -> Sequence[str]:
554
+ hostnames = []
555
+ for host in hosts:
556
+ if host.pool == pool:
557
+ hostnames.append(host.hostname)
558
+ if len(hostnames) == 0:
559
+ hostnames.append(hosts[0].hostname)
560
+ return hostnames
561
+
562
+ def _get_replication_info(
563
+ self,
564
+ location: str,
565
+ hostname: str,
566
+ instance_config: LongRunningServiceConfig,
567
+ provider: ServiceDiscoveryProvider,
568
+ ) -> Dict[str, int]:
569
+ """Returns service.instance and the number of instances registered in smartstack
570
+ at the location as a dict.
571
+
572
+ :param location: A string that identifies a habitat, a region and etc.
573
+ :param hostname: A mesos slave hostname to read replication information from.
574
+ :param instance_config: An instance of LongRunningServiceConfig.
575
+ :returns: A dict {"service.instance": number_of_instances}.
576
+ """
577
+ full_name = compose_job_id(instance_config.service, instance_config.instance)
578
+ key = (location, provider.NAME)
579
+ replication_info = self._cache.get(key)
580
+ if replication_info is None:
581
+ replication_info = provider.get_replication_for_all_services(hostname)
582
+ self._cache[key] = replication_info
583
+ return {full_name: replication_info[full_name]}
584
+
585
+
586
+ class KubeSmartstackEnvoyReplicationChecker(BaseReplicationChecker):
587
+ def __init__(
588
+ self, nodes: Sequence[V1Node], system_paasta_config: SystemPaastaConfig
589
+ ) -> None:
590
+ self.nodes = nodes
591
+ super().__init__(
592
+ system_paasta_config=system_paasta_config,
593
+ service_discovery_providers=get_service_discovery_providers(
594
+ system_paasta_config
595
+ ),
596
+ )
597
+
598
+ def get_allowed_locations_and_hosts(
599
+ self, instance_config: LongRunningServiceConfig
600
+ ) -> Dict[str, Sequence[DiscoveredHost]]:
601
+ discover_location_type = kubernetes_tools.load_service_namespace_config(
602
+ service=instance_config.service,
603
+ namespace=instance_config.get_nerve_namespace(),
604
+ soa_dir=instance_config.soa_dir,
605
+ ).get_discover()
606
+
607
+ attribute_to_nodes = kubernetes_tools.get_nodes_grouped_by_attribute(
608
+ nodes=self.nodes, attribute=discover_location_type
609
+ )
610
+ ret: Dict[str, Sequence[DiscoveredHost]] = {}
611
+ for attr, nodes in attribute_to_nodes.items():
612
+ ret[attr] = [
613
+ DiscoveredHost(
614
+ hostname=node.metadata.labels["yelp.com/hostname"],
615
+ pool=node.metadata.labels["yelp.com/pool"],
616
+ )
617
+ for node in nodes
618
+ ]
619
+ return ret
620
+
621
+
622
+ def build_smartstack_location_dict(
623
+ location: str,
624
+ matched_backends_and_tasks: List[
625
+ Tuple[
626
+ Optional[HaproxyBackend],
627
+ Optional[V1Pod],
628
+ ]
629
+ ],
630
+ should_return_individual_backends: bool = False,
631
+ ) -> MutableMapping[str, Any]:
632
+ running_backends_count = 0
633
+ backends = []
634
+ for backend, task in matched_backends_and_tasks:
635
+ if backend is None:
636
+ continue
637
+ if backend_is_up(backend):
638
+ running_backends_count += 1
639
+ if should_return_individual_backends:
640
+ backends.append(build_smartstack_backend_dict(backend, task))
641
+
642
+ return {
643
+ "name": location,
644
+ "running_backends_count": running_backends_count,
645
+ "backends": backends,
646
+ }
647
+
648
+
649
+ def build_smartstack_backend_dict(
650
+ smartstack_backend: HaproxyBackend,
651
+ task: Union[V1Pod],
652
+ ) -> MutableMapping[str, Any]:
653
+ svname = smartstack_backend["svname"]
654
+ if isinstance(task, V1Pod):
655
+ node_hostname = svname.split("_")[0]
656
+ pod_ip = svname.split("_")[1].split(":")[0]
657
+ hostname = f"{node_hostname}:{pod_ip}"
658
+ else:
659
+ hostname = svname.split("_")[0]
660
+ port = svname.split("_")[-1].split(":")[-1]
661
+
662
+ smartstack_backend_dict = {
663
+ "hostname": hostname,
664
+ "port": int(port),
665
+ "status": smartstack_backend["status"],
666
+ "check_status": smartstack_backend["check_status"],
667
+ "check_code": smartstack_backend["check_code"],
668
+ "last_change": int(smartstack_backend["lastchg"]),
669
+ "has_associated_task": task is not None,
670
+ }
671
+
672
+ check_duration = smartstack_backend["check_duration"]
673
+ if check_duration:
674
+ smartstack_backend_dict["check_duration"] = int(check_duration)
675
+
676
+ return smartstack_backend_dict