_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q13300
_create_osf_project
train
def _create_osf_project(dlgr_id, description=None): """Create a project on the OSF.""" if not description: description = "Experiment {} registered by Dallinger.".format(dlgr_id) r = requests.post( "{}/nodes/".format(root), data={ "type": "nodes", "category":...
python
{ "resource": "" }
q13301
_upload_assets_to_OSF
train
def _upload_assets_to_OSF(dlgr_id, osf_id, provider="osfstorage"): """Upload experimental assets to the OSF.""" root = "https://files.osf.io/v1" snapshot_filename = "{}-code.zip".format(dlgr_id) snapshot_path = os.path.join("snapshots", snapshot_filename) r = requests.put( "{}/resources/{}/p...
python
{ "resource": "" }
q13302
update_task
train
def update_task(deadline, label, task_id): """ Executor for `globus task update` """ client = get_client() task_doc = assemble_generic_doc("task", label=label, deadline=deadline) res = client.update_task(task_id, task_doc) formatted_print(res, simple_text="Success")
python
{ "resource": "" }
q13303
show_task
train
def show_task(successful_transfers, task_id): """ Executor for `globus task show` """ client = get_client() if successful_transfers: print_successful_transfers(client, task_id) else: print_task_detail(client, task_id)
python
{ "resource": "" }
q13304
bookmark_create
train
def bookmark_create(endpoint_plus_path, bookmark_name): """ Executor for `globus bookmark create` """ endpoint_id, path = endpoint_plus_path client = get_client() submit_data = {"endpoint_id": str(endpoint_id), "path": path, "name": bookmark_name} res = client.create_bookmark(submit_data) ...
python
{ "resource": "" }
q13305
server_list
train
def server_list(endpoint_id): """ Executor for `globus endpoint server list` """ # raises usage error on shares for us endpoint, server_list = get_endpoint_w_server_list(endpoint_id) if server_list == "S3": # not GCS -- this is an S3 endpoint server_list = {"s3_url": endpoint["s3_url"]...
python
{ "resource": "" }
q13306
task_list
train
def task_list( limit, filter_task_id, filter_status, filter_type, filter_label, filter_not_label, inexact, filter_requested_after, filter_requested_before, filter_completed_after, filter_completed_before, ): """ Executor for `globus task-list` """ def _proces...
python
{ "resource": "" }
q13307
delete_command
train
def delete_command( batch, ignore_missing, star_silent, recursive, enable_globs, endpoint_plus_path, label, submission_id, dry_run, deadline, skip_activation_check, notify, ): """ Executor for `globus delete` """ endpoint_id, path = endpoint_plus_path ...
python
{ "resource": "" }
q13308
set_command
train
def set_command(value, parameter): """ Executor for `globus config set` """ conf = get_config_obj() section = "cli" if "." in parameter: section, parameter = parameter.split(".", 1) # ensure that the section exists if section not in conf: conf[section] = {} # set th...
python
{ "resource": "" }
q13309
shlex_process_stdin
train
def shlex_process_stdin(process_command, helptext): """ Use shlex to process stdin line-by-line. Also prints help text. Requires that @process_command be a Click command object, used for processing single lines of input. helptext is prepended to the standard message printed to interactive sessi...
python
{ "resource": "" }
q13310
local_id
train
def local_id(personal): """ Executor for `globus endpoint local-id` """ if personal: try: ep_id = LocalGlobusConnectPersonal().endpoint_id except IOError as e: safeprint(e, write_to_stderr=True) click.get_current_context().exit(1) if ep_id is ...
python
{ "resource": "" }
q13311
globus_group
train
def globus_group(*args, **kwargs): """ Wrapper over click.group which sets GlobusCommandGroup as the Class Caution! Don't get snake-bitten by this. `globus_group` is a decorator which MUST take arguments. It is not wrapped in our common detect-and-decorate pattern to allow it to be used bare --...
python
{ "resource": "" }
q13312
_get_package_data
train
def _get_package_data(): """ Import a set of important packages and return relevant data about them in a dict. Imports are done in here to avoid potential for circular imports and other problems, and to make iteration simpler. """ moddata = [] modlist = ( "click", "config...
python
{ "resource": "" }
q13313
print_version
train
def print_version(): """ Print out the current version, and at least try to fetch the latest from PyPi to print alongside it. It may seem odd that this isn't in globus_cli.version , but it's done this way to separate concerns over printing the version from looking it up. """ latest, current...
python
{ "resource": "" }
q13314
update_command
train
def update_command(yes, development, development_version): """ Executor for `globus update` """ # enforce that pip MUST be installed # Why not just include it in the setup.py requirements? Mostly weak # reasons, but it shouldn't matter much. # - if someone has installed the CLI without pip, ...
python
{ "resource": "" }
q13315
whoami_command
train
def whoami_command(linked_identities): """ Executor for `globus whoami` """ client = get_auth_client() # get userinfo from auth. # if we get back an error the user likely needs to log in again try: res = client.oauth2_userinfo() except AuthAPIError: safeprint( ...
python
{ "resource": "" }
q13316
get_completion_context
train
def get_completion_context(args): """ Walk the tree of commands to a terminal command or multicommand, using the Click Context system. Effectively, we'll be using the resilient_parsing mode of commands to stop evaluation, then having them capture their options and arguments, passing us on to the...
python
{ "resource": "" }
q13317
endpoint_is_activated
train
def endpoint_is_activated(endpoint_id, until, absolute_time): """ Executor for `globus endpoint is-activated` """ client = get_client() res = client.endpoint_get_activation_requirements(endpoint_id) def fail(deadline=None): exp_string = "" if deadline is not None: ex...
python
{ "resource": "" }
q13318
endpoint_create
train
def endpoint_create(**kwargs): """ Executor for `globus endpoint create` """ client = get_client() # get endpoint type, ensure unambiguous. personal = kwargs.pop("personal") server = kwargs.pop("server") shared = kwargs.pop("shared") if personal and (not server) and (not shared): ...
python
{ "resource": "" }
q13319
server_update
train
def server_update( endpoint_id, server_id, subject, port, scheme, hostname, incoming_data_ports, outgoing_data_ports, ): """ Executor for `globus endpoint server update` """ client = get_client() server_doc = assemble_generic_doc( "server", subject=subject, p...
python
{ "resource": "" }
q13320
filename_command
train
def filename_command(): """ Executor for `globus config filename` """ try: config = get_config_obj(file_error=True) except IOError as e: safeprint(e, write_to_stderr=True) click.get_current_context().exit(1) else: safeprint(config.filename)
python
{ "resource": "" }
q13321
my_shared_endpoint_list
train
def my_shared_endpoint_list(endpoint_id): """ Executor for `globus endpoint my-shared-endpoint-list` """ client = get_client() ep_iterator = client.my_shared_endpoint_list(endpoint_id) formatted_print(ep_iterator, fields=ENDPOINT_LIST_FIELDS)
python
{ "resource": "" }
q13322
_try_b32_decode
train
def _try_b32_decode(v): """ Attempt to decode a b32-encoded username which is sometimes generated by internal Globus components. The expectation is that the string is a valid ID, username, or b32-encoded name. Therefore, we can do some simple checking on it. If it does not appear to be formatt...
python
{ "resource": "" }
q13323
get_identities_command
train
def get_identities_command(values): """ Executor for `globus get-identities` """ client = get_auth_client() resolved_values = [_try_b32_decode(v) or v for v in values] # since API doesn't accept mixed ids and usernames, # split input values into separate lists ids = [] usernames = ...
python
{ "resource": "" }
q13324
supported_activation_methods
train
def supported_activation_methods(res): """ Given an activation_requirements document returns a list of activation methods supported by this endpoint. """ supported = ["web"] # web activation is always supported. # oauth if res["oauth_server"]: supported.append("oauth") for req...
python
{ "resource": "" }
q13325
activation_requirements_help_text
train
def activation_requirements_help_text(res, ep_id): """ Given an activation requirements document and an endpoint_id returns a string of help text for how to activate the endpoint """ methods = supported_activation_methods(res) lines = [ "This endpoint supports the following activation m...
python
{ "resource": "" }
q13326
get_endpoint_w_server_list
train
def get_endpoint_w_server_list(endpoint_id): """ A helper for handling endpoint server list lookups correctly accounting for various endpoint types. - Raises click.UsageError when used on Shares - Returns (<get_endpoint_response>, "S3") for S3 endpoints - Returns (<get_endpoint_response>, <serv...
python
{ "resource": "" }
q13327
RetryingTransferClient.retry
train
def retry(self, f, *args, **kwargs): """ Retries the given function self.tries times on NetworkErros """ backoff = random.random() / 100 # 5ms on average for _ in range(self.tries - 1): try: return f(*args, **kwargs) except NetworkError: ...
python
{ "resource": "" }
q13328
cancel_task
train
def cancel_task(all, task_id): """ Executor for `globus task cancel` """ if bool(all) + bool(task_id) != 1: raise click.UsageError( "You must pass EITHER the special --all flag " "to cancel all in-progress tasks OR a single " "task ID to cancel." ) ...
python
{ "resource": "" }
q13329
task_wait
train
def task_wait(meow, heartbeat, polling_interval, timeout, task_id, timeout_exit_code): """ Executor for `globus task wait` """ task_wait_with_io( meow, heartbeat, polling_interval, timeout, task_id, timeout_exit_code )
python
{ "resource": "" }
q13330
one_use_option
train
def one_use_option(*args, **kwargs): """ Wrapper of the click.option decorator that replaces any instances of the Option class with the custom OneUseOption class """ # cannot force a multiple or count option to be single use if "multiple" in kwargs or "count" in kwargs: raise ValueError(...
python
{ "resource": "" }
q13331
remove_command
train
def remove_command(parameter): """ Executor for `globus config remove` """ conf = get_config_obj() section = "cli" if "." in parameter: section, parameter = parameter.split(".", 1) # ensure that the section exists if section not in conf: conf[section] = {} # remove ...
python
{ "resource": "" }
q13332
show_command
train
def show_command(endpoint_id, rule_id): """ Executor for `globus endpoint permission show` """ client = get_client() rule = client.get_endpoint_acl_rule(endpoint_id, rule_id) formatted_print( rule, text_format=FORMAT_TEXT_RECORD, fields=( ("Rule ID", "id"), ...
python
{ "resource": "" }
q13333
bookmark_rename
train
def bookmark_rename(bookmark_id_or_name, new_bookmark_name): """ Executor for `globus bookmark rename` """ client = get_client() bookmark_id = resolve_id_or_name(client, bookmark_id_or_name)["id"] submit_data = {"name": new_bookmark_name} res = client.update_bookmark(bookmark_id, submit_da...
python
{ "resource": "" }
q13334
show_command
train
def show_command(parameter): """ Executor for `globus config show` """ section = "cli" if "." in parameter: section, parameter = parameter.split(".", 1) value = lookup_option(parameter, section=section) if value is None: safeprint("{} not set".format(parameter)) else: ...
python
{ "resource": "" }
q13335
rename_command
train
def rename_command(source, destination): """ Executor for `globus rename` """ source_ep, source_path = source dest_ep, dest_path = destination if source_ep != dest_ep: raise click.UsageError( ( "rename requires that the source and dest " "endp...
python
{ "resource": "" }
q13336
endpoint_show
train
def endpoint_show(endpoint_id): """ Executor for `globus endpoint show` """ client = get_client() res = client.get_endpoint(endpoint_id) formatted_print( res, text_format=FORMAT_TEXT_RECORD, fields=GCP_FIELDS if res["is_globus_connect"] else STANDARD_FIELDS, )
python
{ "resource": "" }
q13337
update_command
train
def update_command(permissions, rule_id, endpoint_id): """ Executor for `globus endpoint permission update` """ client = get_client() rule_data = assemble_generic_doc("access", permissions=permissions) res = client.update_endpoint_acl_rule(endpoint_id, rule_id, rule_data) formatted_print(re...
python
{ "resource": "" }
q13338
PrintableErrorField._format_value
train
def _format_value(self, val): """ formats a value to be good for textmode printing val must be unicode """ name = self.name + ":" if not self.multiline or "\n" not in val: val = u"{0} {1}".format(name.ljust(self._text_prefix_len), val) else: ...
python
{ "resource": "" }
q13339
delete_command
train
def delete_command(endpoint_id, rule_id): """ Executor for `globus endpoint permission delete` """ client = get_client() res = client.delete_endpoint_acl_rule(endpoint_id, rule_id) formatted_print(res, text_format=FORMAT_TEXT_RAW, response_key="message")
python
{ "resource": "" }
q13340
transfer_command
train
def transfer_command( batch, sync_level, recursive, destination, source, label, preserve_mtime, verify_checksum, encrypt, submission_id, dry_run, delete, deadline, skip_activation_check, notify, perf_cc, perf_p, perf_pp, perf_udt, ): """ ...
python
{ "resource": "" }
q13341
endpoint_delete
train
def endpoint_delete(endpoint_id): """ Executor for `globus endpoint delete` """ client = get_client() res = client.delete_endpoint(endpoint_id) formatted_print(res, text_format=FORMAT_TEXT_RAW, response_key="message")
python
{ "resource": "" }
q13342
bookmark_delete
train
def bookmark_delete(bookmark_id_or_name): """ Executor for `globus bookmark delete` """ client = get_client() bookmark_id = resolve_id_or_name(client, bookmark_id_or_name)["id"] res = client.delete_bookmark(bookmark_id) formatted_print(res, text_format=FORMAT_TEXT_RAW, response_key="message...
python
{ "resource": "" }
q13343
mkdir_command
train
def mkdir_command(endpoint_plus_path): """ Executor for `globus mkdir` """ endpoint_id, path = endpoint_plus_path client = get_client() autoactivate(client, endpoint_id, if_expires_in=60) res = client.operation_mkdir(endpoint_id, path=path) formatted_print(res, text_format=FORMAT_TEXT_...
python
{ "resource": "" }
q13344
init_command
train
def init_command(default_output_format, default_myproxy_username): """ Executor for `globus config init` """ # now handle the output format, requires a little bit more care # first, prompt if it isn't given, but be clear that we have a sensible # default if they don't set it # then, make sur...
python
{ "resource": "" }
q13345
detect_and_decorate
train
def detect_and_decorate(decorator, args, kwargs): """ Helper for applying a decorator when it is applied directly, and also applying it when it is given arguments and then applied to a function. """ # special behavior when invoked with only one non-keyword argument: act as # a normal decorator, ...
python
{ "resource": "" }
q13346
list_command
train
def list_command(endpoint_id): """ Executor for `globus endpoint permission list` """ client = get_client() rules = client.endpoint_acl_list(endpoint_id) resolved_ids = LazyIdentityMap( x["principal"] for x in rules if x["principal_type"] == "identity" ) def principal_str(rule...
python
{ "resource": "" }
q13347
bookmark_list
train
def bookmark_list(): """ Executor for `globus bookmark list` """ client = get_client() bookmark_iterator = client.bookmark_list() def get_ep_name(item): ep_id = item["endpoint_id"] try: ep_doc = client.get_endpoint(ep_id) return display_name_or_cname(ep_...
python
{ "resource": "" }
q13348
rm_command
train
def rm_command( ignore_missing, star_silent, recursive, enable_globs, endpoint_plus_path, label, submission_id, dry_run, deadline, skip_activation_check, notify, meow, heartbeat, polling_interval, timeout, timeout_exit_code, ): """ Executor for `gl...
python
{ "resource": "" }
q13349
do_link_auth_flow
train
def do_link_auth_flow(session_params=None, force_new_client=False): """ Prompts the user with a link to authenticate with globus auth and authorize the CLI to act on their behalf. """ session_params = session_params or {} # get the ConfidentialApp client object auth_client = internal_auth_c...
python
{ "resource": "" }
q13350
exchange_code_and_store_config
train
def exchange_code_and_store_config(auth_client, auth_code): """ Finishes auth flow after code is gotten from command line or local server. Exchanges code for tokens and gets user info from auth. Stores tokens and user info in config. """ # do a token exchange with the given code tkn = auth_c...
python
{ "resource": "" }
q13351
endpoint_search
train
def endpoint_search(filter_fulltext, filter_owner_id, filter_scope): """ Executor for `globus endpoint search` """ if filter_scope == "all" and not filter_fulltext: raise click.UsageError( "When searching all endpoints (--filter-scope=all, the default), " "a full-text sea...
python
{ "resource": "" }
q13352
endpoint_update
train
def endpoint_update(**kwargs): """ Executor for `globus endpoint update` """ # validate params. Requires a get call to check the endpoint type client = get_client() endpoint_id = kwargs.pop("endpoint_id") get_res = client.get_endpoint(endpoint_id) if get_res["host_endpoint_id"]: ...
python
{ "resource": "" }
q13353
safeprint
train
def safeprint(message, write_to_stderr=False, newline=True): """ Wrapper around click.echo used to encapsulate its functionality. Also protects against EPIPE during click.echo calls, as this can happen normally in piped commands when the consumer closes before the producer. """ try: clic...
python
{ "resource": "" }
q13354
common_options
train
def common_options(*args, **kwargs): """ This is a multi-purpose decorator for applying a "base" set of options shared by all commands. It can be applied either directly, or given keyword arguments. Usage: >>> @common_options >>> def mycommand(abc, xyz): >>> ... or >>> @c...
python
{ "resource": "" }
q13355
validate_endpoint_create_and_update_params
train
def validate_endpoint_create_and_update_params(endpoint_type, managed, params): """ Given an endpoint type of "shared" "server" or "personal" and option values Confirms the option values are valid for the given endpoint """ # options only allowed for GCS endpoints if endpoint_type != "server": ...
python
{ "resource": "" }
q13356
task_id_arg
train
def task_id_arg(*args, **kwargs): """ This is the `TASK_ID` argument consumed by many Transfer Task operations. It accept a toggle on whether or not it is required Usage: >>> @task_id_option >>> def command_func(task_id): >>> ... or >>> @task_id_option(required=False) >>>...
python
{ "resource": "" }
q13357
task_submission_options
train
def task_submission_options(f): """ Options shared by both transfer and delete task submission """ def notify_opt_callback(ctx, param, value): """ Parse --notify - "" is the same as "off" - parse by lowercase, comma-split, strip spaces - "off,x" is invalid for an...
python
{ "resource": "" }
q13358
delete_and_rm_options
train
def delete_and_rm_options(*args, **kwargs): """ Options which apply both to `globus delete` and `globus rm` """ def inner_decorator(f, supports_batch=True, default_enable_globs=False): f = click.option( "--recursive", "-r", is_flag=True, help="Recursively delete dirs" )(f) ...
python
{ "resource": "" }
q13359
server_add_and_update_opts
train
def server_add_and_update_opts(*args, **kwargs): """ shared collection of options for `globus transfer endpoint server add` and `globus transfer endpoint server update`. Accepts a toggle to know if it's being used as `add` or `update`. usage: >>> @server_add_and_update_opts >>> def command...
python
{ "resource": "" }
q13360
endpoint_deactivate
train
def endpoint_deactivate(endpoint_id): """ Executor for `globus endpoint deactivate` """ client = get_client() res = client.endpoint_deactivate(endpoint_id) formatted_print(res, text_format=FORMAT_TEXT_RAW, response_key="message")
python
{ "resource": "" }
q13361
LazyIdentityMap._lookup_identity_names
train
def _lookup_identity_names(self): """ Batch resolve identities to usernames. Returns a dict mapping IDs to Usernames """ id_batch_size = 100 # fetch in batches of 100, store in a dict ac = get_auth_client() self._resolved_map = {} for i in range(0...
python
{ "resource": "" }
q13362
internal_auth_client
train
def internal_auth_client(requires_instance=False, force_new_client=False): """ Looks up the values for this CLI's Instance Client in config If none exists and requires_instance is True or force_new_client is True, registers a new Instance Client with GLobus Auth If none exists and requires_instanc...
python
{ "resource": "" }
q13363
exit_with_mapped_status
train
def exit_with_mapped_status(http_status): """ Given an HTTP Status, exit with either an error status of 1 or the status mapped by what we were given. """ # get the mapping by looking up the state and getting the mapping attr mapping = click.get_current_context().ensure_object(CommandState).http_...
python
{ "resource": "" }
q13364
session_hook
train
def session_hook(exception): """ Expects an exception with an authorization_paramaters field in its raw_json """ safeprint( "The resource you are trying to access requires you to " "re-authenticate with specific identities." ) params = exception.raw_json["authorization_parameter...
python
{ "resource": "" }
q13365
custom_except_hook
train
def custom_except_hook(exc_info): """ A custom excepthook to present python errors produced by the CLI. We don't want to show end users big scary stacktraces if they aren't python programmers, so slim it down to some basic info. We keep a "DEBUGMODE" env variable kicking around to let us turn on sta...
python
{ "resource": "" }
q13366
task_event_list
train
def task_event_list(task_id, limit, filter_errors, filter_non_errors): """ Executor for `globus task-event-list` """ client = get_client() # cannot filter by both errors and non errors if filter_errors and filter_non_errors: raise click.UsageError("Cannot filter by both errors and non e...
python
{ "resource": "" }
q13367
role_delete
train
def role_delete(role_id, endpoint_id): """ Executor for `globus endpoint role delete` """ client = get_client() res = client.delete_endpoint_role(endpoint_id, role_id) formatted_print(res, text_format=FORMAT_TEXT_RAW, response_key="message")
python
{ "resource": "" }
q13368
ls_command
train
def ls_command( endpoint_plus_path, recursive_depth_limit, recursive, long_output, show_hidden, filter_val, ): """ Executor for `globus ls` """ endpoint_id, path = endpoint_plus_path # do autoactivation before the `ls` call so that recursive invocations # won't do this r...
python
{ "resource": "" }
q13369
generate_submission_id
train
def generate_submission_id(): """ Executor for `globus task generate-submission-id` """ client = get_client() res = client.get_submission_id() formatted_print(res, text_format=FORMAT_TEXT_RAW, response_key="value")
python
{ "resource": "" }
q13370
create_command
train
def create_command( principal, permissions, endpoint_plus_path, notify_email, notify_message ): """ Executor for `globus endpoint permission create` """ if not principal: raise click.UsageError("A security principal is required for this command") endpoint_id, path = endpoint_plus_path ...
python
{ "resource": "" }
q13371
bookmark_show
train
def bookmark_show(bookmark_id_or_name): """ Executor for `globus bookmark show` """ client = get_client() res = resolve_id_or_name(client, bookmark_id_or_name) formatted_print( res, text_format=FORMAT_TEXT_RECORD, fields=( ("ID", "id"), ("Name", "n...
python
{ "resource": "" }
q13372
role_list
train
def role_list(endpoint_id): """ Executor for `globus access endpoint-role-list` """ client = get_client() roles = client.endpoint_role_list(endpoint_id) resolved_ids = LazyIdentityMap( x["principal"] for x in roles if x["principal_type"] == "identity" ) def principal_str(role):...
python
{ "resource": "" }
q13373
fill_delegate_proxy_activation_requirements
train
def fill_delegate_proxy_activation_requirements( requirements_data, cred_file, lifetime_hours=12 ): """ Given the activation requirements for an endpoint and a filename for X.509 credentials, extracts the public key from the activation requirements, uses the key and the credentials to make a proxy c...
python
{ "resource": "" }
q13374
create_proxy_credentials
train
def create_proxy_credentials(issuer_cred, public_key, lifetime_hours): """ Given an issuer credentials PEM file in the form of a string, a public_key string from an activation requirements document, and an int for the proxy lifetime, returns credentials as a unicode string in PEM format containing a...
python
{ "resource": "" }
q13375
create_proxy_cert
train
def create_proxy_cert( loaded_cert, loaded_private_key, loaded_public_key, lifetime_hours ): """ Given cryptography objects for an issuing certificate, a public_key, a private_key, and an int for lifetime in hours, creates a proxy cert from the issuer and public key signed by the private key. ""...
python
{ "resource": "" }
q13376
confirm_not_old_proxy
train
def confirm_not_old_proxy(loaded_cert): """ Given a cryptography object for the issuer cert, checks if the cert is an "old proxy" and raise an error if so. """ # Examine the last CommonName to see if it looks like an old proxy. last_cn = loaded_cert.subject.get_attributes_for_oid(x509.oid.NameOI...
python
{ "resource": "" }
q13377
task_pause_info
train
def task_pause_info(task_id): """ Executor for `globus task pause-info` """ client = get_client() res = client.task_pause_info(task_id) def _custom_text_format(res): explicit_pauses = [ field for field in EXPLICIT_PAUSE_MSG_FIELDS # n.b. some keys are...
python
{ "resource": "" }
q13378
InstanaRecorder.run
train
def run(self): """ Span a background thread to periodically report queued spans """ self.timer = t.Thread(target=self.report_spans) self.timer.daemon = True self.timer.name = "Instana Span Reporting" self.timer.start()
python
{ "resource": "" }
q13379
InstanaRecorder.report_spans
train
def report_spans(self): """ Periodically report the queued spans """ logger.debug("Span reporting thread is now alive") def span_work(): queue_size = self.queue.qsize() if queue_size > 0 and instana.singletons.agent.can_send(): response = instana.singleto...
python
{ "resource": "" }
q13380
InstanaRecorder.queued_spans
train
def queued_spans(self): """ Get all of the spans in the queue """ spans = [] while True: try: s = self.queue.get(False) except queue.Empty: break else: spans.append(s) return spans
python
{ "resource": "" }
q13381
InstanaRecorder.record_span
train
def record_span(self, span): """ Convert the passed BasicSpan into an JsonSpan and add it to the span queue """ if instana.singletons.agent.can_send() or "INSTANA_TEST" in os.environ: json_span = None if span.operation_name in self.registered_spans: ...
python
{ "resource": "" }
q13382
InstanaRecorder.build_sdk_span
train
def build_sdk_span(self, span): """ Takes a BasicSpan and converts into an SDK type JsonSpan """ custom_data = CustomData(tags=span.tags, logs=self.collect_logs(span)) sdk_data = SDKData(name=span.operation_name, custom=custom_data, ...
python
{ "resource": "" }
q13383
InstanaRecorder.get_span_kind_as_string
train
def get_span_kind_as_string(self, span): """ Will retrieve the `span.kind` tag and return the appropriate string value for the Instana backend or None if the tag is set to something we don't recognize. :param span: The span to search for the `span.kind` tag :return: Stri...
python
{ "resource": "" }
q13384
InstanaRecorder.get_span_kind_as_int
train
def get_span_kind_as_int(self, span): """ Will retrieve the `span.kind` tag and return the appropriate integer value for the Instana backend or None if the tag is set to something we don't recognize. :param span: The span to search for the `span.kind` tag :return: Intege...
python
{ "resource": "" }
q13385
Meter.run
train
def run(self): """ Spawns the metric reporting thread """ self.thr = threading.Thread(target=self.collect_and_report) self.thr.daemon = True self.thr.name = "Instana Metric Collection" self.thr.start()
python
{ "resource": "" }
q13386
Meter.reset
train
def reset(self): """" Reset the state as new """ self.last_usage = None self.last_collect = None self.last_metrics = None self.snapshot_countdown = 0 self.run()
python
{ "resource": "" }
q13387
Meter.collect_and_report
train
def collect_and_report(self): """ Target function for the metric reporting thread. This is a simple loop to collect and report entity data every 1 second. """ logger.debug("Metric reporting thread is now alive") def metric_work(): self.process() ...
python
{ "resource": "" }
q13388
Meter.process
train
def process(self): """ Collects, processes & reports metrics """ if self.agent.machine.fsm.current is "wait4init": # Test the host agent if we're ready to send data if self.agent.is_agent_ready(): self.agent.machine.fsm.ready() else: re...
python
{ "resource": "" }
q13389
Meter.collect_snapshot
train
def collect_snapshot(self): """ Collects snapshot related information to this process and environment """ try: if "INSTANA_SERVICE_NAME" in os.environ: appname = os.environ["INSTANA_SERVICE_NAME"] elif "FLASK_APP" in os.environ: appname = os.envir...
python
{ "resource": "" }
q13390
Meter.collect_modules
train
def collect_modules(self): """ Collect up the list of modules in use """ try: res = {} m = sys.modules for k in m: # Don't report submodules (e.g. django.x, django.y, django.z) # Skip modules that begin with underscore i...
python
{ "resource": "" }
q13391
Agent.start
train
def start(self, e): """ Starts the agent and required threads """ logger.debug("Spawning metric & trace reporting threads") self.sensor.meter.run() instana.singletons.tracer.recorder.run()
python
{ "resource": "" }
q13392
Agent.handle_fork
train
def handle_fork(self): """ Forks happen. Here we handle them. """ self.reset() self.sensor.handle_fork() instana.singletons.tracer.handle_fork()
python
{ "resource": "" }
q13393
Agent.announce
train
def announce(self, discovery): """ With the passed in Discovery class, attempt to announce to the host agent. """ try: url = self.__discovery_url() logger.debug("making announce request to %s" % (url)) response = None response = self.client...
python
{ "resource": "" }
q13394
Agent.is_agent_ready
train
def is_agent_ready(self): """ Used after making a successful announce to test when the agent is ready to accept data. """ try: response = self.client.head(self.__data_url(), timeout=0.8) if response.status_code is 200: return True retu...
python
{ "resource": "" }
q13395
Agent.task_response
train
def task_response(self, message_id, data): """ When the host agent passes us a task and we do it, this function is used to respond with the results of the task. """ try: response = None payload = json.dumps(data) logger.debug("Task response is...
python
{ "resource": "" }
q13396
Agent.__discovery_url
train
def __discovery_url(self): """ URL for announcing to the host agent """ port = self.sensor.options.agent_port if port == 0: port = AGENT_DEFAULT_PORT return "http://%s:%s/%s" % (self.host, port, AGENT_DISCOVERY_PATH)
python
{ "resource": "" }
q13397
Agent.__data_url
train
def __data_url(self): """ URL for posting metrics to the host agent. Only valid when announced. """ path = AGENT_DATA_PATH % self.from_.pid return "http://%s:%s/%s" % (self.host, self.port, path)
python
{ "resource": "" }
q13398
Agent.__traces_url
train
def __traces_url(self): """ URL for posting traces to the host agent. Only valid when announced. """ path = AGENT_TRACES_PATH % self.from_.pid return "http://%s:%s/%s" % (self.host, self.port, path)
python
{ "resource": "" }
q13399
Agent.__response_url
train
def __response_url(self, message_id): """ URL for responding to agent requests. """ if self.from_.pid != 0: path = AGENT_RESPONSE_PATH % (self.from_.pid, message_id) return "http://%s:%s/%s" % (self.host, self.port, path)
python
{ "resource": "" }