code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def makefile_responds_to(target):
"""Runs `make --question <target>` to detect if a makefile responds to the
specified target."""
# According to http://www.gnu.org/software/make/manual/make.html#index-exit-status-of-make,
# 0 means OK, 1 means the target is not up to date, and 2 means error
returnco... | Runs `make --question <target>` to detect if a makefile responds to the
specified target. | makefile_responds_to | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def makefile_check():
"""Detects if you have a makefile and runs some sanity tests against
it to ensure it is paasta-ready"""
makefile_path = is_file_in_dir("Makefile", os.getcwd())
if makefile_path:
print(PaastaCheckMessages.MAKEFILE_FOUND)
if makefile_has_a_tab(makefile_path):
... | Detects if you have a makefile and runs some sanity tests against
it to ensure it is paasta-ready | makefile_check | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def get_deploy_groups_used_by_framework(instance_type, service, soa_dir):
"""This is a kind of funny function that gets all the instances for specified
service and framework, and massages it into a form that matches up with what
deploy.yaml's steps look like. This is only so we can compare it 1-1
with w... | This is a kind of funny function that gets all the instances for specified
service and framework, and massages it into a form that matches up with what
deploy.yaml's steps look like. This is only so we can compare it 1-1
with what deploy.yaml has for linting.
:param instance_type: one of the entries in... | get_deploy_groups_used_by_framework | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def deployments_check(service, soa_dir):
"""Checks for consistency between deploy.yaml and the kubernetes/etc yamls"""
the_return = True
pipeline_deploy_groups = get_pipeline_deploy_groups(
service=service, soa_dir=soa_dir
)
framework_deploy_groups = {}
in_deploy_not_frameworks = set(pi... | Checks for consistency between deploy.yaml and the kubernetes/etc yamls | deployments_check | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def sensu_check(service, service_path, soa_dir):
"""Check whether monitoring.yaml exists in service directory,
and that the team name is declared.
:param service: name of service currently being examined
:param service_path: path to location of monitoring.yaml file"""
if is_file_in_dir("monitoring.... | Check whether monitoring.yaml exists in service directory,
and that the team name is declared.
:param service: name of service currently being examined
:param service_path: path to location of monitoring.yaml file | sensu_check | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def service_dir_check(service, soa_dir):
"""Check whether directory service exists in /nail/etc/services
:param service: string of service name we wish to inspect
"""
try:
validate_service_name(service, soa_dir)
print(PaastaCheckMessages.service_dir_found(service, soa_dir))
except No... | Check whether directory service exists in /nail/etc/services
:param service: string of service name we wish to inspect
| service_dir_check | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def smartstack_check(service, service_path, soa_dir):
"""Check whether smartstack.yaml exists in service directory, and the proxy
ports are declared. Print appropriate message depending on outcome.
:param service: name of service currently being examined
:param service_path: path to location of smarts... | Check whether smartstack.yaml exists in service directory, and the proxy
ports are declared. Print appropriate message depending on outcome.
:param service: name of service currently being examined
:param service_path: path to location of smartstack.yaml file | smartstack_check | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def paasta_check(args):
"""Analyze the service in the PWD to determine if it is paasta ready
:param args: argparse.Namespace obj created from sys.args by cli"""
soa_dir = args.yelpsoa_config_root
service = figure_out_service_name(args, soa_dir)
service_path = os.path.join(soa_dir, service)
serv... | Analyze the service in the PWD to determine if it is paasta ready
:param args: argparse.Namespace obj created from sys.args by cli | paasta_check | python | Yelp/paasta | paasta_tools/cli/cmds/check.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/check.py | Apache-2.0 |
def paasta_list(args):
"""Print a list of Yelp services currently running
:param args: argparse.Namespace obj created from sys.args by cli"""
if args.print_instances:
services = list_service_instances(args.soa_dir)
elif args.all:
services = list_services(args.soa_dir)
else:
s... | Print a list of Yelp services currently running
:param args: argparse.Namespace obj created from sys.args by cli | paasta_list | python | Yelp/paasta | paasta_tools/cli/cmds/list.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/list.py | Apache-2.0 |
def perform_http_healthcheck(url, timeout):
"""Returns true if healthcheck on url succeeds, false otherwise
:param url: the healthcheck url
:param timeout: timeout in seconds
:returns: True if healthcheck succeeds within number of seconds specified by timeout, false otherwise
"""
try:
w... | Returns true if healthcheck on url succeeds, false otherwise
:param url: the healthcheck url
:param timeout: timeout in seconds
:returns: True if healthcheck succeeds within number of seconds specified by timeout, false otherwise
| perform_http_healthcheck | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def perform_tcp_healthcheck(url, timeout):
"""Returns true if successfully connects to host and port, false otherwise
:param url: the healthcheck url (in the form tcp://host:port)
:param timeout: timeout in seconds
:returns: True if healthcheck succeeds within number of seconds specified by timeout, fa... | Returns true if successfully connects to host and port, false otherwise
:param url: the healthcheck url (in the form tcp://host:port)
:param timeout: timeout in seconds
:returns: True if healthcheck succeeds within number of seconds specified by timeout, false otherwise
| perform_tcp_healthcheck | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def perform_cmd_healthcheck(docker_client, container_id, command, timeout):
"""Returns true if return code of command is 0 when executed inside container, false otherwise
:param docker_client: Docker client object
:param container_id: Docker container id
:param command: command to execute
:param ti... | Returns true if return code of command is 0 when executed inside container, false otherwise
:param docker_client: Docker client object
:param container_id: Docker container id
:param command: command to execute
:param timeout: timeout in seconds
:returns: True if command exits with return code 0, f... | perform_cmd_healthcheck | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def run_healthcheck_on_container(
docker_client, container_id, healthcheck_mode, healthcheck_data, timeout
):
"""Performs healthcheck on a container
:param container_id: Docker container id
:param healthcheck_mode: one of 'http', 'https', 'tcp', or 'cmd'
:param healthcheck_data: a URL when healthch... | Performs healthcheck on a container
:param container_id: Docker container id
:param healthcheck_mode: one of 'http', 'https', 'tcp', or 'cmd'
:param healthcheck_data: a URL when healthcheck_mode is 'http[s]' or 'tcp', a command if healthcheck_mode is 'cmd'
:param timeout: timeout in seconds for individ... | run_healthcheck_on_container | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def simulate_healthcheck_on_service(
instance_config,
docker_client,
container_id,
healthcheck_mode,
healthcheck_data,
healthcheck_enabled,
):
"""Simulates Marathon-style healthcheck on given service if healthcheck is enabled
:param instance_config: service manifest
:param docker_cl... | Simulates Marathon-style healthcheck on given service if healthcheck is enabled
:param instance_config: service manifest
:param docker_client: Docker client object
:param container_id: Docker container id
:param healthcheck_data: tuple url to healthcheck
:param healthcheck_enabled: boolean
:ret... | simulate_healthcheck_on_service | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def docker_pull_image(docker_url):
"""Pull an image via ``docker pull``. Uses the actual pull command instead of the python
bindings due to the docker auth/registry transition. Once we are past Docker 1.6
we can use better credential management, but for now this function assumes the
user running the com... | Pull an image via ``docker pull``. Uses the actual pull command instead of the python
bindings due to the docker auth/registry transition. Once we are past Docker 1.6
we can use better credential management, but for now this function assumes the
user running the command has already been authorized for the r... | docker_pull_image | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def get_container_id(docker_client, container_name):
"""Use 'docker_client' to find the container we started, identifiable by
its 'container_name'. If we can't find the id, raise
LostContainerException.
"""
containers = docker_client.containers(all=False)
for container in containers:
if ... | Use 'docker_client' to find the container we started, identifiable by
its 'container_name'. If we can't find the id, raise
LostContainerException.
| get_container_id | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def get_local_run_environment_vars(instance_config, port0, framework):
"""Returns a dictionary of environment variables to simulate what would be available to
a paasta service running in a container"""
hostname = socket.getfqdn()
docker_image = instance_config.get_docker_image()
if docker_image == "... | Returns a dictionary of environment variables to simulate what would be available to
a paasta service running in a container | get_local_run_environment_vars | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def assume_aws_role(
instance_config: InstanceConfig,
service: str,
assume_role_arn: str,
assume_pod_identity: bool,
use_okta_role: bool,
aws_account: str,
) -> AWSSessionCreds:
"""Runs AWS cli to assume into the correct role, then extract and return the ENV variables from that session"""
... | Runs AWS cli to assume into the correct role, then extract and return the ENV variables from that session | assume_aws_role | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def run_docker_container(
docker_client,
service,
instance,
docker_url,
volumes,
interactive,
command,
healthcheck,
healthcheck_only,
user_port,
instance_config,
secret_provider_name,
soa_dir=DEFAULT_SOA_DIR,
dry_run=False,
json_dict=False,
framework=None,... | docker-py has issues running a container with a TTY attached, so for
consistency we execute 'docker run' directly in both interactive and
non-interactive modes.
In non-interactive mode when the run is complete, stop the container and
remove it (with docker-py).
| run_docker_container | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def format_command_for_type(command, instance_type, date):
"""
Given an instance_type, return a function that appropriately formats
the command to be run.
"""
if instance_type == "tron":
interpolated_command = parse_time_variables(command, date)
return interpolated_command
else:
... |
Given an instance_type, return a function that appropriately formats
the command to be run.
| format_command_for_type | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def configure_and_run_docker_container(
docker_client,
docker_url,
docker_sha,
service,
instance,
cluster,
system_paasta_config,
args,
assume_role_aws_account,
pull_image=False,
dry_run=False,
):
"""
Run Docker container by image hash with args set in command line.
... |
Run Docker container by image hash with args set in command line.
Function prints the output of run command in stdout.
| configure_and_run_docker_container | python | Yelp/paasta | paasta_tools/cli/cmds/local_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/local_run.py | Apache-2.0 |
def build_component_descriptions(components: Mapping[str, Mapping[str, Any]]) -> str:
"""Returns a colored description string for every log component
based on its help attribute"""
output = []
for k, v in components.items():
output.append(" {}: {}".format(v["color"](k), v["help"]))
return... | Returns a colored description string for every log component
based on its help attribute | build_component_descriptions | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def check_timestamp_in_range(
timestamp: datetime.datetime,
start_time: datetime.datetime,
end_time: datetime.datetime,
) -> bool:
"""A convenience function to check if a datetime.datetime timestamp is within the given start and end times,
returns true if start_time or end_time is None
:param t... | A convenience function to check if a datetime.datetime timestamp is within the given start and end times,
returns true if start_time or end_time is None
:param timestamp: The timestamp to check
:param start_time: The start of the interval
:param end_time: The end of the interval
:return: True if ti... | check_timestamp_in_range | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def paasta_log_line_passes_filter(
line: str,
levels: Sequence[str],
service: str,
components: Iterable[str],
clusters: Sequence[str],
instances: List[str],
pods: Iterable[str] = None,
start_time: datetime.datetime = None,
end_time: datetime.datetime = None,
) -> bool:
"""Given a... | Given a (JSON-formatted) log line, return True if the line should be
displayed given the provided levels, components, and clusters; return False
otherwise.
NOTE: Pods are optional as services that use Mesos do not operate with pods.
| paasta_log_line_passes_filter | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def extract_utc_timestamp_from_log_line(line: str) -> datetime.datetime:
"""
Extracts the timestamp from a log line of the format "<timestamp> <other data>" and returns a UTC datetime object
or None if it could not parse the line
"""
# Extract ISO 8601 date per http://www.pelagodesign.com/blog/2009/... |
Extracts the timestamp from a log line of the format "<timestamp> <other data>" and returns a UTC datetime object
or None if it could not parse the line
| extract_utc_timestamp_from_log_line | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def print_log(
line: str,
requested_levels: Sequence[str],
raw_mode: bool = False,
strip_headers: bool = False,
) -> None:
"""Mostly a stub to ease testing. Eventually this may do some formatting or
something.
"""
if raw_mode:
# suppress trailing newline since scribereader alread... | Mostly a stub to ease testing. Eventually this may do some formatting or
something.
| print_log | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def prettify_timestamp(timestamp: datetime.datetime) -> str:
"""Returns more human-friendly form of 'timestamp' without microseconds and
in local time.
"""
dt = isodate.parse_datetime(timestamp)
pretty_timestamp = datetime_from_utc_to_local(dt)
return pretty_timestamp.strftime("%Y-%m-%d %H:%M:%S... | Returns more human-friendly form of 'timestamp' without microseconds and
in local time.
| prettify_timestamp | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def prettify_log_line(
line: str, requested_levels: Sequence[str], strip_headers: bool
) -> str:
"""Given a line from the log, which is expected to be JSON and have all the
things we expect, return a pretty formatted string containing relevant values.
"""
try:
parsed_line = json.loads(line)
... | Given a line from the log, which is expected to be JSON and have all the
things we expect, return a pretty formatted string containing relevant values.
| prettify_log_line | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def register_log_reader(name):
"""Returns a decorator that registers a log reader class at a given name
so get_log_reader_classes can find it."""
def outer(log_reader_class):
_log_reader_classes[name] = log_reader_class
return log_reader_class
return outer | Returns a decorator that registers a log reader class at a given name
so get_log_reader_classes can find it. | register_log_reader | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def run_code_over_scribe_envs(
self,
clusters: Sequence[str],
components: Iterable[str],
callback: Callable[..., None],
) -> None:
"""Iterates over the scribe environments for a given set of clusters and components, executing
functions for each component
:par... | Iterates over the scribe environments for a given set of clusters and components, executing
functions for each component
:param clusters: The set of clusters
:param components: The set of components
:param callback: The callback function. Gets called with (component_name, stream_info, s... | run_code_over_scribe_envs | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def tail_logs(
self,
service: str,
levels: Sequence[str],
components: Iterable[str],
clusters: Sequence[str],
instances: List[str],
pods: Iterable[str] = None,
raw_mode: bool = False,
strip_headers: bool = False,
) -> None:
"""Sergeant ... | Sergeant function for spawning off all the right log tailing functions.
NOTE: This function spawns concurrent processes and doesn't necessarily
worry about cleaning them up! That's because we expect to just exit the
main process when this function returns (as main() does). Someone calling
... | tail_logs | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def scribe_tail(
self,
scribe_env: str,
stream_name: str,
service: str,
levels: Sequence[str],
components: Iterable[str],
clusters: Sequence[str],
instances: List[str],
pods: Iterable[str],
queue: Queue,
filter_fn: Callable,
... | Creates a scribetailer for a particular environment.
When it encounters a line that it should report, it sticks it into the
provided queue.
This code is designed to run in a thread as spawned by tail_paasta_logs().
| scribe_tail | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def determine_scribereader_envs(
self, components: Iterable[str], cluster: str
) -> Set[str]:
"""Returns a list of environments that scribereader needs to connect
to based on a given list of components and the cluster involved.
Some components are in certain environments, regardless... | Returns a list of environments that scribereader needs to connect
to based on a given list of components and the cluster involved.
Some components are in certain environments, regardless of the cluster.
Some clusters do not match up with the scribe environment names, so
we figure that o... | determine_scribereader_envs | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def cluster_to_scribe_env(self, cluster: str) -> str:
"""Looks up the particular scribe env associated with a given paasta cluster.
Scribe has its own "environment" key, which doesn't always map 1:1 with our
cluster names, so we have to maintain a manual mapping.
This mapping is deploy... | Looks up the particular scribe env associated with a given paasta cluster.
Scribe has its own "environment" key, which doesn't always map 1:1 with our
cluster names, so we have to maintain a manual mapping.
This mapping is deployed as a config file via puppet as part of the public
conf... | cluster_to_scribe_env | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def scribe_env_to_locations(scribe_env) -> Mapping[str, Any]:
"""Converts a scribe environment to a dictionary of locations. The
return value is meant to be used as kwargs for `scribereader.get_tail_host_and_port`.
"""
locations = {"ecosystem": None, "region": None, "superregion": None}
if scribe_en... | Converts a scribe environment to a dictionary of locations. The
return value is meant to be used as kwargs for `scribereader.get_tail_host_and_port`.
| scribe_env_to_locations | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def generate_start_end_time(
from_string: str = "30m", to_string: str = None
) -> Tuple[datetime.datetime, datetime.datetime]:
"""Parses the --from and --to command line arguments to create python
datetime objects representing the start and end times for log retrieval
:param from_string: The --from arg... | Parses the --from and --to command line arguments to create python
datetime objects representing the start and end times for log retrieval
:param from_string: The --from argument, defaults to 30 minutes
:param to_string: The --to argument, defaults to the time right now
:return: A tuple containing star... | generate_start_end_time | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def paasta_logs(args: argparse.Namespace) -> int:
"""Print the logs for as Paasta service.
:param args: argparse.Namespace obj created from sys.args by cli"""
soa_dir = args.soa_dir
service = figure_out_service_name(args, soa_dir)
clusters = args.cluster
if (
args.cluster is None
... | Print the logs for as Paasta service.
:param args: argparse.Namespace obj created from sys.args by cli | paasta_logs | python | Yelp/paasta | paasta_tools/cli/cmds/logs.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/logs.py | Apache-2.0 |
def can_run_metric_watcher_threads(
service: str,
soa_dir: str,
) -> bool:
"""
Cannot run slo and metric watcher threads together for now.
SLO Watcher Threads take precedence over metric watcher threads.
Metric Watcher Threads can run if there are no SLOs available.
"""
slo_files = get_f... |
Cannot run slo and metric watcher threads together for now.
SLO Watcher Threads take precedence over metric watcher threads.
Metric Watcher Threads can run if there are no SLOs available.
| can_run_metric_watcher_threads | python | Yelp/paasta | paasta_tools/cli/cmds/mark_for_deployment.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/mark_for_deployment.py | Apache-2.0 |
def get_slack_channel(self) -> str:
"""Safely get some slack channel to post to. Defaults to ``DEFAULT_SLACK_CHANNEL``.
Currently only uses the first slack channel available, and doesn't support
multi-channel notifications."""
if self.deploy_info.get("slack_notify", True):
tr... | Safely get some slack channel to post to. Defaults to ``DEFAULT_SLACK_CHANNEL``.
Currently only uses the first slack channel available, and doesn't support
multi-channel notifications. | get_slack_channel | python | Yelp/paasta | paasta_tools/cli/cmds/mark_for_deployment.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/mark_for_deployment.py | Apache-2.0 |
def paasta_pause_service_autoscaler(args):
"""With a given cluster and duration, pauses the paasta service autoscaler
in that cluster for duration minutes"""
if args.duration > MAX_PAUSE_DURATION:
if not args.force:
print(
"Specified duration: {d} longer than max: {m}".fo... | With a given cluster and duration, pauses the paasta service autoscaler
in that cluster for duration minutes | paasta_pause_service_autoscaler | python | Yelp/paasta | paasta_tools/cli/cmds/pause_service_autoscaler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/pause_service_autoscaler.py | Apache-2.0 |
def is_docker_image_already_in_registry(service: str, soa_dir: str, sha: str, image_version: Optional[str] = None) -> bool: # type: ignore
"""Verifies that docker image exists in the paasta registry.
:param service: name of the service
:param sha: git sha
:returns: True, False or raises requests.excep... | Verifies that docker image exists in the paasta registry.
:param service: name of the service
:param sha: git sha
:returns: True, False or raises requests.exceptions.RequestException
| is_docker_image_already_in_registry | python | Yelp/paasta | paasta_tools/cli/cmds/push_to_registry.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/push_to_registry.py | Apache-2.0 |
def get_versions_for_service(
service: str, deploy_groups: Collection[str], soa_dir: str
) -> Mapping[DeploymentVersion, Tuple[str, str]]:
"""Returns a dictionary of 2-tuples of the form (timestamp, deploy_group) for each version tuple of (deploy sha, image_version)"""
if service is None:
return {}
... | Returns a dictionary of 2-tuples of the form (timestamp, deploy_group) for each version tuple of (deploy sha, image_version) | get_versions_for_service | python | Yelp/paasta | paasta_tools/cli/cmds/rollback.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/rollback.py | Apache-2.0 |
def paasta_rollback(args: argparse.Namespace) -> int:
"""Call mark_for_deployment with rollback parameters
:param args: contains all the arguments passed onto the script: service,
deploy groups and sha. These arguments will be verified and passed onto
mark_for_deployment.
"""
soa_dir = args.soa... | Call mark_for_deployment with rollback parameters
:param args: contains all the arguments passed onto the script: service,
deploy groups and sha. These arguments will be verified and passed onto
mark_for_deployment.
| paasta_rollback | python | Yelp/paasta | paasta_tools/cli/cmds/rollback.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/rollback.py | Apache-2.0 |
def _add_and_update_args(parser: argparse.ArgumentParser):
"""common args for `add` and `update`."""
parser.add_argument(
"-p",
"--plain-text",
required=False,
type=str,
help="Optionally specify the secret as a command line argument",
)
parser.add_argument(
... | common args for `add` and `update`. | _add_and_update_args | python | Yelp/paasta | paasta_tools/cli/cmds/secret.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/secret.py | Apache-2.0 |
def get_docker_image(
args: argparse.Namespace, instance_config: InstanceConfig
) -> Optional[str]:
"""
Since the Docker image digest used to launch the Spark cluster is obtained by inspecting local
Docker images, we need to ensure that the Docker image exists locally or is pulled in all scenarios.
... |
Since the Docker image digest used to launch the Spark cluster is obtained by inspecting local
Docker images, we need to ensure that the Docker image exists locally or is pulled in all scenarios.
| get_docker_image | python | Yelp/paasta | paasta_tools/cli/cmds/spark_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/spark_run.py | Apache-2.0 |
def get_spark_env(
args: argparse.Namespace,
spark_conf_str: str,
aws_creds: Tuple[Optional[str], Optional[str], Optional[str]],
ui_port: str,
system_paasta_config: SystemPaastaConfig,
) -> Dict[str, str]:
"""Create the env config dict to configure on the docker container"""
spark_env = {}
... | Create the env config dict to configure on the docker container | get_spark_env | python | Yelp/paasta | paasta_tools/cli/cmds/spark_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/spark_run.py | Apache-2.0 |
def _calculate_docker_shared_memory_size(shm_size: Optional[str]) -> str:
"""In Order of preference:
1. Argument: --docker-shm-size
3. Default
"""
if shm_size:
return shm_size
return DEFAULT_DOCKER_SHM_SIZE | In Order of preference:
1. Argument: --docker-shm-size
3. Default
| _calculate_docker_shared_memory_size | python | Yelp/paasta | paasta_tools/cli/cmds/spark_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/spark_run.py | Apache-2.0 |
def build_and_push_docker_image(args: argparse.Namespace) -> Optional[str]:
"""
Build an image if the default Spark service image is not preferred.
The image needs to be pushed to a registry for the Spark executors
to pull.
"""
if not makefile_responds_to("cook-image"):
print(
... |
Build an image if the default Spark service image is not preferred.
The image needs to be pushed to a registry for the Spark executors
to pull.
| build_and_push_docker_image | python | Yelp/paasta | paasta_tools/cli/cmds/spark_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/spark_run.py | Apache-2.0 |
def update_args_from_tronfig(args: argparse.Namespace) -> Optional[Dict[str, str]]:
"""
Load and check the following config fields from the provided Tronfig.
- executor
- pool
- iam_role
- iam_role_provider
- force_spark_resource_configs
- max_runtime
- command
- ... |
Load and check the following config fields from the provided Tronfig.
- executor
- pool
- iam_role
- iam_role_provider
- force_spark_resource_configs
- max_runtime
- command
- env
- spark_args
Returns: environment variables dictionary or None if failed.
... | update_args_from_tronfig | python | Yelp/paasta | paasta_tools/cli/cmds/spark_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/spark_run.py | Apache-2.0 |
def make_mutate_refs_func(service_config, force_bounce, desired_state):
"""Create a function that will inform send_pack that we want to create tags
corresponding to the set of branches passed, with the given force_bounce
and desired_state parameters. These tags will point at the current tip of
the branc... | Create a function that will inform send_pack that we want to create tags
corresponding to the set of branches passed, with the given force_bounce
and desired_state parameters. These tags will point at the current tip of
the branch they associate with.
dulwich's send_pack wants a function that takes a d... | make_mutate_refs_func | python | Yelp/paasta | paasta_tools/cli/cmds/start_stop_restart.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/start_stop_restart.py | Apache-2.0 |
def paasta_start_or_stop(args, desired_state):
"""Requests a change of state to start or stop given branches of a service."""
soa_dir = args.soa_dir
pargs = apply_args_filters(args)
if len(pargs) == 0:
return 1
affected_services = {
s for service_list in pargs.values() for s in ser... | Requests a change of state to start or stop given branches of a service. | paasta_start_or_stop | python | Yelp/paasta | paasta_tools/cli/cmds/start_stop_restart.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/start_stop_restart.py | Apache-2.0 |
def get_actual_deployments(
service: str, soa_dir: str
) -> Mapping[str, DeploymentVersion]:
"""Given a service, return a dict of instances->DeploymentVersions"""
config_loader = PaastaServiceConfigLoader(service=service, soa_dir=soa_dir)
clusters = list_clusters(service=service, soa_dir=soa_dir)
ac... | Given a service, return a dict of instances->DeploymentVersions | get_actual_deployments | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def find_instance_types(status: Any) -> List[str]:
"""
find_instance_types finds the instance types from the status api response.
It iterates over all instance type registered in `INSTANCE_TYPE_WRITERS`.
:param status: paasta api status object
:return: the list of matching instance types
"""
... |
find_instance_types finds the instance types from the status api response.
It iterates over all instance type registered in `INSTANCE_TYPE_WRITERS`.
:param status: paasta api status object
:return: the list of matching instance types
| find_instance_types | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def report_status_for_cluster(
service: str,
cluster: str,
deploy_pipeline: Sequence[str],
actual_deployments: Mapping[str, DeploymentVersion],
instance_whitelist: Mapping[str, Type[InstanceConfig]],
system_paasta_config: SystemPaastaConfig,
lock: Lock,
verbose: int = 0,
new: bool = ... | With a given service and cluster, prints the status of the instances
in that cluster | report_status_for_cluster | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def report_invalid_whitelist_values(
whitelist: Iterable[str], items: Sequence[str], item_type: str
) -> str:
"""Warns the user if there are entries in ``whitelist`` which don't
correspond to any item in ``items``. Helps highlight typos.
"""
return_string = ""
bogus_entries = []
if whitelist... | Warns the user if there are entries in ``whitelist`` which don't
correspond to any item in ``items``. Helps highlight typos.
| report_invalid_whitelist_values | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def get_filters(
args,
) -> Sequence[Callable[[InstanceConfig], bool]]:
"""Figures out which filters to apply from an args object, and returns them
:param args: args object
:returns: list of functions that take an instance config and returns if the instance conf matches the filter
"""
filters =... | Figures out which filters to apply from an args object, and returns them
:param args: args object
:returns: list of functions that take an instance config and returns if the instance conf matches the filter
| get_filters | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def apply_args_filters(
args,
) -> Mapping[str, Mapping[str, Mapping[str, Type[InstanceConfig]]]]:
"""
Take an args object and returns the dict of cluster:service:instances
Currently, will filter by clusters, instances, services, and deploy_groups
If no instances are found, will print a message and ... |
Take an args object and returns the dict of cluster:service:instances
Currently, will filter by clusters, instances, services, and deploy_groups
If no instances are found, will print a message and try to find matching instances
for each service
:param args: args object containing attributes to fil... | apply_args_filters | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def paasta_status(args) -> int:
"""Print the status of a Yelp service running on PaaSTA.
:param args: argparse.Namespace obj created from sys.args by cli"""
soa_dir = args.soa_dir
system_paasta_config = load_system_paasta_config()
return_codes = [0]
lock = Lock()
tasks = []
clusters_ser... | Print the status of a Yelp service running on PaaSTA.
:param args: argparse.Namespace obj created from sys.args by cli | paasta_status | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def _backend_report(
normal_instance_count: int, up_backends: int, system_name: BackendType
) -> str:
"""Given that a service is in smartstack, this returns a human readable
report of the up backends"""
# TODO: Take into account a configurable threshold, PAASTA-1102
crit_threshold = 50
under_rep... | Given that a service is in smartstack, this returns a human readable
report of the up backends | _backend_report | python | Yelp/paasta | paasta_tools/cli/cmds/status.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/status.py | Apache-2.0 |
def get_schema_validator(file_type: str) -> Draft4Validator:
"""Get the correct schema to use for validation
:param file_type: what schema type should we validate against
"""
schema_path = f"schemas/{file_type}_schema.json"
autoscaling_path = "schemas/autoscaling_schema.json"
schema = pkgutil.g... | Get the correct schema to use for validation
:param file_type: what schema type should we validate against
| get_schema_validator | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def validate_rollback_bounds(
config: Dict[str, List[ConditionConfig]], file_loc: str
) -> bool:
"""
Ensure that at least one of upper_bound or lower_bound is set (and set to non-null values)
"""
errors = []
for source, queries in config.items():
for query in queries:
if not... |
Ensure that at least one of upper_bound or lower_bound is set (and set to non-null values)
| validate_rollback_bounds | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def validate_schema(file_path: str, file_type: str) -> bool:
"""Check if the specified config file has a valid schema
:param file_path: path to file to validate
:param file_type: what schema type should we validate against
"""
try:
validator = get_schema_validator(file_type)
except Exce... | Check if the specified config file has a valid schema
:param file_path: path to file to validate
:param file_type: what schema type should we validate against
| validate_schema | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def validate_all_schemas(service_path: str) -> bool:
"""Finds all recognized config files in service directory,
and validates their schema.
:param service_path: path to location of configuration files
"""
path = os.path.join(service_path, "**/*.yaml")
returncode = True
for file_name in gl... | Finds all recognized config files in service directory,
and validates their schema.
:param service_path: path to location of configuration files
| validate_all_schemas | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def check_service_path(service_path):
"""Check that the specified path exists and has yaml files
:param service_path: Path to directory that should contain yaml files
"""
if not service_path or not os.path.isdir(service_path):
print(
failure(
"%s is not a directory" ... | Check that the specified path exists and has yaml files
:param service_path: Path to directory that should contain yaml files
| check_service_path | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def get_service_path(service, soa_dir):
"""Determine the path of the directory containing the conf files
:param service: Name of service
:param soa_dir: Directory containing soa configs for all services
"""
if service:
service_path = os.path.join(soa_dir, service)
else:
if soa_d... | Determine the path of the directory containing the conf files
:param service: Name of service
:param soa_dir: Directory containing soa configs for all services
| get_service_path | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def path_to_soa_dir_service(service_path):
"""Split a service_path into its soa_dir and service name components"""
soa_dir = os.path.dirname(service_path)
service = os.path.basename(service_path)
return soa_dir, service | Split a service_path into its soa_dir and service name components | path_to_soa_dir_service | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def validate_unique_instance_names(service_path):
"""Check that the service does not use the same instance name more than once"""
soa_dir, service = path_to_soa_dir_service(service_path)
check_passed = True
for cluster in list_clusters(service, soa_dir):
service_instances = get_service_instance... | Check that the service does not use the same instance name more than once | validate_unique_instance_names | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def validate_autoscaling_configs(service_path: str) -> bool:
"""Validate new autoscaling configurations that are not validated by jsonschema for the service of interest.
:param service_path: Path to directory containing soa conf yaml files for service
"""
soa_dir, service = path_to_soa_dir_service(serv... | Validate new autoscaling configurations that are not validated by jsonschema for the service of interest.
:param service_path: Path to directory containing soa conf yaml files for service
| validate_autoscaling_configs | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def paasta_validate_soa_configs(
service: str, service_path: str, verbose: bool = False
) -> bool:
"""Analyze the service in service_path to determine if the conf files are valid
:param service_path: Path to directory containing soa conf yaml files for service
"""
if not check_service_path(service_... | Analyze the service in service_path to determine if the conf files are valid
:param service_path: Path to directory containing soa conf yaml files for service
| paasta_validate_soa_configs | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def paasta_validate(args):
"""Generate a service_path from the provided args and call paasta_validate_soa_configs
:param args: argparse.Namespace obj created from sys.args by cli
"""
service_path = get_service_path(args.service, args.yelpsoa_config_root)
service = args.service or guess_service_name... | Generate a service_path from the provided args and call paasta_validate_soa_configs
:param args: argparse.Namespace obj created from sys.args by cli
| paasta_validate | python | Yelp/paasta | paasta_tools/cli/cmds/validate.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/validate.py | Apache-2.0 |
def get_latest_marked_version(
git_url: str, deploy_group: str
) -> Optional[DeploymentVersion]:
"""Return the latest marked for deployment version or None"""
# TODO: correct this function for new tag format
refs = list_remote_refs(git_url)
_, sha, image_version = get_latest_deployment_tag(refs, dep... | Return the latest marked for deployment version or None | get_latest_marked_version | python | Yelp/paasta | paasta_tools/cli/cmds/wait_for_deployment.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/wait_for_deployment.py | Apache-2.0 |
def validate_version_is_latest(
version: DeploymentVersion, git_url: str, deploy_group: str, service: str
):
"""Verify if the requested version is the latest marked for deployment.
Raise exception when the provided version is not the latest
marked for deployment in 'deploy_group' for 'service'.
""... | Verify if the requested version is the latest marked for deployment.
Raise exception when the provided version is not the latest
marked for deployment in 'deploy_group' for 'service'.
| validate_version_is_latest | python | Yelp/paasta | paasta_tools/cli/cmds/wait_for_deployment.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/wait_for_deployment.py | Apache-2.0 |
def validate_deploy_group(deploy_group: str, service: str, soa_dir: str):
"""Validate deploy_group.
Raise exception if the specified deploy group is not used anywhere.
"""
in_use_deploy_groups = list_deploy_groups(service=service, soa_dir=soa_dir)
_, invalid_deploy_groups = validate_given_deploy_gr... | Validate deploy_group.
Raise exception if the specified deploy group is not used anywhere.
| validate_deploy_group | python | Yelp/paasta | paasta_tools/cli/cmds/wait_for_deployment.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/cmds/wait_for_deployment.py | Apache-2.0 |
def _get_smartstack_proxy_ports_from_file(root, file):
"""Given a root and file (as from os.walk), attempt to return the highest
smartstack proxy port number (int) from that file. Returns 0 if there is no
smartstack proxy_port.
"""
ports = set()
with open(os.path.join(root, file)) as f:
... | Given a root and file (as from os.walk), attempt to return the highest
smartstack proxy port number (int) from that file. Returns 0 if there is no
smartstack proxy_port.
| _get_smartstack_proxy_ports_from_file | python | Yelp/paasta | paasta_tools/cli/fsm/autosuggest.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/fsm/autosuggest.py | Apache-2.0 |
def suggest_smartstack_proxy_port(
yelpsoa_config_root, range_min=19000, range_max=21000
):
"""Pick a random available port in the 19000-21000 block"""
available_proxy_ports = set(range(range_min, range_max + 1))
for root, dirs, files in os.walk(yelpsoa_config_root):
for f in files:
... | Pick a random available port in the 19000-21000 block | suggest_smartstack_proxy_port | python | Yelp/paasta | paasta_tools/cli/fsm/autosuggest.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/cli/fsm/autosuggest.py | Apache-2.0 |
def get_deploy_durations_from_file(filename):
"""
filename: path to a file to be parsed for datetime data
The expected input is a paasta service log for the deploy events
The way I've been fetching them is by running 'internal logreader command' | grep deploy | grep event > filename
"""
file_obj... |
filename: path to a file to be parsed for datetime data
The expected input is a paasta service log for the deploy events
The way I've been fetching them is by running 'internal logreader command' | grep deploy | grep event > filename
| get_deploy_durations_from_file | python | Yelp/paasta | paasta_tools/contrib/bounce_log_latency_parser.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/contrib/bounce_log_latency_parser.py | Apache-2.0 |
def host_to_ip(host: str, fallback: str) -> str:
"""Try to resolve a host to an IP with a fallback.
Because DNS resolution is relatively slow and can't be easily performed
using asyncio, we cheat a little and use a regex for well-formed hostnames
to try to guess the IP without doing real resolution.
... | Try to resolve a host to an IP with a fallback.
Because DNS resolution is relatively slow and can't be easily performed
using asyncio, we cheat a little and use a regex for well-formed hostnames
to try to guess the IP without doing real resolution.
A fallback is needed because in some cases the nerve ... | host_to_ip | python | Yelp/paasta | paasta_tools/contrib/check_orphans.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/contrib/check_orphans.py | Apache-2.0 |
def get_container_type(container_name: str, instance_name: str) -> str:
"""
To differentiate between main service containers and sidecars
"""
if instance_name and container_name == kubernetes_tools.sanitise_kubernetes_name(
instance_name
):
return MAIN_CONTAINER_TYPE
else:
... |
To differentiate between main service containers and sidecars
| get_container_type | python | Yelp/paasta | paasta_tools/contrib/get_running_task_allocation.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/contrib/get_running_task_allocation.py | Apache-2.0 |
def get_report_from_splunk(creds, app, filename, criteria_filter):
"""Expect a table containing at least the following fields:
criteria (<service> kubernetes-<cluster_name> <instance>)
service_owner (Optional)
project (Required to create tickets)
estimated_monthly_savings (Optional)
search_time ... | Expect a table containing at least the following fields:
criteria (<service> kubernetes-<cluster_name> <instance>)
service_owner (Optional)
project (Required to create tickets)
estimated_monthly_savings (Optional)
search_time (Unix time)
one of the following pairs:
- current_cpus and suggest... | get_report_from_splunk | python | Yelp/paasta | paasta_tools/contrib/paasta_update_soa_memcpu.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/contrib/paasta_update_soa_memcpu.py | Apache-2.0 |
def get_reviewers_in_group(group_name):
"""Using rbt's target-groups argument overrides our configured default review groups.
So we'll expand the group into usernames and pass those users in the group individually.
"""
rightsizer_reviewers = json.loads(
subprocess.check_output(
(
... | Using rbt's target-groups argument overrides our configured default review groups.
So we'll expand the group into usernames and pass those users in the group individually.
| get_reviewers_in_group | python | Yelp/paasta | paasta_tools/contrib/paasta_update_soa_memcpu.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/contrib/paasta_update_soa_memcpu.py | Apache-2.0 |
def nested_inc(op, _, attr_val, attr_name, state, step=1):
"""Increments relevant counter by step from args array"""
oph = state.setdefault(op, {})
nameh = oph.setdefault(attr_name, {})
nameh.setdefault(attr_val, 0)
nameh[attr_val] += step
return state | Increments relevant counter by step from args array | nested_inc | python | Yelp/paasta | paasta_tools/frameworks/constraints.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/constraints.py | Apache-2.0 |
def check_offer_constraints(offer, constraints, state):
"""Returns True if all constraints are satisfied by offer's attributes,
returns False otherwise. Prints a error message and re-raises if an error
was thrown."""
for (attr, op, val) in constraints:
try:
offer_attr = next((x for x... | Returns True if all constraints are satisfied by offer's attributes,
returns False otherwise. Prints a error message and re-raises if an error
was thrown. | check_offer_constraints | python | Yelp/paasta | paasta_tools/frameworks/constraints.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/constraints.py | Apache-2.0 |
def update_constraint_state(offer, constraints, state, step=1):
"""Mutates state for each offer attribute found in constraints by calling
relevant UPDATE_OP lambda"""
for (attr, op, val) in constraints:
for oa in offer.attributes:
if attr == oa.name:
UPDATE_OPS[op](val, o... | Mutates state for each offer attribute found in constraints by calling
relevant UPDATE_OP lambda | update_constraint_state | python | Yelp/paasta | paasta_tools/frameworks/constraints.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/constraints.py | Apache-2.0 |
def launch_tasks_for_offers(
self, driver: MesosSchedulerDriver, offers
) -> List[TaskInfo]:
"""For each offer tries to launch all tasks that can fit in there.
Declines offer if no fitting tasks found."""
launched_tasks: List[TaskInfo] = []
for offer in offers:
w... | For each offer tries to launch all tasks that can fit in there.
Declines offer if no fitting tasks found. | launch_tasks_for_offers | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def task_fits(self, offer):
"""Checks whether the offer is big enough to fit the tasks"""
needed_resources = {
"cpus": self.service_config.get_cpus(),
"mem": self.service_config.get_mem(),
"disk": self.service_config.get_disk(),
}
for resource in offer... | Checks whether the offer is big enough to fit the tasks | task_fits | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def need_more_tasks(self, name, existingTasks, scheduledTasks):
"""Returns whether we need to start more tasks."""
num_have = 0
for task, parameters in existingTasks.items():
if self.is_task_new(name, task) and (
parameters.mesos_task_state in LIVE_TASK_STATES
... | Returns whether we need to start more tasks. | need_more_tasks | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def tasks_and_state_for_offer(
self, driver: MesosSchedulerDriver, offer, state: ConstraintState
) -> Tuple[List[TaskInfo], ConstraintState]:
"""Returns collection of tasks that can fit inside an offer."""
tasks: List[TaskInfo] = []
offerCpus = 0.0
offerMem = 0.0
offe... | Returns collection of tasks that can fit inside an offer. | tasks_and_state_for_offer | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def healthiness_score(task_id):
"""Return a tuple that can be used as a key for sorting, that expresses our desire to keep this task around.
Higher values (things that sort later) are more desirable."""
params = all_tasks_with_params[task_id]
state_score = {
... | Return a tuple that can be used as a key for sorting, that expresses our desire to keep this task around.
Higher values (things that sort later) are more desirable. | healthiness_score | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def get_happy_tasks(self, tasks_with_params: Dict[str, MesosTaskParameters]):
"""Filter a dictionary of tasks->params to those that are running and not draining."""
happy_tasks = {}
for tid, params in tasks_with_params.items():
if params.mesos_task_state == TASK_RUNNING and not param... | Filter a dictionary of tasks->params to those that are running and not draining. | get_happy_tasks | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def make_drain_task(self, task_id: str):
"""Return a DrainTask object, which is suitable for passing to drain methods."""
ports = []
params = self.task_store.get_task(task_id)
for resource in params.resources:
if resource["name"] == "ports":
for rg in resour... | Return a DrainTask object, which is suitable for passing to drain methods. | make_drain_task | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def recreate_drain_method(self) -> None:
"""Re-instantiate self.drain_method. Should be called after self.service_config changes."""
self.drain_method = drain_lib.get_drain_method(
name=self.service_config.get_drain_method(
self.service_config.service_namespace_config
... | Re-instantiate self.drain_method. Should be called after self.service_config changes. | recreate_drain_method | python | Yelp/paasta | paasta_tools/frameworks/native_scheduler.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_scheduler.py | Apache-2.0 |
def base_task(
self, system_paasta_config: SystemPaastaConfig, portMappings=True
) -> TaskInfo:
"""Return a TaskInfo Dict with all the fields corresponding to the
configuration filled in.
Does not include task.agent_id or a task.id; those need to be
computed separately.
... | Return a TaskInfo Dict with all the fields corresponding to the
configuration filled in.
Does not include task.agent_id or a task.id; those need to be
computed separately.
| base_task | python | Yelp/paasta | paasta_tools/frameworks/native_service_config.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/native_service_config.py | Apache-2.0 |
def merge(self: _SelfT, **kwargs) -> "MesosTaskParameters":
"""Return a merged MesosTaskParameters object, where attributes in other take precedence over self."""
new_dict = copy.deepcopy(self.__dict__)
new_dict.update(kwargs)
return MesosTaskParameters(**new_dict) | Return a merged MesosTaskParameters object, where attributes in other take precedence over self. | merge | python | Yelp/paasta | paasta_tools/frameworks/task_store.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/task_store.py | Apache-2.0 |
def add_task_if_doesnt_exist(self, task_id: str, **kwargs) -> None:
"""Add a task if it does not already exist. If it already exists, do nothing."""
if self.get_task(task_id) is not None:
return
else:
self.overwrite_task(task_id, MesosTaskParameters(**kwargs)) | Add a task if it does not already exist. If it already exists, do nothing. | add_task_if_doesnt_exist | python | Yelp/paasta | paasta_tools/frameworks/task_store.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/task_store.py | Apache-2.0 |
def _get_task(self, task_id: str) -> Tuple[MesosTaskParameters, ZnodeStat]:
"""Like get_task, but also returns the ZnodeStat that self.zk_client.get() returns"""
try:
data, stat = self.zk_client.get("/%s" % task_id)
return MesosTaskParameters.deserialize(data), stat
excep... | Like get_task, but also returns the ZnodeStat that self.zk_client.get() returns | _get_task | python | Yelp/paasta | paasta_tools/frameworks/task_store.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/frameworks/task_store.py | Apache-2.0 |
def _format_remote_run_job_name(
job: V1Job,
user: str,
) -> str:
"""Format name for remote run job
:param V1Job job: job definition
:param str user: the user requesting the remote-run
:return: job name
"""
return limit_size_with_hash(f"remote-run-{user}-{job.metadata.name}") | Format name for remote run job
:param V1Job job: job definition
:param str user: the user requesting the remote-run
:return: job name
| _format_remote_run_job_name | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def remote_run_start(
service: str,
instance: str,
cluster: str,
user: str,
interactive: bool,
recreate: bool,
max_duration: int,
is_toolbox: bool,
) -> RemoteRunOutcome:
"""Trigger remote-run job
:param str service: service name
:param str instance: service instance
:pa... | Trigger remote-run job
:param str service: service name
:param str instance: service instance
:param str cluster: paasta cluster
:param str user: the user requesting the remote-run sandbox
:param bool interactive: whether it is expected to access the remote-run job interactively
:param bool rec... | remote_run_start | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def remote_run_ready(
service: str,
instance: str,
cluster: str,
job_name: str,
user: str,
is_toolbox: bool,
) -> RemoteRunOutcome:
"""Check if remote-run pod is ready
:param str service: service name
:param str instance: service instance
:param str cluster: paasta cluster
:... | Check if remote-run pod is ready
:param str service: service name
:param str instance: service instance
:param str cluster: paasta cluster
:param str job_name: name of the remote-run job to check
:param bool is_toolbox: requested job is for a toolbox container
:return: job status, with pod info... | remote_run_ready | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def remote_run_stop(
service: str,
instance: str,
cluster: str,
user: str,
is_toolbox: bool,
) -> RemoteRunOutcome:
"""Stop remote-run job
:param str service: service name
:param str instance: service instance
:param str cluster: paasta cluster
:param str user: the user requesti... | Stop remote-run job
:param str service: service name
:param str instance: service instance
:param str cluster: paasta cluster
:param str user: the user requesting the remote-run sandbox
:param bool is_toolbox: requested job is for a toolbox container
:return: outcome of the operation
| remote_run_stop | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
def remote_run_token(
service: str,
instance: str,
cluster: str,
user: str,
) -> str:
"""Creates a short lived token for execing into a pod
:param str service: service name
:param str instance: service instance
:param str cluster: paasta cluster
:param str user: the user requesting ... | Creates a short lived token for execing into a pod
:param str service: service name
:param str instance: service instance
:param str cluster: paasta cluster
:param str user: the user requesting the remote-run sandbox
| remote_run_token | python | Yelp/paasta | paasta_tools/kubernetes/remote_run.py | https://github.com/Yelp/paasta/blob/master/paasta_tools/kubernetes/remote_run.py | Apache-2.0 |
Subsets and Splits
Django Code with Docstrings
Filters Python code examples from Django repository that contain Django-related code, helping identify relevant code snippets for understanding Django framework usage patterns.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves Python code examples from Django repository that contain 'django' in the code, which helps identify Django-specific code snippets but provides limited analytical insights beyond basic filtering.
SQL Console for Shuu12121/python-treesitter-filtered-datasetsV2
Retrieves specific code examples from the Flask repository but doesn't provide meaningful analysis or patterns beyond basic data retrieval.
HTTPX Repo Code and Docstrings
Retrieves specific code examples from the httpx repository, which is useful for understanding how particular libraries are used but doesn't provide broader analytical insights about the dataset.
Requests Repo Docstrings & Code
Retrieves code examples with their docstrings and file paths from the requests repository, providing basic filtering but limited analytical value beyond finding specific code samples.
Quart Repo Docstrings & Code
Retrieves code examples with their docstrings from the Quart repository, providing basic code samples but offering limited analytical value for understanding broader patterns or relationships in the dataset.