This repository was archived by the owner on Apr 15, 2026. It is now read-only.
Eliminate utils/restore Metrics#214
Merged
Merged
Conversation
6dd788b to
68d2f73
Compare
aa88e83 to
3013e95
Compare
This PR elmintes the utils package by moving the functionality to where
it is used. This is more in-line with idiomatic go (no non-descriptive
package names). As part of the elimination we moved to a custom slice
for logs that elminates the majority of the Custom Marshal/Unmarshal
code.
Identified in this change, the metrics emission was no longer wired up
and has been restored to functionality.
Key improvements:
- Introduce LogsSlice type with proper JSON marshaling/unmarshaling
- Implements Stringer interface for consistent log formatting
- Handles newline-delimited string conversion automatically
- Eliminates need for custom PredictionResponse marshal/unmarshal
- Move metrics functionality from dead util/metrics.go to runner.go
- Restore sendRunnerMetric() function that was never called
- Inline HTTPClientWithRetry() using httpclient.ApplyRetryPolicy
- Fix missing imports and undefined references
- Remove util.JoinLogs() dependency by using LogsSlice.String()
- Consolidate logging utilities into appropriate packages
Technical details:
- LogsSlice.String() preserves util.JoinLogs() behavior (joins with \n, ensures trailing \n)
- LogsSlice.MarshalJSON/UnmarshalJSON handles string ↔ []string conversion
- All util package imports removed across codebase
- Metrics sending now properly integrated into runner lifecycle
This eliminates the "terrible util package" while restoring previously
broken metrics functionality and improving type safety for log handling.
fc85e3b to
22c158d
Compare
meatballhat
approved these changes
Sep 16, 2025
Contributor
meatballhat
left a comment
There was a problem hiding this comment.
non-blocking feedback only
| maxConcurrency := max(1, cogYaml.Concurrency.Max) | ||
|
|
||
| // Send metrics | ||
| go r.sendRunnerMetric(*cogYaml) |
Contributor
There was a problem hiding this comment.
Intentionally dereferencing?
Contributor
Author
There was a problem hiding this comment.
This was carried forward this was how it was originally and we shoudl evaluate if we need to deref like this in the future. happy to make the change but will not as this is a "eliminate package" pr.
| "github.com/replicate/cog-runtime/internal/util" | ||
| ) | ||
|
|
||
| const TimeLayout = "2006-01-02T15:04:05.999999-07:00" |
Contributor
There was a problem hiding this comment.
nit: How is this (meaningfully?) different than time.RFC3339Nano?
Contributor
Author
There was a problem hiding this comment.
Not! let's use consts!
Contributor
Author
There was a problem hiding this comment.
We should also likely move to utc always not -700, I'll do that in a fast followup.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR elmintes the utils package by moving the functionality to where it is used. This is more in-line with idiomatic go (no non-descriptive package names). As part of the elimination we moved to a custom slice for logs that elminates the majority of the Custom Marshal/Unmarshal code.
Identified in this change, the metrics emission was no longer wired up and has been restored to functionality.
Key improvements:
Technical details:
This eliminates the "terrible util package" while restoring previously
broken metrics functionality and improving type safety for log handling.