Skip to content

Commit

Permalink
cleanup prints()
Browse files Browse the repository at this point in the history
  • Loading branch information
jj22ee committed Feb 9, 2024
1 parent 77042d9 commit 4de549a
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
import datetime
import json
from logging import getLogger

Expand Down Expand Up @@ -42,7 +41,6 @@ def get_sampling_rules(self) -> [_SamplingRule]:
if "SamplingRule" not in record:
_logger.error("SamplingRule is missing in SamplingRuleRecord")
else:
print(record["SamplingRule"])
sampling_rules.append(_SamplingRule(**record["SamplingRule"]))

except requests.exceptions.RequestException as req_err:
Expand All @@ -55,16 +53,12 @@ def get_sampling_rules(self) -> [_SamplingRule]:
def get_sampling_targets_response(self, statistics):
sampling_targets_response = {}
headers = {"content-type": "application/json"}
now = datetime.datetime.now()
print("%s --- %s", now, now.timestamp())
print(statistics)
try:
xray_response = requests.post(url=self.__get_sampling_targets_endpoint, headers=headers, timeout=20, json={
"SamplingStatisticsDocuments": statistics
})

self.count += 5
print(xray_response.status_code)
if xray_response is None:
_logger.error("GetSamplingTargets response is None")
return {}
Expand All @@ -74,8 +68,6 @@ def get_sampling_targets_response(self, statistics):
"`SamplingTargetDocuments` or `LastRuleModification` is missing in getSamplingTargets response: %s", sampling_targets_response
)
return {}
# sampling_target_documents = sampling_targets_response["SamplingTargetDocuments"]
print(sampling_targets_response)
except requests.exceptions.RequestException as req_err:
_logger.error("Request error occurred: %s", req_err)
except json.JSONDecodeError as json_err:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def should_sample(
trace_state: TraceState = None,
borrow: bool = False,
) -> SamplingResult:
# print(self.reservoir.__dict__)
if self.reservoir.try_spend(1, borrow):
return SamplingResult(decision=Decision.RECORD_AND_SAMPLE, attributes=attributes, trace_state=trace_state)
return SamplingResult(decision=Decision.DROP, attributes=attributes, trace_state=trace_state)
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,9 @@ def try_spend(self, cost: int, borrow: bool):
# 2. actual_balance=4, cost=3 -> actual_remaining_balance = 1
# 3. actual_remaining_balance=1 -> remaining_balance_millis = 250ms
actual_balance = current_balance_millis * quota_per_millis
print("actual_balance: %s, >=cost??: %s, borrowed??", actual_balance, str(actual_balance >= cost), str(borrow))
if actual_balance >= cost:
actual_remaining_balance = actual_balance - cost
remaining_balance_millis = actual_remaining_balance / quota_per_millis
print("remaining_balance_millis: %s", remaining_balance_millis)
self.wallet_floor_millis = wallet_ceiling_millis - remaining_balance_millis
return True
# No changes to the wallet state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ def should_sample(
) -> SamplingResult:
with self.statistics_lock: self.statistics.RequestCount += 1

# print("self.reservoir_expiry: %s", self.reservoir_expiry)
# print(type(self.reservoir_expiry))
reservoir_expired: bool = self.clock.now() > self.reservoir_expiry
sampling_result = SamplingResult(decision=Decision.DROP, attributes=attributes, trace_state=trace_state)
if reservoir_expired:
self.borrowing = True
print("RULE EXPIRED")

sampling_result = self.reservoir_sampler.should_sample(
parent_context,
trace_id,
Expand All @@ -76,7 +74,6 @@ def should_sample(
if self.borrowing:
self.statistics.BorrowCount += 1
self.statistics.SampleCount += 1
print("sampling_result: %s", sampling_result.decision)
return sampling_result

sampling_result = self.fixed_rate_sampler.should_sample(
Expand All @@ -94,8 +91,6 @@ def should_sample(
return sampling_result

def update_target(self, target):
print("%s ..... %s", target["RuleName"], target["ReservoirQuota"])

new_quota = target["ReservoirQuota"] if target["ReservoirQuota"] is not None else 0
new_fixed_rate = target["FixedRate"] if target["FixedRate"] is not None else 0
self.reservoir_sampler = _ReservoirSampler(new_quota, self.clock)
Expand All @@ -109,12 +104,9 @@ def update_target(self, target):
self.reservoir_expiry = self.clock.now()

self.polling_interval = target["Interval"]
print("%s ..... %s ..... %s", self.reservoir_expiry, 10, 12)
self.borrowing = False

def get_then_reset_statistics(self) -> _SamplingStatisticsDocument:
print(self.client_id)

self.statistics_lock.acquire()
old_stats = self.statistics
self.statistics = _SamplingStatisticsDocument(self.client_id, self.sampling_rule.RuleName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ def should_sample(
rule: _Rule
for rule in self.rules:
if rule.matches(self.__resource, attributes):
print("Matched WITH: %s", rule.sampling_rule.RuleName)

print("Current status: %s", rule.statistics.__dict__)

return rule.should_sample(
parent_context,
trace_id,
Expand Down Expand Up @@ -100,7 +96,7 @@ def update_sampling_targets(self, sampling_targets_response) -> (bool, int):
self.__cache_lock.acquire()

rule_map:dict[str,_Rule] = {rule.sampling_rule.RuleName: rule for rule in self.rules}
min_polling_interval = None#DEFAULT_TARGET_POLLING_INTERVAL_SECONDS
min_polling_interval = None

for target in targets:
if target["RuleName"] in rule_map:
Expand All @@ -116,12 +112,6 @@ def update_sampling_targets(self, sampling_targets_response) -> (bool, int):
if last_rule_modification > self._last_modified:
return (True, min_polling_interval)
return (False, min_polling_interval)

def get_minimum_target_poll_interval(self):
self.__cache_lock.acquire()
min_interval = min(self.rules.polling_interval)
min(self.rules, key=itemgetter('price'))
self.__cache_lock.release()

def get_all_statistics(self):
all_statistics = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def __init__(
_logger.setLevel(log_level)

self.__client_id = self.__generate_client_id()
print("client ID: %s", self.__client_id)
self.__clock = _Clock()
self.__xray_client = _AwsXRaySamplingClient(endpoint, log_level=log_level)
self.__fallback_sampler = _FallbackSampler(self.__clock)
Expand Down Expand Up @@ -99,12 +98,9 @@ def should_sample(
parent_context, trace_id, name, kind=kind, attributes=attributes, links=links, trace_state=trace_state
)

res = self.__rule_cache.should_sample(
return self.__rule_cache.should_sample(
parent_context, trace_id, name, kind=kind, attributes=attributes, links=links, trace_state=trace_state
)
if res.decision is not Decision.DROP:
print("SAAAAAAAMPPPPPLLLEEEEED")
return res

# pylint: disable=no-self-use
@override
Expand All @@ -128,13 +124,8 @@ def __get_and_update_sampling_targets(self) -> None:
sampling_targets_response = self.__xray_client.get_sampling_targets_response(all_statistics)
refresh_rules, min_polling_interval = self.__rule_cache.update_sampling_targets(sampling_targets_response)
if refresh_rules:
print("REFRESHING RULES")
print("REFRESHING RULES")
print("REFRESHING RULES")
print("REFRESHING RULES")
self.__get_and_update_sampling_rules()
if min_polling_interval is not None:
print("NEW NEW NEW polling interval : %s", min_polling_interval)
self.__target_polling_interval = min_polling_interval

def __start_sampling_target_poller(self) -> None:
Expand Down

0 comments on commit 4de549a

Please sign in to comment.