Skip to content

NH-53473 benchmark always sample #248

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -52,11 +52,7 @@ LIBOBOESERVERLESSX86 := "liboboe-1.0-lambda-x86_64.so"
OBOEVERSION := $(shell cat ./solarwinds_apm/extension/VERSION)

# specification of source of header and library files
ifdef STAGING_OBOE
OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}"
else
OBOEREPO := "https://agent-binaries.cloud.solarwinds.com/apm/c-lib/${OBOEVERSION}"
endif
OBOEREPO := "https://agent-binaries.global.st-ssp.solarwinds.com/apm/c-lib/${OBOEVERSION}"

verify-oboe-version:
@echo -e "Downloading Oboe VERSION file from ${OBOEREPO}"
1 change: 1 addition & 0 deletions solarwinds_apm/configurator.py
Original file line number Diff line number Diff line change
@@ -416,6 +416,7 @@ def _initialize_solarwinds_reporter(
"grpc_proxy": apm_config.get("proxy"),
"stdout_clear_nonblocking": 0,
"metric_format": apm_config.metric_format,
"log_type": 0,
}

return apm_config.extension.Reporter(**reporter_kwargs)
2 changes: 1 addition & 1 deletion solarwinds_apm/extension/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13.0.0
14.0.0
9 changes: 1 addition & 8 deletions solarwinds_apm/sampler.py
Original file line number Diff line number Diff line change
@@ -275,14 +275,7 @@ def is_decision_continued(self, liboboe_decision: dict) -> bool:

def otel_decision_from_liboboe(self, liboboe_decision: dict) -> enum.Enum:
"""Formats OTel decision from liboboe decision"""
decision = Decision.DROP
if liboboe_decision["do_sample"]:
# even if not do_metrics
# pylint:disable=redefined-variable-type
decision = Decision.RECORD_AND_SAMPLE
elif liboboe_decision["do_metrics"]:
# pylint:disable=redefined-variable-type
decision = Decision.RECORD_ONLY
decision = Decision.RECORD_AND_SAMPLE
logger.debug("OTel decision created: %s", decision)
return decision

172 changes: 86 additions & 86 deletions tests/integration/test_scenario_4.py
Original file line number Diff line number Diff line change
@@ -171,97 +171,97 @@ def test_scenario_4_sampled(self):
# Note: context.span_id needs a 16-byte hex conversion first.
assert "{:016x}".format(span_client.context.span_id) == new_span_id

def test_scenario_4_not_sampled(self):
"""
Scenario #4, NOT sampled:
1. Decision to NOT sample is continued at service entry span (mocked). This is
not the root span because it continues an existing OTel context.
2. traceparent and tracestate headers in the request to the test app are
injected into the outgoing request (done by OTel TraceContextTextMapPropagator).
3. No spans are exported.
"""
trace_id = "11112222333344445555666677778888"
span_id = "1000100010001000"
trace_flags = "00"
traceparent = "00-{}-{}-{}".format(trace_id, span_id, trace_flags)
tracestate_span = "e000baa4e000baa4"
tracestate = "sw={}-{}".format(tracestate_span, trace_flags)
# def test_scenario_4_not_sampled(self):
# """
# Scenario #4, NOT sampled:
# 1. Decision to NOT sample is continued at service entry span (mocked). This is
# not the root span because it continues an existing OTel context.
# 2. traceparent and tracestate headers in the request to the test app are
# injected into the outgoing request (done by OTel TraceContextTextMapPropagator).
# 3. No spans are exported.
# """
# trace_id = "11112222333344445555666677778888"
# span_id = "1000100010001000"
# trace_flags = "00"
# traceparent = "00-{}-{}-{}".format(trace_id, span_id, trace_flags)
# tracestate_span = "e000baa4e000baa4"
# tracestate = "sw={}-{}".format(tracestate_span, trace_flags)

# Use in-process test app client and mock to propagate context
# and create in-memory trace
resp = None
# liboboe mocked to guarantee return of "do_sample" (2nd arg)
mock_decision = mock.Mock(
return_value=(1, 0, 3, 4, 5.0, 6.0, 1, 0, "ok", "ok", 0)
)
with mock.patch(
target="solarwinds_apm.extension.oboe.Context.getDecisions",
new=mock_decision,
):
# Request to instrumented app with headers
resp = self.client.get(
"/test_trace/",
headers={
"traceparent": traceparent,
"tracestate": tracestate,
"some-header": "some-value"
}
)
resp_json = json.loads(resp.data)
# # Use in-process test app client and mock to propagate context
# # and create in-memory trace
# resp = None
# # liboboe mocked to guarantee return of "do_sample" (2nd arg)
# mock_decision = mock.Mock(
# return_value=(1, 0, 3, 4, 5.0, 6.0, 1, 0, "ok", "ok", 0)
Comment on lines +174 to +195

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
# )
# with mock.patch(
# target="solarwinds_apm.extension.oboe.Context.getDecisions",
# new=mock_decision,
# ):
# # Request to instrumented app with headers
# resp = self.client.get(
# "/test_trace/",
# headers={
# "traceparent": traceparent,
# "tracestate": tracestate,
# "some-header": "some-value"
# }
# )
# resp_json = json.loads(resp.data)

# Verify some-header was not altered by instrumentation
try:
assert resp_json["incoming-headers"]["some-header"] == "some-value"
except KeyError as e:
self.fail("KeyError was raised at incoming-headers check: {}".format(e))
# # Verify some-header was not altered by instrumentation
# try:
# assert resp_json["incoming-headers"]["some-header"] == "some-value"
# except KeyError as e:
# self.fail("KeyError was raised at incoming-headers check: {}".format(e))

# Verify trace context injected into test app's outgoing postman-echo call
# (added to Flask app's response data) includes:
# - traceparent with a trace_id, trace_flags from original request
# - tracestate from original request
assert "traceparent" in resp_json
_TRACEPARENT_HEADER_FORMAT = (
"^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$"
)
_TRACEPARENT_HEADER_FORMAT_RE = re.compile(_TRACEPARENT_HEADER_FORMAT)
traceparent_re_result = re.search(
_TRACEPARENT_HEADER_FORMAT_RE,
resp_json["traceparent"],
)
new_trace_id = traceparent_re_result.group(2)
assert new_trace_id is not None
assert new_trace_id == trace_id
new_span_id = traceparent_re_result.group(3)
assert new_span_id is not None
new_trace_flags = traceparent_re_result.group(4)
assert new_trace_flags == trace_flags
# # Verify trace context injected into test app's outgoing postman-echo call
# # (added to Flask app's response data) includes:
# # - traceparent with a trace_id, trace_flags from original request
# # - tracestate from original request
Comment on lines +213 to +221

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
# assert "traceparent" in resp_json
# _TRACEPARENT_HEADER_FORMAT = (
# "^([0-9a-f]{2})-([0-9a-f]{32})-([0-9a-f]{16})-([0-9a-f]{2})$"
# )
# _TRACEPARENT_HEADER_FORMAT_RE = re.compile(_TRACEPARENT_HEADER_FORMAT)
# traceparent_re_result = re.search(
# _TRACEPARENT_HEADER_FORMAT_RE,
# resp_json["traceparent"],
# )
# new_trace_id = traceparent_re_result.group(2)
# assert new_trace_id is not None
# assert new_trace_id == trace_id
# new_span_id = traceparent_re_result.group(3)
# assert new_span_id is not None
# new_trace_flags = traceparent_re_result.group(4)
# assert new_trace_flags == trace_flags

assert "tracestate" in resp_json
# In this test we know there is only `sw` in tracestate
# and its value will be new_span_id and new_trace_flags
assert resp_json["tracestate"] == "sw={}-{}".format(new_span_id, new_trace_flags)
# assert "tracestate" in resp_json
# # In this test we know there is only `sw` in tracestate
# # and its value will be new_span_id and new_trace_flags
# assert resp_json["tracestate"] == "sw={}-{}".format(new_span_id, new_trace_flags)

# Verify the OTel context extracted from the original request are continued by
# the trace context injected into test app's outgoing postman-echo call
try:
assert resp_json["incoming-headers"]["traceparent"] == traceparent
assert new_trace_id in resp_json["incoming-headers"]["traceparent"]
assert new_span_id not in resp_json["incoming-headers"]["traceparent"]
assert new_trace_flags in resp_json["incoming-headers"]["traceparent"]
# # Verify the OTel context extracted from the original request are continued by
# # the trace context injected into test app's outgoing postman-echo call
# try:
# assert resp_json["incoming-headers"]["traceparent"] == traceparent
# assert new_trace_id in resp_json["incoming-headers"]["traceparent"]
# assert new_span_id not in resp_json["incoming-headers"]["traceparent"]
# assert new_trace_flags in resp_json["incoming-headers"]["traceparent"]

assert resp_json["incoming-headers"]["tracestate"] == tracestate
assert "sw=" in resp_json["incoming-headers"]["tracestate"]
assert new_span_id not in resp_json["incoming-headers"]["tracestate"]
assert new_trace_flags in resp_json["incoming-headers"]["tracestate"]
except KeyError as e:
self.fail("KeyError was raised at continue trace check: {}".format(e))
# assert resp_json["incoming-headers"]["tracestate"] == tracestate
# assert "sw=" in resp_json["incoming-headers"]["tracestate"]
# assert new_span_id not in resp_json["incoming-headers"]["tracestate"]
# assert new_trace_flags in resp_json["incoming-headers"]["tracestate"]
# except KeyError as e:
# self.fail("KeyError was raised at continue trace check: {}".format(e))

# Verify x-trace response header has same trace_id
# though it will have different span ID because of Flask
# app's outgoing request
assert "x-trace" in resp.headers
assert new_trace_id in resp.headers["x-trace"]
# # Verify x-trace response header has same trace_id
# # though it will have different span ID because of Flask
# # app's outgoing request
Comment on lines +246 to +261

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
# assert "x-trace" in resp.headers
# assert new_trace_id in resp.headers["x-trace"]

# Verify no spans exported
spans = self.memory_exporter.get_finished_spans()
assert len(spans) == 0
# # Verify no spans exported
# spans = self.memory_exporter.get_finished_spans()
# assert len(spans) == 0
Loading