diff --git a/datadog_checks_base/datadog_checks/base/checks/base.py b/datadog_checks_base/datadog_checks/base/checks/base.py index bae1c3051494d..fee2d288ad77f 100644 --- a/datadog_checks_base/datadog_checks/base/checks/base.py +++ b/datadog_checks_base/datadog_checks/base/checks/base.py @@ -147,12 +147,12 @@ class except the `check` method but sometimes it might be useful for a Check to # a mapping type, then each key will be considered a `name` and will be sent with its (str) value. METADATA_TRANSFORMERS = None - FIRST_CAP_RE = re.compile(br'(.)([A-Z][a-z]+)') - ALL_CAP_RE = re.compile(br'([a-z0-9])([A-Z])') - METRIC_REPLACEMENT = re.compile(br'([^a-zA-Z0-9_.]+)|(^[^a-zA-Z]+)') - TAG_REPLACEMENT = re.compile(br'[,\+\*\-/()\[\]{}\s]') - MULTIPLE_UNDERSCORE_CLEANUP = re.compile(br'__+') - DOT_UNDERSCORE_CLEANUP = re.compile(br'_*\._*') + FIRST_CAP_RE = re.compile(rb'(.)([A-Z][a-z]+)') + ALL_CAP_RE = re.compile(rb'([a-z0-9])([A-Z])') + METRIC_REPLACEMENT = re.compile(rb'([^a-zA-Z0-9_.]+)|(^[^a-zA-Z]+)') + TAG_REPLACEMENT = re.compile(rb'[,\+\*\-/()\[\]{}\s]') + MULTIPLE_UNDERSCORE_CLEANUP = re.compile(rb'__+') + DOT_UNDERSCORE_CLEANUP = re.compile(rb'_*\._*') # allows to set a limit on the number of metric name and tags combination # this check can send per run. This is useful for checks that have an unbounded @@ -1146,10 +1146,10 @@ def convert_to_underscore_separated(self, name): And substitute illegal metric characters """ name = ensure_bytes(name) - metric_name = self.FIRST_CAP_RE.sub(br'\1_\2', name) - metric_name = self.ALL_CAP_RE.sub(br'\1_\2', metric_name).lower() - metric_name = self.METRIC_REPLACEMENT.sub(br'_', metric_name) - return self.DOT_UNDERSCORE_CLEANUP.sub(br'.', metric_name).strip(b'_') + metric_name = self.FIRST_CAP_RE.sub(rb'\1_\2', name) + metric_name = self.ALL_CAP_RE.sub(rb'\1_\2', metric_name).lower() + metric_name = self.METRIC_REPLACEMENT.sub(rb'_', metric_name) + return self.DOT_UNDERSCORE_CLEANUP.sub(rb'.', metric_name).strip(b'_') def warning(self, warning_message, *args, **kwargs): # type: (str, *Any, **Any) -> None @@ -1243,10 +1243,10 @@ def normalize(self, metric, prefix=None, fix_case=False): if prefix is not None: prefix = self.convert_to_underscore_separated(prefix) else: - name = self.METRIC_REPLACEMENT.sub(br'_', metric) - name = self.DOT_UNDERSCORE_CLEANUP.sub(br'.', name).strip(b'_') + name = self.METRIC_REPLACEMENT.sub(rb'_', metric) + name = self.DOT_UNDERSCORE_CLEANUP.sub(rb'.', name).strip(b'_') - name = self.MULTIPLE_UNDERSCORE_CLEANUP.sub(br'_', name) + name = self.MULTIPLE_UNDERSCORE_CLEANUP.sub(rb'_', name) if prefix is not None: name = ensure_bytes(prefix) + b"." + name @@ -1262,9 +1262,9 @@ def normalize_tag(self, tag): """ if isinstance(tag, str): tag = tag.encode('utf-8', 'ignore') - tag = self.TAG_REPLACEMENT.sub(br'_', tag) - tag = self.MULTIPLE_UNDERSCORE_CLEANUP.sub(br'_', tag) - tag = self.DOT_UNDERSCORE_CLEANUP.sub(br'.', tag).strip(b'_') + tag = self.TAG_REPLACEMENT.sub(rb'_', tag) + tag = self.MULTIPLE_UNDERSCORE_CLEANUP.sub(rb'_', tag) + tag = self.DOT_UNDERSCORE_CLEANUP.sub(rb'.', tag).strip(b'_') return to_native_string(tag) def check(self, instance): diff --git a/datadog_checks_base/datadog_checks/base/checks/network.py b/datadog_checks_base/datadog_checks/base/checks/network.py index 6747faca9c4f6..c064fd805649e 100644 --- a/datadog_checks_base/datadog_checks/base/checks/network.py +++ b/datadog_checks_base/datadog_checks/base/checks/network.py @@ -33,7 +33,7 @@ def check(self, instance): try: statuses = self._check(instance) except Exception: - self.log.exception(u"Failed to run instance '%s'.", instance.get('name', u"")) + self.log.exception("Failed to run instance '%s'.", instance.get('name', "")) else: if isinstance(statuses, tuple): # Assume the check only returns one service check diff --git a/datadog_checks_base/datadog_checks/base/checks/prometheus/mixins.py b/datadog_checks_base/datadog_checks/base/checks/prometheus/mixins.py index e32f88c26c092..d3f6c8c9f2143 100644 --- a/datadog_checks_base/datadog_checks/base/checks/prometheus/mixins.py +++ b/datadog_checks_base/datadog_checks/base/checks/prometheus/mixins.py @@ -561,7 +561,7 @@ def poll(self, endpoint, pFormat=PrometheusFormat.PROTOBUF, headers=None, instan headers['Accept-Encoding'] = 'gzip' if pFormat == PrometheusFormat.PROTOBUF: headers['accept'] = ( - 'application/vnd.google.protobuf; ' 'proto=io.prometheus.client.MetricFamily; ' 'encoding=delimited' + 'application/vnd.google.protobuf; proto=io.prometheus.client.MetricFamily; encoding=delimited' ) handler = self.get_http_handler(endpoint, instance) if ( @@ -569,7 +569,7 @@ def poll(self, endpoint, pFormat=PrometheusFormat.PROTOBUF, headers=None, instan and not handler.ignore_tls_warning and not is_affirmative(handler.options.get('ssl_verify', True)) ): - self.log.debug(u'An unverified HTTPS request is being made to %s', endpoint) + self.log.debug('An unverified HTTPS request is being made to %s', endpoint) try: response = handler.get(endpoint, extra_headers=headers, stream=False) diff --git a/datadog_checks_base/datadog_checks/base/checks/win/wmi/base.py b/datadog_checks_base/datadog_checks/base/checks/win/wmi/base.py index ab980c07e8a6b..729125f8725ef 100644 --- a/datadog_checks_base/datadog_checks/base/checks/win/wmi/base.py +++ b/datadog_checks_base/datadog_checks/base/checks/win/wmi/base.py @@ -68,14 +68,14 @@ def _format_tag_query(self, sampler, wmi_obj, tag_query): target_property = tag_query[3] except IndexError: self.log.error( - u"Wrong `tag_queries` parameter format. " "Please refer to the configuration file for more information." + "Wrong `tag_queries` parameter format. Please refer to the configuration file for more information." ) raise except TypeError: wmi_property = tag_query[0] wmi_class = sampler.class_name self.log.error( - u"Incorrect 'link source property' in `tag_queries` parameter: `%s` is not a property of `%s`", + "Incorrect 'link source property' in `tag_queries` parameter: `%s` is not a property of `%s`", wmi_property, wmi_class, ) @@ -94,7 +94,7 @@ def _raise_on_invalid_tag_query_result(self, sampler, wmi_obj, tag_query): message = "multiple results returned (one expected)" self.log.warning( - u"Failed to extract a tag from `tag_queries` parameter: %s. wmi_object=%s - query=%s", + "Failed to extract a tag from `tag_queries` parameter: %s. wmi_object=%s - query=%s", message, wmi_obj, tag_query, @@ -103,7 +103,7 @@ def _raise_on_invalid_tag_query_result(self, sampler, wmi_obj, tag_query): if sampler[0][target_property] is None: self.log.error( - u"Incorrect 'target property' in `tag_queries` parameter: `%s` is empty or is not a property of `%s`", + "Incorrect 'target property' in `tag_queries` parameter: `%s` is empty or is not a property of `%s`", target_property, target_class, ) @@ -116,7 +116,7 @@ def _get_tag_query_tag(self, sampler, wmi_obj, tag_query): Returns: tag or TagQueryUniquenessFailure exception. """ - self.log.debug(u"`tag_queries` parameter found. wmi_object=%s - query=%s", wmi_obj, tag_query) + self.log.debug("`tag_queries` parameter found. wmi_object=%s - query=%s", wmi_obj, tag_query) # Extract query information target_class, target_property, filters = self._format_tag_query(sampler, wmi_obj, tag_query) @@ -134,7 +134,7 @@ def _get_tag_query_tag(self, sampler, wmi_obj, tag_query): tag = "{tag_name}:{tag_value}".format(tag_name=target_property.lower(), tag_value="_".join(link_value.split())) - self.log.debug(u"Extracted `tag_queries` tag: '%s'", tag) + self.log.debug("Extracted `tag_queries` tag: '%s'", tag) return tag def _extract_metrics(self, wmi_sampler, tag_by, tag_queries, constant_tags): @@ -154,7 +154,7 @@ def _extract_metrics(self, wmi_sampler, tag_by, tag_queries, constant_tags): """ if len(wmi_sampler) > 1 and not tag_by: raise MissingTagBy( - u"WMI query returned multiple rows but no `tag_by` value was given." + "WMI query returned multiple rows but no `tag_by` value was given." " class={wmi_class} - properties={wmi_properties} - filters={filters}".format( wmi_class=wmi_sampler.class_name, wmi_properties=wmi_sampler.property_names, @@ -209,11 +209,11 @@ def _extract_metrics(self, wmi_sampler, tag_by, tag_queries, constant_tags): extracted_metrics.append(WMIMetric(wmi_property, float(wmi_value), tags)) except ValueError: self.log.warning( - u"When extracting metrics with WMI, found a non digit value for property '%s'.", wmi_property + "When extracting metrics with WMI, found a non digit value for property '%s'.", wmi_property ) continue except TypeError: - self.log.warning(u"When extracting metrics with WMI, found a missing property '%s'", wmi_property) + self.log.warning("When extracting metrics with WMI, found a missing property '%s'", wmi_property) continue return extracted_metrics @@ -241,7 +241,7 @@ def _submit_metrics(self, metrics, metric_name_and_type_by_property): try: func = getattr(self, metric_type.lower()) except AttributeError: - raise Exception(u"Invalid metric type: {0}".format(metric_type)) + raise Exception("Invalid metric type: {0}".format(metric_type)) func(metric_name, metric.value, metric.tags) @@ -270,7 +270,7 @@ def get_running_wmi_sampler(self, properties, filters, **kwargs): username=self.username, password=self.password, tag_by=tag_by, - **kwargs + **kwargs, ) def _get_running_wmi_sampler(self, instance_key, wmi_class, properties, tag_by="", **kwargs): diff --git a/datadog_checks_base/datadog_checks/base/checks/win/wmi/sampler.py b/datadog_checks_base/datadog_checks/base/checks/win/wmi/sampler.py index c3131743db29e..3fe685742c8d1 100644 --- a/datadog_checks_base/datadog_checks/base/checks/win/wmi/sampler.py +++ b/datadog_checks_base/datadog_checks/base/checks/win/wmi/sampler.py @@ -23,6 +23,7 @@ Original discussion thread: https://github.com/DataDog/dd-agent/issues/1952 Credits to @TheCloudlessSky (https://github.com/TheCloudlessSky) """ + from copy import deepcopy from threading import Event, Thread @@ -227,7 +228,7 @@ def provider(self, value): result = parsed_value if result is None: - self.logger.error(u"Invalid '%s' WMI Provider Architecture. The parameter is ignored.", value) + self.logger.error("Invalid '%s' WMI Provider Architecture. The parameter is ignored.", value) self._provider = result or ProviderArchitecture.DEFAULT @@ -278,7 +279,7 @@ def __len__(self): """ # No data is returned while sampling if self._sampling: - raise TypeError(u"Sampling `WMISampler` object has no len()") + raise TypeError("Sampling `WMISampler` object has no len()") return len(self._current_sample) @@ -288,7 +289,7 @@ def __iter__(self): """ # No data is returned while sampling if self._sampling: - raise TypeError(u"Sampling `WMISampler` object is not iterable") + raise TypeError("Sampling `WMISampler` object is not iterable") if self.is_raw_perf_class: # Format required @@ -334,7 +335,7 @@ def _get_property_calculator(self, counter_type): calculator = get_calculator(counter_type) except UndefinedCalculator: self.logger.warning( - u"Undefined WMI calculator for counter_type %s. Values are reported as RAW.", counter_type + "Undefined WMI calculator for counter_type %s. Values are reported as RAW.", counter_type ) return calculator @@ -364,7 +365,7 @@ def get_connection(self): Create a new WMI connection """ self.logger.debug( - u"Connecting to WMI server (host=%s, namespace=%s, provider=%s, username=%s).", + "Connecting to WMI server (host=%s, namespace=%s, provider=%s, username=%s).", self.host, self.namespace, self.provider, @@ -550,7 +551,7 @@ def _query(self): # pylint: disable=E0202 wql = "Select {property_names} from {class_name}{filters}".format( property_names=formated_property_names, class_name=self.class_name, filters=self.formatted_filters ) - self.logger.debug(u"Querying WMI: %s", wql) + self.logger.debug("Querying WMI: %s", wql) except Exception as e: self.logger.error(str(e)) return [] @@ -575,7 +576,7 @@ def _query(self): # pylint: disable=E0202 results = self._parse_results(raw_results, includes_qualifiers=includes_qualifiers) except pywintypes.com_error: - self.logger.warning(u"Failed to execute WMI query (%s)", wql, exc_info=True) + self.logger.warning("Failed to execute WMI query (%s)", wql, exc_info=True) results = [] return results @@ -615,7 +616,6 @@ def _parse_results(self, raw_results, includes_qualifiers): ) if should_get_qualifier_type: - # Can't index into "Qualifiers_" for keys that don't exist # without getting an exception. qualifiers = dict((q.Name, q.Value) for q in wmi_property.Qualifiers_) @@ -628,14 +628,14 @@ def _parse_results(self, raw_results, includes_qualifiers): self._property_counter_types[wmi_property.Name] = counter_type self.logger.debug( - u"Caching property qualifier CounterType: %s.%s = %s", + "Caching property qualifier CounterType: %s.%s = %s", self.class_name, wmi_property.Name, counter_type, ) else: self.logger.debug( - u"CounterType qualifier not found for %s.%s", self.class_name, wmi_property.Name + "CounterType qualifier not found for %s.%s", self.class_name, wmi_property.Name ) try: diff --git a/datadog_checks_base/datadog_checks/base/checks/windows/perf_counters/connection.py b/datadog_checks_base/datadog_checks/base/checks/windows/perf_counters/connection.py index 4a335721d3ea5..17f8480f962bf 100644 --- a/datadog_checks_base/datadog_checks/base/checks/windows/perf_counters/connection.py +++ b/datadog_checks_base/datadog_checks/base/checks/windows/perf_counters/connection.py @@ -77,7 +77,7 @@ def __init__(self, config): # https://docs.microsoft.com/en-us/windows/win32/api/winnetwk/ns-winnetwk-netresourcea # https://mhammond.github.io/pywin32/PyNETRESOURCE.html self.network_resource = win32wnet.NETRESOURCE() - self.network_resource.lpRemoteName = fr'\\{server}' + self.network_resource.lpRemoteName = rf'\\{server}' self.__query_handle = None diff --git a/datadog_checks_base/datadog_checks/base/stubs/datadog_agent.py b/datadog_checks_base/datadog_checks/base/stubs/datadog_agent.py index 3e465941b07d9..adc56bad1010e 100644 --- a/datadog_checks_base/datadog_checks/base/stubs/datadog_agent.py +++ b/datadog_checks_base/datadog_checks/base/stubs/datadog_agent.py @@ -67,10 +67,10 @@ def assert_external_tags(self, hostname, external_tags, match_tags_order=False): external_tags = {k: sorted(v) for (k, v) in external_tags.items()} tags = {k: sorted(v) for (k, v) in tags.items()} - assert ( - external_tags == tags - ), 'Expected {} external tags for hostname {}, found {}. Submitted external tags: {}'.format( - external_tags, hostname, tags, repr(self._external_tags) + assert external_tags == tags, ( + 'Expected {} external tags for hostname {}, found {}. Submitted external tags: {}'.format( + external_tags, hostname, tags, repr(self._external_tags) + ) ) return diff --git a/datadog_checks_base/datadog_checks/base/utils/db/query.py b/datadog_checks_base/datadog_checks/base/utils/db/query.py index 137c835ae15f7..ce88a4bcae618 100644 --- a/datadog_checks_base/datadog_checks/base/utils/db/query.py +++ b/datadog_checks_base/datadog_checks/base/utils/db/query.py @@ -214,9 +214,7 @@ def compile( elif extra_type not in extra_transformers and extra_type not in submission_transformers: raise ValueError('unknown type `{}` for extra {} of {}'.format(extra_type, extra_name, query_name)) - transformer_factory = extra_transformers.get( - extra_type, submission_transformers.get(extra_type) - ) # type: TransformerFactory + transformer_factory = extra_transformers.get(extra_type, submission_transformers.get(extra_type)) # type: TransformerFactory extra_source = extra.get('source') if extra_type in submission_transformers: diff --git a/datadog_checks_base/datadog_checks/base/utils/db/transform.py b/datadog_checks_base/datadog_checks/base/utils/db/transform.py index 0c4d82cec27d8..8d8e513085ae6 100644 --- a/datadog_checks_base/datadog_checks/base/utils/db/transform.py +++ b/datadog_checks_base/datadog_checks/base/utils/db/transform.py @@ -85,9 +85,7 @@ def get_monotonic_gauge(transformers, column_name, **modifiers): Send the result as both a `gauge` suffixed by `.total` and a `monotonic_count` suffixed by `.count`. """ gauge = transformers['gauge'](transformers, '{}.total'.format(column_name), **modifiers) # type: Callable - monotonic_count = transformers['monotonic_count']( - transformers, '{}.count'.format(column_name), **modifiers - ) # type: Callable + monotonic_count = transformers['monotonic_count'](transformers, '{}.count'.format(column_name), **modifiers) # type: Callable def monotonic_gauge(_, value, **kwargs): # type: (List, str, Dict[str, Any]) -> None diff --git a/datadog_checks_base/datadog_checks/base/utils/http.py b/datadog_checks_base/datadog_checks/base/utils/http.py index a21d286f37265..d6e531bf08167 100644 --- a/datadog_checks_base/datadog_checks/base/utils/http.py +++ b/datadog_checks_base/datadog_checks/base/utils/http.py @@ -378,7 +378,7 @@ def options_method(self, url, **options): def _request(self, method, url, options): if self.log_requests: - self.logger.debug(u'Sending %s request to %s', method.upper(), url) + self.logger.debug('Sending %s request to %s', method.upper(), url) if self.no_proxy_uris and should_bypass_proxy(url, self.no_proxy_uris): options.setdefault('proxies', PROXY_SETTINGS_DISABLED) @@ -390,7 +390,7 @@ def _request(self, method, url, options): new_options = self.populate_options(options) if url.startswith('https') and not self.ignore_tls_warning and not new_options['verify']: - self.logger.debug(u'An unverified HTTPS request is being made to %s', url) + self.logger.debug('An unverified HTTPS request is being made to %s', url) extra_headers = options.pop('extra_headers', None) if extra_headers is not None: @@ -416,7 +416,7 @@ def _request(self, method, url, options): response = self.make_request_aia_chasing(request_method, method, url, new_options, persist) response.raise_for_status() except Exception as e: - self.logger.debug(u'Renewing auth token, as an error occurred: %s', e) + self.logger.debug('Renewing auth token, as an error occurred: %s', e) self.handle_auth_token(method=method, url=url, default_options=self.options, error=str(e)) response = self.make_request_aia_chasing(request_method, method, url, new_options, persist) else: diff --git a/datadog_checks_base/datadog_checks/base/utils/prometheus/metrics_pb2.py b/datadog_checks_base/datadog_checks/base/utils/prometheus/metrics_pb2.py index 041f2db38a2cd..0fcfde3a360de 100644 --- a/datadog_checks_base/datadog_checks/base/utils/prometheus/metrics_pb2.py +++ b/datadog_checks_base/datadog_checks/base/utils/prometheus/metrics_pb2.py @@ -6,6 +6,7 @@ # https://github.com/prometheus/client_model/blob/086fe7ca28bde6cec2acd5223423c1475a362858/metrics.proto#L76-%20%20L81 """Generated protocol buffer code.""" + from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool from google.protobuf import symbol_database as _symbol_database @@ -16,7 +17,7 @@ _sym_db = _symbol_database.Default() DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile( - b'\n\rmetrics.proto\x12\x14io.prometheus.client\"(\n\tLabelPair\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t\"\x16\n\x05Gauge\x12\r\n\x05value\x18\x01 \x01(\x01\"\x18\n\x07\x43ounter\x12\r\n\x05value\x18\x01 \x01(\x01\"+\n\x08Quantile\x12\x10\n\x08quantile\x18\x01 \x01(\x01\x12\r\n\x05value\x18\x02 \x01(\x01\"e\n\x07Summary\x12\x14\n\x0csample_count\x18\x01 \x01(\x04\x12\x12\n\nsample_sum\x18\x02 \x01(\x01\x12\x30\n\x08quantile\x18\x03 \x03(\x0b\x32\x1e.io.prometheus.client.Quantile\"\x18\n\x07Untyped\x12\r\n\x05value\x18\x01 \x01(\x01\"c\n\tHistogram\x12\x14\n\x0csample_count\x18\x01 \x01(\x04\x12\x12\n\nsample_sum\x18\x02 \x01(\x01\x12,\n\x06\x62ucket\x18\x03 \x03(\x0b\x32\x1c.io.prometheus.client.Bucket\"7\n\x06\x42ucket\x12\x18\n\x10\x63umulative_count\x18\x01 \x01(\x04\x12\x13\n\x0bupper_bound\x18\x02 \x01(\x01\"\xbe\x02\n\x06Metric\x12.\n\x05label\x18\x01 \x03(\x0b\x32\x1f.io.prometheus.client.LabelPair\x12*\n\x05gauge\x18\x02 \x01(\x0b\x32\x1b.io.prometheus.client.Gauge\x12.\n\x07\x63ounter\x18\x03 \x01(\x0b\x32\x1d.io.prometheus.client.Counter\x12.\n\x07summary\x18\x04 \x01(\x0b\x32\x1d.io.prometheus.client.Summary\x12.\n\x07untyped\x18\x05 \x01(\x0b\x32\x1d.io.prometheus.client.Untyped\x12\x32\n\thistogram\x18\x07 \x01(\x0b\x32\x1f.io.prometheus.client.Histogram\x12\x14\n\x0ctimestamp_ms\x18\x06 \x01(\x03\"\x88\x01\n\x0cMetricFamily\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04help\x18\x02 \x01(\t\x12.\n\x04type\x18\x03 \x01(\x0e\x32 .io.prometheus.client.MetricType\x12,\n\x06metric\x18\x04 \x03(\x0b\x32\x1c.io.prometheus.client.Metric*M\n\nMetricType\x12\x0b\n\x07\x43OUNTER\x10\x00\x12\t\n\x05GAUGE\x10\x01\x12\x0b\n\x07SUMMARY\x10\x02\x12\x0b\n\x07UNTYPED\x10\x03\x12\r\n\tHISTOGRAM\x10\x04\x42\x16\n\x14io.prometheus.client' + b'\n\rmetrics.proto\x12\x14io.prometheus.client"(\n\tLabelPair\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t"\x16\n\x05Gauge\x12\r\n\x05value\x18\x01 \x01(\x01"\x18\n\x07\x43ounter\x12\r\n\x05value\x18\x01 \x01(\x01"+\n\x08Quantile\x12\x10\n\x08quantile\x18\x01 \x01(\x01\x12\r\n\x05value\x18\x02 \x01(\x01"e\n\x07Summary\x12\x14\n\x0csample_count\x18\x01 \x01(\x04\x12\x12\n\nsample_sum\x18\x02 \x01(\x01\x12\x30\n\x08quantile\x18\x03 \x03(\x0b\x32\x1e.io.prometheus.client.Quantile"\x18\n\x07Untyped\x12\r\n\x05value\x18\x01 \x01(\x01"c\n\tHistogram\x12\x14\n\x0csample_count\x18\x01 \x01(\x04\x12\x12\n\nsample_sum\x18\x02 \x01(\x01\x12,\n\x06\x62ucket\x18\x03 \x03(\x0b\x32\x1c.io.prometheus.client.Bucket"7\n\x06\x42ucket\x12\x18\n\x10\x63umulative_count\x18\x01 \x01(\x04\x12\x13\n\x0bupper_bound\x18\x02 \x01(\x01"\xbe\x02\n\x06Metric\x12.\n\x05label\x18\x01 \x03(\x0b\x32\x1f.io.prometheus.client.LabelPair\x12*\n\x05gauge\x18\x02 \x01(\x0b\x32\x1b.io.prometheus.client.Gauge\x12.\n\x07\x63ounter\x18\x03 \x01(\x0b\x32\x1d.io.prometheus.client.Counter\x12.\n\x07summary\x18\x04 \x01(\x0b\x32\x1d.io.prometheus.client.Summary\x12.\n\x07untyped\x18\x05 \x01(\x0b\x32\x1d.io.prometheus.client.Untyped\x12\x32\n\thistogram\x18\x07 \x01(\x0b\x32\x1f.io.prometheus.client.Histogram\x12\x14\n\x0ctimestamp_ms\x18\x06 \x01(\x03"\x88\x01\n\x0cMetricFamily\x12\x0c\n\x04name\x18\x01 \x01(\t\x12\x0c\n\x04help\x18\x02 \x01(\t\x12.\n\x04type\x18\x03 \x01(\x0e\x32 .io.prometheus.client.MetricType\x12,\n\x06metric\x18\x04 \x03(\x0b\x32\x1c.io.prometheus.client.Metric*M\n\nMetricType\x12\x0b\n\x07\x43OUNTER\x10\x00\x12\t\n\x05GAUGE\x10\x01\x12\x0b\n\x07SUMMARY\x10\x02\x12\x0b\n\x07UNTYPED\x10\x03\x12\r\n\tHISTOGRAM\x10\x04\x42\x16\n\x14io.prometheus.client' ) _globals = globals() diff --git a/datadog_checks_base/datadog_checks/base/utils/tailfile.py b/datadog_checks_base/datadog_checks/base/utils/tailfile.py index 905a7ec122ac9..2de6f99dee5c7 100644 --- a/datadog_checks_base/datadog_checks/base/utils/tailfile.py +++ b/datadog_checks_base/datadog_checks/base/utils/tailfile.py @@ -9,7 +9,6 @@ class TailFile(object): - CRC_SIZE = 16 def __init__(self, logger, path, callback): @@ -22,7 +21,6 @@ def __init__(self, logger, path, callback): self._callback = callback def _open_file(self, move_end=False, pos=False): - already_open = False # close and reopen to handle logrotate if self._f is not None: diff --git a/datadog_checks_base/datadog_checks/checks/libs/wmi/sampler.py b/datadog_checks_base/datadog_checks/checks/libs/wmi/sampler.py index 7c3fb5b2aecea..b7f0963bbeeab 100644 --- a/datadog_checks_base/datadog_checks/checks/libs/wmi/sampler.py +++ b/datadog_checks_base/datadog_checks/checks/libs/wmi/sampler.py @@ -23,4 +23,5 @@ Original discussion thread: https://github.com/DataDog/dd-agent/issues/1952 Credits to @TheCloudlessSky (https://github.com/TheCloudlessSky) """ + from ....win.wmi.sampler import WMISampler diff --git a/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py b/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py index 17341a0fce77b..1cdd641a42579 100644 --- a/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py +++ b/datadog_checks_base/tests/base/checks/openmetrics/test_legacy/test_openmetrics.py @@ -185,10 +185,10 @@ def test_submit_gauge_with_labels(aggregator, mocked_prometheus_check, mocked_pr ref_gauge = GaugeMetricFamily( 'process_virtual_memory_bytes', 'Virtual memory size in bytes.', - labels=['my_1st_label', 'my_2nd_label', 'labél_nat', 'labél_mix', u'labél_uni'], + labels=['my_1st_label', 'my_2nd_label', 'labél_nat', 'labél_mix', 'labél_uni'], ) ref_gauge.add_metric( - ['my_1st_label_value', 'my_2nd_label_value', 'my_labél_val', u'my_labél_val🐶', u'my_labél_val'], 54927360.0 + ['my_1st_label_value', 'my_2nd_label_value', 'my_labél_val', 'my_labél_val🐶', 'my_labél_val'], 54927360.0 ) check = mocked_prometheus_check diff --git a/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_options.py b/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_options.py index a3291f14b1781..1e3fae25848fc 100644 --- a/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_options.py +++ b/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_options.py @@ -682,7 +682,6 @@ def test_shared_labels_without_cache(self, aggregator, dd_run_check, mock_http_r aggregator.assert_all_metrics_covered() def test_target_info_tags_propagation(self, aggregator, dd_run_check, mock_http_response): - check = get_check({'metrics': ['.+'], 'target_info': True}) mock_http_response( @@ -708,7 +707,6 @@ def test_target_info_tags_propagation(self, aggregator, dd_run_check, mock_http_ aggregator.assert_all_metrics_covered() def test_target_info_tags_propagation_unordered(self, aggregator, dd_run_check, mock_http_response): - check = get_check({'metrics': ['.+'], 'target_info': True, 'cache_shared_labels': False}) mock_http_response( @@ -734,7 +732,6 @@ def test_target_info_tags_propagation_unordered(self, aggregator, dd_run_check, aggregator.assert_all_metrics_covered() def test_target_info_tags_propagation_unordered_w_cache(self, aggregator, dd_run_check, mock_http_response): - check = get_check({'metrics': ['.+'], 'target_info': True}) mock_http_response( @@ -769,7 +766,6 @@ def test_target_info_tags_propagation_unordered_w_cache(self, aggregator, dd_run aggregator.assert_all_metrics_covered() def test_target_info_update_cache(self, aggregator, dd_run_check, mock_http_response): - check = get_check({'metrics': ['.+'], 'target_info': True}) check_var = check @@ -816,7 +812,6 @@ def test_target_info_update_cache(self, aggregator, dd_run_check, mock_http_resp aggregator.assert_all_metrics_covered() def test_target_info_w_shared_labels_cache(self, aggregator, dd_run_check, mock_http_response): - check = get_check({'metrics': ['.+'], 'share_labels': {'go_memstats_free_bytes': True}, 'target_info': True}) check_var = check diff --git a/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_transformers/test_time_elapsed.py b/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_transformers/test_time_elapsed.py index f23c446eaa229..c62456f300ebc 100644 --- a/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_transformers/test_time_elapsed.py +++ b/datadog_checks_base/tests/base/checks/openmetrics/test_v2/test_transformers/test_time_elapsed.py @@ -12,9 +12,7 @@ def test(aggregator, dd_run_check, mock_http_response): # HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection. # TYPE go_memstats_last_gc_time_seconds gauge go_memstats_last_gc_time_seconds{{foo="bar"}} {} - """.format( - get_timestamp() - 1.2 - ) + """.format(get_timestamp() - 1.2) ) check = get_check({'metrics': [{'go_memstats_last_gc_time_seconds': {'type': 'time_elapsed'}}]}) dd_run_check(check) diff --git a/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py b/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py index a3a997aaf1b75..9003b2b96060f 100644 --- a/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py +++ b/datadog_checks_base/tests/base/checks/prometheus/test_prometheus.py @@ -368,10 +368,10 @@ def test_submit_gauge_with_labels(mocked_prometheus_check, ref_gauge): _l3.value = 'my_labél_value' _l4 = ref_gauge.metric[0].label.add() _l4.name = 'labél_mix' - _l4.value = u'my_labél_value🇫🇷🇪🇸🇺🇸' + _l4.value = 'my_labél_value🇫🇷🇪🇸🇺🇸' _l5 = ref_gauge.metric[0].label.add() - _l5.name = u'labél_unicode' - _l5.value = u'my_labél_value' + _l5.name = 'labél_unicode' + _l5.value = 'my_labél_value' check = mocked_prometheus_check check._submit(check.metrics_mapper[ref_gauge.name], ref_gauge) check.gauge.assert_called_with( diff --git a/datadog_checks_base/tests/base/checks/test_agent_check.py b/datadog_checks_base/tests/base/checks/test_agent_check.py index d1b9734692a95..4640286249998 100644 --- a/datadog_checks_base/tests/base/checks/test_agent_check.py +++ b/datadog_checks_base/tests/base/checks/test_agent_check.py @@ -337,29 +337,29 @@ def test_agent_signature(case_name, check, expected_attributes): class TestMetricNormalization: def test_default(self): check = AgentCheck() - metric_name = u'Klüft inför på fédéral' + metric_name = 'Klüft inför på fédéral' normalized_metric_name = 'Kluft_infor_pa_federal' assert check.normalize(metric_name) == normalized_metric_name def test_fix_case(self): check = AgentCheck() - metric_name = u'Klüft inför på fédéral' + metric_name = 'Klüft inför på fédéral' normalized_metric_name = 'kluft_infor_pa_federal' assert check.normalize(metric_name, fix_case=True) == normalized_metric_name def test_prefix(self): check = AgentCheck() - metric_name = u'metric' - prefix = u'somePrefix' + metric_name = 'metric' + prefix = 'somePrefix' normalized_metric_name = 'somePrefix.metric' assert check.normalize(metric_name, prefix=prefix) == normalized_metric_name def test_prefix_bytes(self): check = AgentCheck() - metric_name = u'metric' + metric_name = 'metric' prefix = b'some' normalized_metric_name = 'some.metric' @@ -368,7 +368,7 @@ def test_prefix_bytes(self): def test_prefix_unicode_metric_bytes(self): check = AgentCheck() metric_name = b'metric' - prefix = u'some' + prefix = 'some' normalized_metric_name = 'some.metric' assert check.normalize(metric_name, prefix=prefix) == normalized_metric_name @@ -376,35 +376,35 @@ def test_prefix_unicode_metric_bytes(self): def test_prefix_fix_case(self): check = AgentCheck() metric_name = b'metric' - prefix = u'somePrefix' + prefix = 'somePrefix' normalized_metric_name = 'some_prefix.metric' assert check.normalize(metric_name, fix_case=True, prefix=prefix) == normalized_metric_name def test_underscores_redundant(self): check = AgentCheck() - metric_name = u'a_few__redundant___underscores' + metric_name = 'a_few__redundant___underscores' normalized_metric_name = 'a_few_redundant_underscores' assert check.normalize(metric_name) == normalized_metric_name def test_underscores_at_ends(self): check = AgentCheck() - metric_name = u'_some_underscores_' + metric_name = '_some_underscores_' normalized_metric_name = 'some_underscores' assert check.normalize(metric_name) == normalized_metric_name def test_underscores_and_dots(self): check = AgentCheck() - metric_name = u'some_.dots._and_._underscores' + metric_name = 'some_.dots._and_._underscores' normalized_metric_name = 'some.dots.and.underscores' assert check.normalize(metric_name) == normalized_metric_name def test_invalid_chars_and_underscore(self): check = AgentCheck() - metric_name = u'metric.hello++aaa$$_bbb' + metric_name = 'metric.hello++aaa$$_bbb' normalized_metric_name = 'metric.hello_aaa_bbb' assert check.normalize(metric_name) == normalized_metric_name @@ -414,7 +414,7 @@ def test_invalid_chars_and_underscore(self): 'case, tag, expected_tag', [ ('nothing to normalize', 'abc:123', 'abc:123'), - ('unicode', u'Klüft inför på fédéral', 'Klüft_inför_på_fédéral'), + ('unicode', 'Klüft inför på fédéral', 'Klüft_inför_på_fédéral'), ('invalid chars', 'foo,+*-/()[]{}- \t\nbar:123', 'foo_bar:123'), ('leading and trailing underscores', '__abc:123__', 'abc:123'), ('redundant underscore', 'foo_____bar', 'foo_bar'), @@ -467,7 +467,7 @@ def test_valid_event(self, aggregator): check.event(event) aggregator.assert_event('test event test event', tags=["foo", "bar"]) - @pytest.mark.parametrize('msg_text', [u'test-π', 'test-π', b'test-\xcf\x80']) + @pytest.mark.parametrize('msg_text', ['test-π', 'test-π', b'test-\xcf\x80']) def test_encoding(self, aggregator, msg_text): check = AgentCheck() event = { @@ -475,7 +475,7 @@ def test_encoding(self, aggregator, msg_text): 'msg_title': 'new test event', 'aggregation_key': 'test.event', 'msg_text': msg_text, - 'tags': ['∆', u'Ω-bar'], + 'tags': ['∆', 'Ω-bar'], 'timestamp': 1, } check.event(event) @@ -671,7 +671,7 @@ def test_bytes_string(self): def test_unicode_string(self): check = AgentCheck() - tag = u'unicode:string' + tag = 'unicode:string' tags = [tag] normalized_tags = check._normalize_tags_type(tags, None) @@ -683,7 +683,7 @@ def test_unicode_string(self): def test_unicode_device_name(self): check = AgentCheck() tags = [] - device_name = u'unicode_string' + device_name = 'unicode_string' normalized_tags = check._normalize_tags_type(tags, device_name) normalized_device_tag = normalized_tags[0] @@ -718,10 +718,10 @@ def test_external_host_tag_normalization(self): def test_external_hostname(self, datadog_agent): check = AgentCheck() - external_host_tags = [(u'hostnam\xe9', {'src_name': ['key1:val1']})] + external_host_tags = [('hostnam\xe9', {'src_name': ['key1:val1']})] check.set_external_tags(external_host_tags) - datadog_agent.assert_external_tags(u'hostnam\xe9', {'src_name': ['key1:val1']}) + datadog_agent.assert_external_tags('hostnam\xe9', {'src_name': ['key1:val1']}) datadog_agent.assert_external_tags_count(1) @pytest.mark.parametrize( diff --git a/datadog_checks_base/tests/base/utils/db/test_query_manager.py b/datadog_checks_base/tests/base/utils/db/test_query_manager.py index ebabb46d2a7ed..ffb03f5042ecb 100644 --- a/datadog_checks_base/tests/base/utils/db/test_query_manager.py +++ b/datadog_checks_base/tests/base/utils/db/test_query_manager.py @@ -718,8 +718,7 @@ def test_percent_total_not_string(self): with pytest.raises( ValueError, match=( - '^error compiling type `percent` for extra foo of test query: ' - 'the `total` parameter must be a string$' + '^error compiling type `percent` for extra foo of test query: the `total` parameter must be a string$' ), ): query_manager.compile_queries() @@ -910,8 +909,7 @@ def test_log_attributes_not_dict(self): with pytest.raises( ValueError, match=( - '^error compiling type `log` for extra log of test query: ' - 'the `attributes` parameter must be a mapping$' + '^error compiling type `log` for extra log of test query: the `attributes` parameter must be a mapping$' ), ): query_manager.compile_queries() @@ -934,8 +932,7 @@ def test_log_attributes_empty(self): with pytest.raises( ValueError, match=( - '^error compiling type `log` for extra log of test query: ' - 'the `attributes` parameter must not be empty$' + '^error compiling type `log` for extra log of test query: the `attributes` parameter must not be empty$' ), ): query_manager.compile_queries() @@ -1114,9 +1111,9 @@ class MyCheck(AgentCheck): query_manager2 = QueryManager(check2, mock_executor(), [dummy_query]) query_manager1.compile_queries() query_manager2.compile_queries() - assert not id(query_manager1.queries[0]) == id( - query_manager2.queries[0] - ), "QueryManager does not copy the queries" + assert not id(query_manager1.queries[0]) == id(query_manager2.queries[0]), ( + "QueryManager does not copy the queries" + ) def test_query_execution_error(self, caplog, aggregator): class Result(object): diff --git a/datadog_checks_base/tests/base/utils/db/test_timed_cache.py b/datadog_checks_base/tests/base/utils/db/test_timed_cache.py index 30b1b2a2e61e0..119784da7f6e1 100644 --- a/datadog_checks_base/tests/base/utils/db/test_timed_cache.py +++ b/datadog_checks_base/tests/base/utils/db/test_timed_cache.py @@ -16,9 +16,9 @@ def test_set_and_get_item(self): def test_get_with_default(self): cache = TimedCache(600) - assert ( - cache.get('nonexistent', 'default') == 'default' - ), "Should return the default value when the key is not found." + assert cache.get('nonexistent', 'default') == 'default', ( + "Should return the default value when the key is not found." + ) def test_item_deletion(self): cache = TimedCache(600) diff --git a/datadog_checks_base/tests/base/utils/db/test_util.py b/datadog_checks_base/tests/base/utils/db/test_util.py index 2b23ce89b480b..c0ba21369c586 100644 --- a/datadog_checks_base/tests/base/utils/db/test_util.py +++ b/datadog_checks_base/tests/base/utils/db/test_util.py @@ -371,7 +371,7 @@ def test_dbm_async_job_inactive_stop(aggregator): pytest.param({"foo": decimal.Decimal("1.0")}, id='dict-with-decimal'), pytest.param({"foo": datetime.datetime(2020, 1, 1, 0, 0, 0)}, id='dict-with-datetime'), pytest.param({"foo": datetime.date(2020, 1, 1)}, id='dict-with-date'), - pytest.param({"foo": IPv4Address(u"192.168.1.1")}, id='dict-with-IPv4Address'), + pytest.param({"foo": IPv4Address("192.168.1.1")}, id='dict-with-IPv4Address'), ], ) def test_default_json_event_encoding(input): diff --git a/datadog_checks_base/tests/base/utils/http/test_authtoken.py b/datadog_checks_base/tests/base/utils/http/test_authtoken.py index 6b6913c80093a..26b461a699090 100644 --- a/datadog_checks_base/tests/base/utils/http/test_authtoken.py +++ b/datadog_checks_base/tests/base/utils/http/test_authtoken.py @@ -463,8 +463,10 @@ def __init__(self, *args, **kwargs): def fetch_token(self, *args, **kwargs): return {'error': 'unauthorized_client'} - with mock.patch('requests.get'), mock.patch('oauthlib.oauth2.BackendApplicationClient'), mock.patch( - 'requests_oauthlib.OAuth2Session', side_effect=MockOAuth2Session + with ( + mock.patch('requests.get'), + mock.patch('oauthlib.oauth2.BackendApplicationClient'), + mock.patch('requests_oauthlib.OAuth2Session', side_effect=MockOAuth2Session), ): with pytest.raises(Exception, match='OAuth2 client credentials grant error: unauthorized_client'): http.get('https://www.google.com') @@ -503,9 +505,12 @@ def __init__(self, *args, **kwargs): def fetch_token(self, *args, **kwargs): return token_response - with mock.patch('requests.get') as get, mock.patch('oauthlib.oauth2.BackendApplicationClient'), mock.patch( - 'requests_oauthlib.OAuth2Session', side_effect=MockOAuth2Session - ), mock.patch('datadog_checks.base.utils.http.get_timestamp', return_value=0): + with ( + mock.patch('requests.get') as get, + mock.patch('oauthlib.oauth2.BackendApplicationClient'), + mock.patch('requests_oauthlib.OAuth2Session', side_effect=MockOAuth2Session), + mock.patch('datadog_checks.base.utils.http.get_timestamp', return_value=0), + ): http.get('https://www.google.com') get.assert_called_with( @@ -550,8 +555,10 @@ def fetch_token(self, *args, **kwargs): assert kwargs['audience'] == 'http://example.com' return {'access_token': 'foo', 'expires_in': 9000} - with mock.patch('requests.get') as get, mock.patch('oauthlib.oauth2.BackendApplicationClient'), mock.patch( - 'requests_oauthlib.OAuth2Session', side_effect=MockOAuth2Session + with ( + mock.patch('requests.get') as get, + mock.patch('oauthlib.oauth2.BackendApplicationClient'), + mock.patch('requests_oauthlib.OAuth2Session', side_effect=MockOAuth2Session), ): http.get('https://www.google.com') diff --git a/datadog_checks_base/tests/base/utils/http/test_http.py b/datadog_checks_base/tests/base/utils/http/test_http.py index 23e426d5cb26d..0419e05bf9aa4 100644 --- a/datadog_checks_base/tests/base/utils/http/test_http.py +++ b/datadog_checks_base/tests/base/utils/http/test_http.py @@ -53,8 +53,9 @@ def test_cipher_construction(self, instance, expected_ciphers): http = RequestsWrapper(instance, init_config) mock_socket = mock.MagicMock() - with mock.patch.object(ssl.SSLContext, 'set_ciphers') as mock_set_ciphers, mock.patch( - 'datadog_checks.base.utils.http.create_socket_connection', return_value=mock_socket + with ( + mock.patch.object(ssl.SSLContext, 'set_ciphers') as mock_set_ciphers, + mock.patch('datadog_checks.base.utils.http.create_socket_connection', return_value=mock_socket), ): http.fetch_intermediate_certs('https://www.google.com') mock_set_ciphers.assert_called_once_with(expected_ciphers) diff --git a/datadog_checks_base/tests/base/utils/test_utils.py b/datadog_checks_base/tests/base/utils/test_utils.py index 53cd8eb86ec30..497efa87fbe2b 100644 --- a/datadog_checks_base/tests/base/utils/test_utils.py +++ b/datadog_checks_base/tests/base/utils/test_utils.py @@ -203,12 +203,12 @@ def test_ensure_bytes(self): assert ensure_bytes('qwerty') == b'qwerty' def test_ensure_unicode(self): - assert ensure_unicode('éâû') == u'éâû' - assert ensure_unicode(u'éâû') == u'éâû' + assert ensure_unicode('éâû') == 'éâû' + assert ensure_unicode('éâû') == 'éâû' def test_to_native_string(self): # type: () -> None - text = u'éâû' + text = 'éâû' binary = text.encode('utf-8') assert to_native_string(binary) == text diff --git a/datadog_checks_base/tests/models/test_types.py b/datadog_checks_base/tests/models/test_types.py index c37561d3564f0..10ae0de15cd13 100644 --- a/datadog_checks_base/tests/models/test_types.py +++ b/datadog_checks_base/tests/models/test_types.py @@ -7,7 +7,6 @@ def test_make_immutable(): - obj = make_immutable( { 'string': 'foo', diff --git a/datadog_checks_base/tests/stubs/test_assert_metric.py b/datadog_checks_base/tests/stubs/test_assert_metric.py index dec114fa51f61..8c86dd112650c 100644 --- a/datadog_checks_base/tests/stubs/test_assert_metric.py +++ b/datadog_checks_base/tests/stubs/test_assert_metric.py @@ -6,7 +6,6 @@ class TestAssertMetric: - def test_assert_metric_hostname(self, aggregator): check = AgentCheck() diff --git a/datadog_checks_base/tests/test_log.py b/datadog_checks_base/tests/test_log.py index fef735203a8b2..a23fa2af063ec 100644 --- a/datadog_checks_base/tests/test_log.py +++ b/datadog_checks_base/tests/test_log.py @@ -18,9 +18,9 @@ def test_get_py_loglevel(): # default value for invalid input assert log._get_py_loglevel(None) == logging.INFO # default value for valid unicode input encoding into an invalid key - assert log._get_py_loglevel(u'dèbùg') == logging.INFO + assert log._get_py_loglevel('dèbùg') == logging.INFO # check unicode works - assert log._get_py_loglevel(u'crit') == logging.CRITICAL + assert log._get_py_loglevel('crit') == logging.CRITICAL # check string works assert log._get_py_loglevel('crit') == logging.CRITICAL diff --git a/datadog_checks_base/tests/test_metadata.py b/datadog_checks_base/tests/test_metadata.py index 8e028fed1721f..4a0ef129bf1b5 100644 --- a/datadog_checks_base/tests/test_metadata.py +++ b/datadog_checks_base/tests/test_metadata.py @@ -59,8 +59,8 @@ def test_encoding(self): constructor = ensure_bytes finalizer = ensure_unicode - name = constructor(u'nam\u00e9') - value = constructor(u'valu\u00e9') + name = constructor('nam\u00e9') + value = constructor('valu\u00e9') with mock.patch(SET_CHECK_METADATA_METHOD) as m: check.set_metadata(name, value) diff --git a/datadog_checks_dev/datadog_checks/dev/ci.py b/datadog_checks_dev/datadog_checks/dev/ci.py index cf97577b660e7..5b2024434ce02 100644 --- a/datadog_checks_dev/datadog_checks/dev/ci.py +++ b/datadog_checks_dev/datadog_checks/dev/ci.py @@ -4,6 +4,7 @@ """ CI utilities """ + import os diff --git a/datadog_checks_dev/datadog_checks/dev/conditions.py b/datadog_checks_dev/datadog_checks/dev/conditions.py index d4c228c259780..8123b717b2941 100644 --- a/datadog_checks_dev/datadog_checks/dev/conditions.py +++ b/datadog_checks_dev/datadog_checks/dev/conditions.py @@ -95,7 +95,7 @@ def __call__(self): time.sleep(self.wait) else: - raise RetryError('Endpoint: {}\n' 'Error: {}'.format(last_endpoint, last_error)) + raise RetryError('Endpoint: {}\nError: {}'.format(last_endpoint, last_error)) class CheckCommandOutput(LazyFunction): @@ -169,11 +169,11 @@ def __call__(self): patterns = '\t- '.join([''] + [str(p) for p in self.patterns]) missing_patterns = '\t- '.join([''] + [str(p) for p in missing_patterns]) raise RetryError( - u'Command: {}\nFailed to match `{}` of the patterns.\n' - u'Provided patterns: {}\n' - u'Missing patterns: {}\n' - u'Exit code: {}\n' - u'Captured Output: {}'.format( + 'Command: {}\nFailed to match `{}` of the patterns.\n' + 'Provided patterns: {}\n' + 'Missing patterns: {}\n' + 'Exit code: {}\n' + 'Captured Output: {}'.format( self.command, self.matches, patterns, missing_patterns, exit_code, log_output ) ) diff --git a/datadog_checks_dev/datadog_checks/dev/fs.py b/datadog_checks_dev/datadog_checks/dev/fs.py index 6c94e9ae63915..a71a3cea084e1 100644 --- a/datadog_checks_dev/datadog_checks/dev/fs.py +++ b/datadog_checks_dev/datadog_checks/dev/fs.py @@ -5,6 +5,7 @@ Filesystem utility functions abstracting common operations, specially designed to be used by Integrations within tests. """ + import inspect import os import shutil diff --git a/datadog_checks_dev/datadog_checks/dev/subprocess.py b/datadog_checks_dev/datadog_checks/dev/subprocess.py index 9dd7aae87b2d8..5fbb904369ff3 100644 --- a/datadog_checks_dev/datadog_checks/dev/subprocess.py +++ b/datadog_checks_dev/datadog_checks/dev/subprocess.py @@ -73,7 +73,7 @@ def run_command(command, capture=None, check=False, encoding='utf-8', shell=Fals if check and process.returncode != 0: raise SubprocessError( - 'Command: {}\n' 'Exit code: {}\n' 'Captured Output: {}'.format(command, process.returncode, stdout + stderr) + 'Command: {}\nExit code: {}\nCaptured Output: {}'.format(command, process.returncode, stdout + stderr) ) return SubprocessResult(stdout, stderr, process.returncode) diff --git a/datadog_checks_dev/datadog_checks/dev/testing.py b/datadog_checks_dev/datadog_checks/dev/testing.py index 5fe0e66f3f692..71cee594a54a5 100644 --- a/datadog_checks_dev/datadog_checks/dev/testing.py +++ b/datadog_checks_dev/datadog_checks/dev/testing.py @@ -3,6 +3,7 @@ # Licensed under a 3-clause BSD style license (see LICENSE) """This module contains test annotations""" + import pytest from .utils import ON_MACOS, ON_WINDOWS diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/create.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/create.py index c3895080deabc..37723aa48bf1b 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/create.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/create.py @@ -234,9 +234,7 @@ def create(ctx, name, integration_type, location, non_interactive, quiet, dry_ru # Fill in all common non Marketplace fields template_fields['pricing_plan'] = '' if repo_choice in ['core', 'integrations-internal-core']: - template_fields[ - 'author_info' - ] = """ + template_fields['author_info'] = """ "author": { "support_email": "help@datadoghq.com", "name": "Datadog", @@ -246,9 +244,7 @@ def create(ctx, name, integration_type, location, non_interactive, quiet, dry_ru else: prompt_and_update_if_missing(template_fields, 'email', 'Email used for support requests') prompt_and_update_if_missing(template_fields, 'author', 'Your name') - template_fields[ - 'author_info' - ] = f""" + template_fields['author_info'] = f""" "author": {{ "support_email": "{template_fields['email']}", "name": "{template_fields['author']}", diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/prometheus.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/prometheus.py index 09a0bed69581a..7a6e6e6fc37f7 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/prometheus.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/prometheus.py @@ -50,7 +50,7 @@ def parse_metrics(stream): def get_options_text(options): - return '\n{}\n' 'q - Quit'.format('\n'.join('{} - {}'.format(n, option) for n, option in enumerate(options, 1))) + return '\n{}\nq - Quit'.format('\n'.join('{} - {}'.format(n, option) for n, option in enumerate(options, 1))) def set_up_stream(ctx, endpoint, filehandle): @@ -243,16 +243,14 @@ def parse(ctx, endpoint, fh, check, here): write_file_lines(metadata_file, output_lines) echo_success('success!') - metric_map = ( - 'METRIC_MAP = {{\n' - '{}\n' - '}}'.format('\n'.join(" '{}': '{}',".format(metric, data['dd_name']) for metric, data in metric_items)) + metric_map = 'METRIC_MAP = {{\n{}\n}}'.format( + '\n'.join(" '{}': '{}',".format(metric, data['dd_name']) for metric, data in metric_items) ) echo_info(metric_map) - metric_list = ( - '\nMETRICS = [\n' '{}\n' ']'.format('\n'.join(" '{}',".format(data['dd_name']) for _, data in metric_items)) + metric_list = '\nMETRICS = [\n{}\n]'.format( + '\n'.join(" '{}',".format(data['dd_name']) for _, data in metric_items) ) echo_info(metric_list) diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py index 2ff772fce8910..58aeea737620b 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/generate_profile.py @@ -311,7 +311,7 @@ def _compile_mib_to_json(mib, source_mib_directories, destination_directory, sou 'textFilter': False and (lambda symbol, text: text) or None, 'writeMibs': True, 'ignoreErrors': False, - } + }, ) return processed diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/validators/validator.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/validators/validator.py index 24ea2bab4de6d..fe71c79987a0b 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/validators/validator.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/meta/snmp/validators/validator.py @@ -270,9 +270,7 @@ def validate(self, profile, path): if not all_metric_tags_are_valid: self.fail( "metric_tables defined in lines {} are not valid. \ - \nmetric_tags must have 'column' or 'index' value".format( - lines - ) + \nmetric_tags must have 'column' or 'index' value".format(lines) ) if not self.result.failed: diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/show/ready.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/show/ready.py index 66c749b1e9204..7e8f58604e99d 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/show/ready.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/show/ready.py @@ -64,7 +64,7 @@ def ready(ctx, quiet): if quiet: msg = target else: - msg = 'Check {} has {} out of {} merged PRs that could be released' ''.format( + msg = 'Check {} has {} out of {} merged PRs that could be released'.format( target, shippable_prs, len(pr_numbers) ) echo_info(msg) diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/stats/stats.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/stats/stats.py index 7a75bb3f01453..70921cc02e7d6 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/stats/stats.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/release/stats/stats.py @@ -121,7 +121,6 @@ def merged_prs(ctx, from_ref, to_ref, release_milestone, exclude_releases, expor @click.option('--release-milestone', '-r', help="Github release milestone", required=True) @click.pass_context def report(ctx, from_ref, to_ref, release_milestone): - agent_release = Release.from_github(ctx, 'datadog-agent', release_milestone, from_ref=from_ref, to_ref=to_ref) integrations_release = Release.from_github( ctx, 'integrations-core', release_milestone, from_ref=from_ref, to_ref=to_ref diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/dashboards.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/dashboards.py index 07db22bcef0c2..5933d1630d1a5 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/dashboards.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/dashboards.py @@ -43,7 +43,6 @@ def _is_dashboard_format(payload): def check_widgets(decoded, filename, app_uuid, fix, file_fixed, file_failed, display_queue): """Recursively check the decoded dashboard object for widget references and validate the app_id inside.""" for widget in decoded.get('widgets', []): - if widget.get('definition', {}).get('widgets'): decoded = {'widgets': widget['definition']['widgets']} file_fixed, file_failed = check_widgets( diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/package.py b/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/package.py index 4d2e623ca540d..e4ead6015b4cc 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/package.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/package.py @@ -93,7 +93,7 @@ def package(check): display_queue.append( ( echo_failure, - f' Invalid email(s) found in {check}/pyproject.toml: ' f'{", ".join(invalid_emails)}.', + f' Invalid email(s) found in {check}/pyproject.toml: {", ".join(invalid_emails)}.', ) ) diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/configuration/template.py b/datadog_checks_dev/datadog_checks/dev/tooling/configuration/template.py index 1478c84b44126..b21078c347992 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/configuration/template.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/configuration/template.py @@ -52,7 +52,9 @@ def load(self, template): if branch in data: data = data[branch] else: - raise ValueError(f"Template `{'/'.join(path_parts)}` has no element `{'.'.join(branches[:i + 1])}`") + raise ValueError( + f"Template `{'/'.join(path_parts)}` has no element `{'.'.join(branches[: i + 1])}`" + ) elif isinstance(data, list): for item in data: if isinstance(item, dict) and item.get('name') == branch: diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/license_headers.py b/datadog_checks_dev/datadog_checks/dev/tooling/license_headers.py index 8d02a583f5458..3da34b14e37d8 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/license_headers.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/license_headers.py @@ -56,7 +56,6 @@ def validate_license_headers( ignoreset = set(ignore or []) def walk_recursively(path, gitignore_matcher): - for child in path.iterdir(): # Skip gitignored files if gitignore_matcher.match(child): diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/common/validator.py b/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/common/validator.py index add075a5cf969..af54163fde288 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/common/validator.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/common/validator.py @@ -86,7 +86,6 @@ def __repr__(self): class MaintainerValidator(BaseManifestValidator): - MAINTAINER_PATH = {V1: '/maintainer', V2: '/author/support_email'} def validate(self, check_name, decoded, fix): @@ -110,7 +109,6 @@ def validate(self, check_name, decoded, fix): class MetricsMetadataValidator(BaseManifestValidator): - METADATA_PATH = {V1: "/assets/metrics_metadata", V2: "/assets/integration/metrics/metadata_path"} def validate(self, check_name, decoded, fix): diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/v2/migration.py b/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/v2/migration.py index 088915fd7ed1c..c8d4f6bb6630c 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/v2/migration.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/manifest_validator/v2/migration.py @@ -112,7 +112,6 @@ def migrate_manifest(repo_name, integration, to_version): - loaded_manifest = JSONDict(load_manifest(integration)) manifest_version = loaded_manifest.get_path("/manifest_version") diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/testing.py b/datadog_checks_dev/datadog_checks/dev/tooling/testing.py index 5430f759f6b82..5c04c0e8303d0 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/testing.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/testing.py @@ -268,7 +268,6 @@ def select_hatch_envs( latest, env_filter_re, ): - available_envs = get_available_hatch_envs(check, sort, e2e_tests_only=e2e_tests_only) if style or format_style: diff --git a/datadog_checks_dev/datadog_checks/dev/tooling/utils.py b/datadog_checks_dev/datadog_checks/dev/tooling/utils.py index bb2e8ed624d3f..3b855d4dd8264 100644 --- a/datadog_checks_dev/datadog_checks/dev/tooling/utils.py +++ b/datadog_checks_dev/datadog_checks/dev/tooling/utils.py @@ -170,7 +170,13 @@ def initialize_root(config, agent=False, core=False, extras=False, marketplace=F repo_choice = ( 'core' if core - else 'extras' if extras else 'agent' if agent else 'marketplace' if marketplace else config.get('repo', 'core') + else 'extras' + if extras + else 'agent' + if agent + else 'marketplace' + if marketplace + else config.get('repo', 'core') ) config['repo_choice'] = repo_choice message = None @@ -182,7 +188,9 @@ def initialize_root(config, agent=False, core=False, extras=False, marketplace=F repo = ( 'datadog-agent' if repo_choice == 'agent' - else 'marketplace' if repo_choice == 'marketplace' else f'integrations-{repo_choice}' + else 'marketplace' + if repo_choice == 'marketplace' + else f'integrations-{repo_choice}' ) message = f'`{repo}` directory `{root}` does not exist, defaulting to the current location.' diff --git a/datadog_checks_dev/datadog_checks/dev/utils.py b/datadog_checks_dev/datadog_checks/dev/utils.py index d4ffd2ce66361..13cfd398fdb24 100644 --- a/datadog_checks_dev/datadog_checks/dev/utils.py +++ b/datadog_checks_dev/datadog_checks/dev/utils.py @@ -5,6 +5,7 @@ Utilities functions abstracting common operations, specially designed to be used by Integrations within tests. """ + import csv import inspect import json diff --git a/datadog_checks_dev/tests/test_kind.py b/datadog_checks_dev/tests/test_kind.py index 3b91da584351b..6dae58ade8773 100644 --- a/datadog_checks_dev/tests/test_kind.py +++ b/datadog_checks_dev/tests/test_kind.py @@ -33,8 +33,10 @@ def test_retry_on_failed_conditions(self, attempts, expected_call_count): else: expected_exception = Exception - with pytest.raises(expected_exception), patch('datadog_checks.dev.kind.KindUp'), patch( - 'datadog_checks.dev.kind.KindDown' + with ( + pytest.raises(expected_exception), + patch('datadog_checks.dev.kind.KindUp'), + patch('datadog_checks.dev.kind.KindDown'), ): with kind_run(attempts=attempts, conditions=[condition], attempts_wait=0): pass @@ -48,8 +50,9 @@ def test_retry_condition_failed_only_on_first_run(self): up = MagicMock() up.return_value = "" - with patch('datadog_checks.dev.kind.KindUp', return_value=up), patch( - 'datadog_checks.dev.kind.KindDown', return_value=MagicMock() + with ( + patch('datadog_checks.dev.kind.KindUp', return_value=up), + patch('datadog_checks.dev.kind.KindDown', return_value=MagicMock()), ): with kind_run(attempts=3, conditions=[condition], attempts_wait=0): pass diff --git a/datadog_checks_dev/tests/tooling/commands/validate/test_config.py b/datadog_checks_dev/tests/tooling/commands/validate/test_config.py index 938c33bd37467..010997b7121a2 100644 --- a/datadog_checks_dev/tests/tooling/commands/validate/test_config.py +++ b/datadog_checks_dev/tests/tooling/commands/validate/test_config.py @@ -25,7 +25,6 @@ def test_validate_config_spec_file_mandatory_in_core(repo, expect_failure): runner = CliRunner() with runner.isolated_filesystem(): - # Generate the check structure working_repo = 'integrations-{}'.format(repo) shutil.copytree( diff --git a/datadog_checks_dev/tests/tooling/commands/validate/test_models.py b/datadog_checks_dev/tests/tooling/commands/validate/test_models.py index 6c966ac610289..f2afdf366a04b 100644 --- a/datadog_checks_dev/tests/tooling/commands/validate/test_models.py +++ b/datadog_checks_dev/tests/tooling/commands/validate/test_models.py @@ -25,7 +25,6 @@ def test_generate_new_files_check_licenses(repo, expect_licenses): runner = CliRunner() with runner.isolated_filesystem(): - # Generate the check structure working_repo = 'integrations-{}'.format(repo) shutil.copytree( @@ -68,7 +67,6 @@ def test_validate_config_models_not_in_sync(repo, expect_failure): runner = CliRunner() with runner.isolated_filesystem(): - # Generate the check structure working_repo = 'integrations-{}'.format(repo) shutil.copytree( @@ -111,7 +109,6 @@ def test_validate_no_config_models(repo, expect_failure): runner = CliRunner() with runner.isolated_filesystem(): - # Generate the check structure working_repo = 'integrations-{}'.format(repo) shutil.copytree( diff --git a/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py b/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py index 9fae1eb639c25..00cb8779a7264 100644 --- a/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py +++ b/datadog_checks_dev/tests/tooling/configuration/consumers/test_example.py @@ -867,9 +867,7 @@ def test_section_description_length_limit(): description: words value: type: string - """.format( - 'a' * DESCRIPTION_LINE_LENGTH_LIMIT - ) + """.format('a' * DESCRIPTION_LINE_LENGTH_LIMIT) ) files = consumer.render() @@ -890,9 +888,7 @@ def test_option_description_length_limit(): description: {} value: type: string - """.format( - 'a' * DESCRIPTION_LINE_LENGTH_LIMIT - ) + """.format('a' * DESCRIPTION_LINE_LENGTH_LIMIT) ) files = consumer.render() @@ -914,9 +910,7 @@ def test_option_description_length_limit_with_noqa(): value: type: string example: something - """.format( - 'a' * DESCRIPTION_LINE_LENGTH_LIMIT + ' /noqa' - ) + """.format('a' * DESCRIPTION_LINE_LENGTH_LIMIT + ' /noqa') ) files = consumer.render() @@ -928,9 +922,7 @@ def test_option_description_length_limit_with_noqa(): ## {} # # foo: something - """.format( - 'a' * DESCRIPTION_LINE_LENGTH_LIMIT - ) + """.format('a' * DESCRIPTION_LINE_LENGTH_LIMIT) ) @@ -1211,9 +1203,7 @@ def test_compact_example_long_line(): type: array items: type: string - """.format( - long_str - ) + """.format(long_str) ) files = consumer.render() contents, errors = files['test.yaml.example'] @@ -1225,9 +1215,7 @@ def test_compact_example_long_line(): # # foo: # - [{0}, {0}, {0}, {0}] - """.format( - long_str - ) + """.format(long_str) )