Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .changelog/4742.changed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set ruff line-length to 120 and enforce E501 across the repository
8 changes: 2 additions & 6 deletions .github/workflows/generate_workflows_lib/hatch_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
with open(
Path(__file__).parent.parent.parent.parent.joinpath("tox.ini")
) as tox_ini_file_0:
with open(Path(__file__).parent.parent.parent.parent.joinpath("tox.ini")) as tox_ini_file_0:
with open(
Path(__file__).parent.joinpath(
"src/generate_workflows_lib/tox.ini"
),
Path(__file__).parent.joinpath("src/generate_workflows_lib/tox.ini"),
"w",
) as tox_ini_file_1:
tox_ini_file_1.write(tox_ini_file_0.read())
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
r"(?P<name>[-\w]+\w)-?(?P<test_requirements>\d+)?"
)
_tox_lint_env_regex = re_compile(r"lint-(?P<name>[-\w]+)")
_tox_contrib_env_regex = re_compile(
r"py310-test-(?P<name>[-\w]+\w)-?(?P<contrib_requirements>\d+)?"
)
_tox_contrib_env_regex = re_compile(r"py310-test-(?P<name>[-\w]+\w)-?(?P<contrib_requirements>\d+)?")


def get_tox_envs(tox_ini_path: Path) -> list:
Expand All @@ -25,9 +23,7 @@ def get_tox_envs(tox_ini_path: Path) -> list:

tox_section = next(tox_ini.sections())

core_config_set = CoreConfigSet(
conf, tox_section, tox_ini_path.parent, tox_ini_path
)
core_config_set = CoreConfigSet(conf, tox_section, tox_ini_path.parent, tox_ini_path)

(
core_config_set.loaders.extend(
Expand Down Expand Up @@ -66,9 +62,7 @@ def get_test_job_datas(tox_envs: list, operating_systems: list) -> list:

groups = tox_test_env_match.groupdict()

aliased_python_version = python_version_alias[
groups["python_version"]
]
aliased_python_version = python_version_alias[groups["python_version"]]
tox_env = tox_test_env_match.string

test_requirements = groups["test_requirements"]
Expand All @@ -83,10 +77,7 @@ def get_test_job_datas(tox_envs: list, operating_systems: list) -> list:
{
"name": f"{tox_env}_{operating_system}",
"ui_name": (
f"{groups['name']}"
f"{test_requirements}"
f"{aliased_python_version} "
f"{os_alias[operating_system]}"
f"{groups['name']}{test_requirements}{aliased_python_version} {os_alias[operating_system]}"
),
"python_version": aliased_python_version,
"tox_env": tox_env,
Expand Down Expand Up @@ -169,13 +160,9 @@ def get_misc_job_datas(tox_envs: list) -> list:
return misc_job_datas


def _generate_workflow(
job_datas: list, name: str, workflow_directory_path: Path
) -> None:
def _generate_workflow(job_datas: list, name: str, workflow_directory_path: Path) -> None:
env = Environment(loader=FileSystemLoader(Path(__file__).parent))
with open(
workflow_directory_path.joinpath(f"{name}.yml"), "w"
) as yml_file:
with open(workflow_directory_path.joinpath(f"{name}.yml"), "w") as yml_file:
yml_file.write(
env.get_template(f"{name}.yml.j2").render(
job_datas=job_datas,
Expand All @@ -184,9 +171,7 @@ def _generate_workflow(
yml_file.write("\n")


def generate_test_workflow(
tox_ini_path: Path, workflow_directory_path: Path, *operating_systems
) -> None:
def generate_test_workflow(tox_ini_path: Path, workflow_directory_path: Path, *operating_systems) -> None:
_generate_workflow(
get_test_job_datas(get_tox_envs(tox_ini_path), operating_systems),
"test",
Expand All @@ -209,9 +194,7 @@ def generate_contrib_workflow(
workflow_directory_path: Path,
) -> None:
_generate_workflow(
get_contrib_job_datas(
get_tox_envs(Path(__file__).parent.joinpath("tox.ini"))
),
get_contrib_job_datas(get_tox_envs(Path(__file__).parent.joinpath("tox.ini"))),
"core_contrib_test",
workflow_directory_path,
)
Expand All @@ -233,8 +216,6 @@ def generate_ci_workflow(
) -> None:
with open(workflow_directory_path.joinpath("ci.yml"), "w") as ci_yml_file:
ci_yml_file.write(
Environment(loader=FileSystemLoader(Path(__file__).parent))
.get_template("ci.yml.j2")
.render()
Environment(loader=FileSystemLoader(Path(__file__).parent)).get_template("ci.yml.j2").render()
)
ci_yml_file.write("\n")
62 changes: 10 additions & 52 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,70 +30,33 @@
source_dirs = []

exp = "../exporter"
exp_dirs = [
os.path.abspath("/".join([exp, f, "src"]))
for f in listdir(exp)
if isdir(join(exp, f))
]
exp_dirs = [os.path.abspath("/".join([exp, f, "src"])) for f in listdir(exp) if isdir(join(exp, f))]

instr = "../instrumentation"
instr_dirs = [
os.path.abspath("/".join([instr, f, "src"]))
for f in listdir(instr)
if isdir(join(instr, f))
]
instr_dirs = [os.path.abspath("/".join([instr, f, "src"])) for f in listdir(instr) if isdir(join(instr, f))]

instr_genai = "../instrumentation-genai"
instr_genai_dirs = [
os.path.abspath("/".join([instr_genai, f, "src"]))
for f in listdir(instr_genai)
if isdir(join(instr_genai, f))
os.path.abspath("/".join([instr_genai, f, "src"])) for f in listdir(instr_genai) if isdir(join(instr_genai, f))
]

prop = "../propagator"
prop_dirs = [
os.path.abspath("/".join([prop, f, "src"]))
for f in listdir(prop)
if isdir(join(prop, f))
]
prop_dirs = [os.path.abspath("/".join([prop, f, "src"])) for f in listdir(prop) if isdir(join(prop, f))]

sdk_ext = "../sdk-extension"
sdk_ext_dirs = [
os.path.abspath("/".join([sdk_ext, f, "src"]))
for f in listdir(sdk_ext)
if isdir(join(sdk_ext, f))
]
sdk_ext_dirs = [os.path.abspath("/".join([sdk_ext, f, "src"])) for f in listdir(sdk_ext) if isdir(join(sdk_ext, f))]

resource = "../resource"
resource_dirs = [
os.path.abspath("/".join([resource, f, "src"]))
for f in listdir(resource)
if isdir(join(resource, f))
]
resource_dirs = [os.path.abspath("/".join([resource, f, "src"])) for f in listdir(resource) if isdir(join(resource, f))]

util = "../util"
util_dirs = [
os.path.abspath("/".join([util, f, "src"]))
for f in listdir(util)
if isdir(join(util, f))
]
util_dirs = [os.path.abspath("/".join([util, f, "src"])) for f in listdir(util) if isdir(join(util, f))]

opamp = "../opamp"
opamp_dirs = [
os.path.abspath("/".join([opamp, f, "src"]))
for f in listdir(opamp)
if isdir(join(opamp, f))
]
opamp_dirs = [os.path.abspath("/".join([opamp, f, "src"])) for f in listdir(opamp) if isdir(join(opamp, f))]

sys.path[:0] = (
exp_dirs
+ instr_dirs
+ instr_genai_dirs
+ sdk_ext_dirs
+ prop_dirs
+ resource_dirs
+ util_dirs
+ opamp_dirs
exp_dirs + instr_dirs + instr_genai_dirs + sdk_ext_dirs + prop_dirs + resource_dirs + util_dirs + opamp_dirs
)

# -- Project information -----------------------------------------------------
Expand Down Expand Up @@ -175,12 +138,7 @@


def getlistcfg(strval):
return [
val.strip()
for line in strval.split("\n")
for val in line.split(",")
if val.strip()
]
return [val.strip() for line in strval.split("\n") for val in line.split(",") if val.strip()]


ignore_categories = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ def create_google_grpc_credentials() -> grpc.ChannelCredentials:
credentials, _ = google.auth.default()
return grpc.composite_channel_credentials(
grpc.ssl_channel_credentials(),
grpc.metadata_call_credentials(
AuthMetadataPlugin(credentials=credentials, request=Request())
),
grpc.metadata_call_credentials(AuthMetadataPlugin(credentials=credentials, request=Request())),
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ class TestOTLPTraceAutoInstrumentGcpCredential(TestCase):
_OTEL_PYTHON_EXPORTER_OTLP_GRPC_TRACES_CREDENTIAL_PROVIDER: "gcp_grpc_credentials",
},
)
def test_loads_otlp_exporters_with_google_creds(
self, mock_default: MagicMock
): # pylint: disable=no-self-use
def test_loads_otlp_exporters_with_google_creds(self, mock_default: MagicMock): # pylint: disable=no-self-use
"""Test that OTel configuration internals can load the credentials from entrypoint by
name"""
mock_credentials = MagicMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def basic_auth(self, basic_auth: Dict):
raise ValueError("username required in basic_auth")
if "password_file" in basic_auth:
if "password" in basic_auth:
raise ValueError(
"basic_auth cannot contain password and password_file"
)
raise ValueError("basic_auth cannot contain password and password_file")
with open( # pylint: disable=unspecified-encoding
basic_auth["password_file"]
) as file:
Expand Down Expand Up @@ -145,13 +143,9 @@ def tls_config(self, tls_config: Dict):
new_config["cert_file"] = tls_config["cert_file"]
new_config["key_file"] = tls_config["key_file"]
elif "cert_file" in tls_config or "key_file" in tls_config:
raise ValueError(
"tls_config requires both cert_file and key_file"
)
raise ValueError("tls_config requires both cert_file and key_file")
if "insecure_skip_verify" in tls_config:
new_config["insecure_skip_verify"] = tls_config[
"insecure_skip_verify"
]
new_config["insecure_skip_verify"] = tls_config["insecure_skip_verify"]
self._tls_config = tls_config

@property
Expand Down Expand Up @@ -180,9 +174,7 @@ def export(
return MetricExportResult.SUCCESS
timeseries = self._translate_data(metrics_data)
if not timeseries:
logger.error(
"All records contain unsupported aggregators, export aborted"
)
logger.error("All records contain unsupported aggregators, export aborted")
return MetricExportResult.FAILURE
message = self._build_message(timeseries)
headers = self._build_headers()
Expand All @@ -196,22 +188,16 @@ def _translate_data(self, data: MetricsData) -> Sequence[TimeSeries]:
# OTLP Data model suggests combining some attrs into job/instance
# Should we do that here?
if self.resources_as_labels:
resource_labels = [
(n, str(v)) for n, v in resource.attributes.items()
]
resource_labels = [(n, str(v)) for n, v in resource.attributes.items()]
else:
resource_labels = []
# Scope name/version probably not too useful from a labeling perspective
for scope_metrics in resource_metrics.scope_metrics:
for metric in scope_metrics.metrics:
rw_timeseries.extend(
self._parse_metric(metric, resource_labels)
)
rw_timeseries.extend(self._parse_metric(metric, resource_labels))
return rw_timeseries

def _parse_metric(
self, metric: Metric, resource_labels: Sequence
) -> Sequence[TimeSeries]:
def _parse_metric(self, metric: Metric, resource_labels: Sequence) -> Sequence[TimeSeries]:
"""
Parses the Metric & lower objects, then converts the output into
OM TimeSeries. Returns a List of TimeSeries objects based on one Metric
Expand Down Expand Up @@ -247,9 +233,7 @@ def _convert_to_timeseries(
timeseries = []
for labels, samples in sample_sets.items():
ts = TimeSeries()
for label_name, label_value in sorted(
chain(resource_labels, labels)
):
for label_name, label_value in sorted(chain(resource_labels, labels)):
# Previous implementation did not str() the names...
ts.labels.append(self._label(label_name, str(label_value)))
for value, timestamp in samples:
Expand Down Expand Up @@ -312,28 +296,18 @@ def handle_bucket(value, bound=None, name_override=None):
return tuple(ts_attrs), ts_sample

for bound_pos, bound in enumerate(data_point.explicit_bounds):
sample_attr_pairs.append(
handle_bucket(data_point.bucket_counts[bound_pos], bound)
)
sample_attr_pairs.append(handle_bucket(data_point.bucket_counts[bound_pos], bound))

# Add the last label for implicit +inf bucket
sample_attr_pairs.append(
handle_bucket(data_point.bucket_counts[-1], bound="+Inf")
)
sample_attr_pairs.append(handle_bucket(data_point.bucket_counts[-1], bound="+Inf"))

# Lastly, add series for count & sum
sample_attr_pairs.append(
handle_bucket(data_point.sum, name_override=f"{name}_sum")
)
sample_attr_pairs.append(
handle_bucket(data_point.count, name_override=f"{name}_count")
)
sample_attr_pairs.append(handle_bucket(data_point.sum, name_override=f"{name}_sum"))
sample_attr_pairs.append(handle_bucket(data_point.count, name_override=f"{name}_count"))
return sample_attr_pairs

def _parse_data_point(self, data_point, name=None):
attrs = tuple(data_point.attributes.items()) + (
("__name__", self._sanitize_string(name, "name")),
)
attrs = tuple(data_point.attributes.items()) + (("__name__", self._sanitize_string(name, "name")),)
sample = (data_point.value, (data_point.time_unix_nano // 1_000_000))
return attrs, sample

Expand All @@ -355,9 +329,7 @@ def _build_headers(self) -> Dict:
headers[header_name] = header_value
return headers

def _send_message(
self, message: bytes, headers: Dict
) -> MetricExportResult:
def _send_message(self, message: bytes, headers: Dict) -> MetricExportResult:
auth = None
if self.basic_auth:
auth = (self.basic_auth["username"], self.basic_auth["password"])
Expand All @@ -370,10 +342,7 @@ def _send_message(
elif "insecure_skip_verify" in self.tls_config:
verify = self.tls_config["insecure_skip_verify"]

if (
"cert_file" in self.tls_config
and "key_file" in self.tls_config
):
if "cert_file" in self.tls_config and "key_file" in self.tls_config:
cert = (
self.tls_config["cert_file"],
self.tls_config["key_file"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@

@pytest.fixture
def prom_rw():
return PrometheusRemoteWriteMetricsExporter(
"http://victoria:8428/api/v1/write"
)
return PrometheusRemoteWriteMetricsExporter("http://victoria:8428/api/v1/write")


@pytest.fixture
Expand All @@ -34,13 +32,9 @@ def metric(request):
type_ = random.choice(["gauge", "sum"])

if type_ == "gauge":
return metric_util._generate_gauge(
"test.gauge", random.randint(0, 100)
)
return metric_util._generate_gauge("test.gauge", random.randint(0, 100))
if type_ == "sum":
return metric_util._generate_sum(
"test.sum", random.randint(0, 9_999_999_999)
)
return metric_util._generate_sum("test.sum", random.randint(0, 9_999_999_999))
if type_ == "histogram":
return _generate_histogram("test_histogram")

Expand Down
Loading
Loading