-
Notifications
You must be signed in to change notification settings - Fork 23
HYPERFLEET-889 - feat: Remove custom Logger wrapper from Adapter #280
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -284,6 +284,12 @@ Per Helm Chart Conventions Standard section 9 (Deprecation and Migration Pattern | |
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- if hasKey .Values "serviceMonitor" }} | ||
| {{- fail "serviceMonitor has moved to monitoring.serviceMonitor. Please update your values (e.g. monitoring.serviceMonitor.enabled)." }} | ||
| {{- end -}} | ||
| {{- if hasKey .Values "tracing" }} | ||
| {{- fail "tracing has moved to monitoring.tracing. Please update your values (e.g. monitoring.tracing.enabled)." }} | ||
| {{- end -}} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
|
|
@@ -303,6 +309,27 @@ broker.type must be set explicitly — inference from sub-keys is not supported. | |
| {{- required "broker.type must be set to one of: googlepubsub, rabbitmq" .Values.broker.type -}} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Convert a validated "<digits><unit>" duration string (unit one of s/m/h/d) to seconds. | ||
| Callers must validate the format (via regexMatch) before calling this. | ||
| */}} | ||
| {{- define "hyperfleet-adapter.durationToSeconds" -}} | ||
| {{- $d := . -}} | ||
| {{- $length := len $d -}} | ||
| {{- $lastIdx := sub $length 1 | int -}} | ||
| {{- $unit := substr $lastIdx $length $d -}} | ||
| {{- $num := substr 0 $lastIdx $d | int64 -}} | ||
| {{- if eq $unit "s" -}} | ||
| {{- $num -}} | ||
| {{- else if eq $unit "m" -}} | ||
| {{- mul $num 60 -}} | ||
| {{- else if eq $unit "h" -}} | ||
| {{- mul $num 3600 -}} | ||
| {{- else if eq $unit "d" -}} | ||
| {{- mul $num 86400 -}} | ||
| {{- end -}} | ||
| {{- end }} | ||
|
|
||
| {{/* | ||
| Validate that required fields are set for the resolved broker type. | ||
| */}} | ||
|
|
@@ -314,11 +341,22 @@ Validate that required fields are set for the resolved broker type. | |
| {{- if not (regexMatch "^(0|[1-9][0-9]*[smhd])$" $ttl) -}} | ||
| {{- fail "broker.googlepubsub.expirationTTL must be \"0\" (never expire) or a duration like \"1d\", \"12h\", \"30m\", \"604800s\"" -}} | ||
| {{- end -}} | ||
| {{- if ne $ttl "0" -}} | ||
| {{- $ttlSeconds := include "hyperfleet-adapter.durationToSeconds" $ttl | int64 -}} | ||
| {{- if lt $ttlSeconds 86400 -}} | ||
| {{- fail "broker.googlepubsub.expirationTTL must be \"0\" (never expire) or at least \"1d\" (Google Pub/Sub minimum)" -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- end -}} | ||
| {{- if .Values.broker.googlepubsub.messageRetentionDuration -}} | ||
| {{- if not (regexMatch "^[1-9][0-9]*[smhd]$" (.Values.broker.googlepubsub.messageRetentionDuration | toString)) -}} | ||
| {{- $retention := .Values.broker.googlepubsub.messageRetentionDuration | toString -}} | ||
| {{- if not (regexMatch "^[1-9][0-9]*[smhd]$" $retention) -}} | ||
| {{- fail "broker.googlepubsub.messageRetentionDuration must be a duration like \"1d\", \"12h\", \"30m\", \"604800s\"" -}} | ||
| {{- end -}} | ||
| {{- $retentionSeconds := include "hyperfleet-adapter.durationToSeconds" $retention | int64 -}} | ||
| {{- if or (lt $retentionSeconds 600) (gt $retentionSeconds 2678400) -}} | ||
| {{- fail "broker.googlepubsub.messageRetentionDuration must be between \"10m\" and \"31d\" (Google Pub/Sub limits)" -}} | ||
| {{- end -}} | ||
|
Comment on lines
351
to
+359
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -e
printf '%s\n' '--- helper context ---'
sed -n '300,375p' charts/templates/_helpers.tpl
printf '%s\n' '--- chart files ---'
git ls-files 'charts/**' | sort
printf '%s\n' '--- retention references ---'
rg -n -C 3 'messageRetentionDuration|durationToSeconds|test-helm|values.schema' charts Makefile .github 2>/dev/null || true
printf '%s\n' '--- relevant chart metadata ---'
fd -i 'values.yaml|values.schema.json|Chart.yaml' charts -t f -x sh -c 'echo "--- $1"; sed -n "1,220p" "$1"' shRepository: openshift-hyperfleet/hyperfleet-adapter Length of output: 30727 🏁 Script executed: #!/bin/bash
set -e
python3 - <<'PY'
import json
from pathlib import Path
schema = json.loads(Path("charts/values.schema.json").read_text())
googlepubsub = schema["properties"]["broker"]["properties"]["googlepubsub"]["properties"]
# Model the relevant Helm --set scalar coercion and Go-template truthiness.
def helm_set_scalar(value):
if value == "true":
return True
if value == "false":
return False
if value == "0":
return 0
if value.isdigit():
return int(value)
return value
def go_template_truthy(value):
return not (value is None or value is False or value == 0 or value == "")
for raw in ("0", "10m", "0s"):
value = helm_set_scalar(raw)
print(f"--set raw={raw!r}: parsed={value!r}, type={type(value).__name__}, if-truthy={go_template_truthy(value)}")
print("schema_declares_messageRetentionDuration=",
"messageRetentionDuration" in googlepubsub)
PYRepository: openshift-hyperfleet/hyperfleet-adapter Length of output: 386 🌐 Web query:
💡 Result: In Helm templates, boolean evaluation treats several "zero" values as false, including numeric 0, an empty string, nil (null), and empty collections (maps, slices, arrays) [1][2]. Because of this, explicitly distinguishing between a provided numeric zero and an omitted or null value can be challenging [3][4]. --set vs --set-string When using --set, Helm parses values using its internal parser, which may automatically convert numeric strings into numeric types (e.g., int64 or float64) [5][6][7]. If you need to force a value to be treated strictly as a string, use --set-string [8][7]. This prevents automatic type conversion and ensures the value is treated as a string within your templates [9][10]. Handling the "0" vs. "false" Issue Because both numeric 0 and empty/nil values evaluate to false in Go templates, developers often encounter issues when 0 is a valid, intentional setting [3][2]. To differentiate between a missing value and a literal 0, you can use the following common patterns: 1. Use the quote trick: You can quote the value to check against empty strings. For example, comparing Citations:
Normalize
🤖 Prompt for AI AgentsSource: Path instructions |
||
| {{- end -}} | ||
| {{- else if eq $brokerType "rabbitmq" -}} | ||
| {{- if not .Values.broker.rabbitmq.url -}} | ||
|
|
@@ -352,4 +390,4 @@ Also validate that all file paths in adapterTaskConfig.files actually exist | |
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{- end }} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: openshift-hyperfleet/hyperfleet-adapter
Length of output: 18781
🏁 Script executed:
Repository: openshift-hyperfleet/architecture
Length of output: 24465
🏁 Script executed:
Repository: openshift-hyperfleet/hyperfleet-adapter
Length of output: 17518
🏁 Script executed (no clone):
Length of output: 324
🌐 Web query:
Masterminds Sprig mul function int64 overflow toInt64 source💡 Result:
In the Masterminds Sprig library, the mul function performs multiplication on int64 values without explicit overflow protection or error handling [1][2][3]. The function is implemented in functions.go as follows: "mul": func(a interface{}, v...interface{}) int64 { val:= toInt64(a) for _, b:= range v { val = val * toInt64(b) } return val }, The helper function toInt64 (located in numeric.go) handles the conversion of various types to int64 [4][5]. When converting unsigned integers (uint, uint64) that exceed math.MaxInt64, the function currently returns math.MaxInt64 as a fallback: case reflect.Uint, reflect.Uint64: tv:= val.Uint if tv <= math.MaxInt64 { return int64(tv) } return math.MaxInt64 Because the mul function uses standard Go multiplication (*), any product exceeding the range of a 64-bit signed integer will wrap around according to standard Go integer overflow behavior, rather than returning an error [1][2]. The library does not implement safe multiplication checks to detect or prevent this overflow [1][2].
Citations:
🏁 Script executed:
Repository: openshift-hyperfleet/hyperfleet-adapter
Length of output: 4335
Reject duration overflow before
mul(CWE-190).The duration regex accepts an unbounded number of digits. Sprig
mulperforms uncheckedint64multiplication. For example,307445734561827301mwraps to86444seconds and passes the86400-second check. Bound the numeric component before multiplication and add overflow and boundary tests.🤖 Prompt for AI Agents
Source: Path instructions