def test_main_mesos(): with mock.patch( "paasta_tools.check_services_replication_tools.check_services_replication", autospec=True, ) as mock_check_services_replication, mock.patch( "paasta_tools.check_services_replication_tools.parse_args", autospec=True ) as mock_parse_args, mock.patch( "paasta_tools.check_services_replication_tools.get_mesos_tasks_and_slaves", autospec=True, return_value=([mock.Mock()], [mock.Mock()]), ), mock.patch( "paasta_tools.check_services_replication_tools.load_system_paasta_config", autospec=True, ) as mock_load_system_paasta_config, mock.patch( "paasta_tools.check_services_replication_tools.yelp_meteorite", autospec=True, ) as mock_yelp_meteorite, mock.patch( "paasta_tools.check_services_replication_tools.sys.exit", autospec=True, ) as mock_sys_exit: mock_parse_args.return_value.under_replicated_crit_pct = 5 mock_parse_args.return_value.min_count_critical = 1 mock_parse_args.return_value.dry_run = False mock_check_services_replication.return_value = (6, 100) check_services_replication_tools.main( instance_type_class=None, check_service_replication=None, namespace=None, mesos=True, ) assert mock_check_services_replication.called mock_yelp_meteorite.create_gauge.assert_called_once_with( "paasta.pct_services_under_replicated", { "paasta_cluster": mock_load_system_paasta_config.return_value.get_cluster. return_value, "scheduler": "mesos", }, ) mock_gauge = mock_yelp_meteorite.create_gauge.return_value mock_gauge.set.assert_called_once_with(6) mock_sys_exit.assert_called_once_with(2)
def test_main_kubernetes(): with mock.patch( "paasta_tools.check_services_replication_tools.check_services_replication", autospec=True, ) as mock_check_services_replication, mock.patch( "paasta_tools.check_services_replication_tools.parse_args", autospec=True ) as mock_parse_args, mock.patch( "paasta_tools.check_services_replication_tools.get_kubernetes_pods_and_nodes", autospec=True, return_value=([mock.Mock()], [mock.Mock()]), ), mock.patch( "paasta_tools.check_services_replication_tools.load_system_paasta_config", autospec=True, ) as mock_load_system_paasta_config, mock.patch( "paasta_tools.check_services_replication_tools.yelp_meteorite", autospec=True, ) as mock_yelp_meteorite, mock.patch( "paasta_tools.check_services_replication_tools.sys.exit", autospec=True, ) as mock_sys_exit: mock_parse_args.return_value.under_replicated_crit_pct = 10 mock_parse_args.return_value.under_replicated_warn_pct = 5 mock_check_services_replication.return_value = 6 check_services_replication_tools.main( instance_type_class=None, check_service_replication=None, namespace="baz", ) assert mock_check_services_replication.called mock_yelp_meteorite.create_gauge.assert_called_once_with( "paasta.pct_services_under_replicated", { "paasta_cluster": mock_load_system_paasta_config.return_value.get_cluster.return_value, "scheduler": "kubernetes", }, ) mock_gauge = mock_yelp_meteorite.create_gauge.return_value mock_gauge.set.assert_called_once_with( mock_check_services_replication.return_value ) mock_sys_exit.assert_called_once_with(1)
), check_under_replication( instance_config=instance_config, expected_count=taskmanagers_expected_cnt, num_available=num_healthy_taskmanagers, sub_component="taskmanager", ), check_under_registered_taskmanagers( instance_config=instance_config, expected_count=taskmanagers_expected_cnt, ), ] output = "\n########\n".join([r[1] for r in results]) if any(r[0] for r in results): log.error(output) status = pysensu_yelp.Status.CRITICAL else: log.info(output) status = pysensu_yelp.Status.OK send_replication_event(instance_config=instance_config, status=status, output=output) if __name__ == "__main__": main( flink_tools.FlinkDeploymentConfig, check_flink_service_health, namespace="paasta-flinks", )
num_healthy_taskmanagers = healthy_flink_containers_cnt(si_pods, "taskmanager") # TBD: check cnt according to Flink monitoring_tools.send_replication_event_if_under_replication( instance_config=instance_config, expected_count=1, num_available=num_healthy_supervisors, sub_component="supervisor", ) monitoring_tools.send_replication_event_if_under_replication( instance_config=instance_config, expected_count=1, num_available=num_healthy_jobmanagers, sub_component="jobmanager", ) monitoring_tools.send_replication_event_if_under_replication( instance_config=instance_config, expected_count=taskmanagers_expected_cnt, num_available=num_healthy_taskmanagers, sub_component="taskmanager", ) if __name__ == "__main__": main( flink_tools.FlinkDeploymentConfig, check_flink_service_replication, namespace="paasta-flinks", )
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """ Usage: ./check_cassandracluster_services_replication.py [options] """ import logging from paasta_tools import cassandracluster_tools from paasta_tools.check_kubernetes_services_replication import ( check_kubernetes_pod_replication, ) from paasta_tools.check_services_replication_tools import main log = logging.getLogger(__name__) if __name__ == "__main__": main( cassandracluster_tools.CassandraClusterDeploymentConfig, check_kubernetes_pod_replication, namespace="paasta-cassandraclusters", )
proxy_port = get_proxy_port_for_instance(instance_config) registrations = instance_config.get_registrations() # if the primary registration does not match the service_instance name then # the best we can do is check marathon for replication (for now). if proxy_port is not None and registrations[0] == instance_config.job_id: is_well_replicated = monitoring_tools.check_replication_for_instance( instance_config=instance_config, expected_count=expected_count, replication_checker=replication_checker, dry_run=dry_run, ) return is_well_replicated else: check_healthy_marathon_tasks_for_service_instance( instance_config=instance_config, expected_count=expected_count, all_tasks=all_tasks_or_pods, dry_run=dry_run, ) return None if __name__ == "__main__": main( instance_type_class=marathon_tools.MarathonServiceConfig, check_service_replication=check_service_replication, namespace=None, # not relevant for mesos mesos=True, )
expected_count = instance_config.get_instances() log.info("Expecting %d total tasks for %s" % (expected_count, instance_config.job_id)) proxy_port = get_proxy_port_for_instance(instance_config) registrations = instance_config.get_registrations() # if the primary registration does not match the service_instance name then # the best we can do is check k8s for replication (for now). if proxy_port is not None and registrations[0] == instance_config.job_id: is_well_replicated = monitoring_tools.check_smartstack_replication_for_instance( instance_config=instance_config, expected_count=expected_count, smartstack_replication_checker=smartstack_replication_checker, ) return is_well_replicated else: check_healthy_kubernetes_tasks_for_service_instance( instance_config=instance_config, expected_count=expected_count, all_pods=all_tasks_or_pods, ) return None if __name__ == "__main__": main( kubernetes_tools.KubernetesDeploymentConfig, check_kubernetes_pod_replication, namespace="paasta", )