Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Eliminate utils/restore Metrics#214

Merged
tempusfrangit merged 1 commit into
mainfrom
no-more-utils
Sep 16, 2025
Merged

Eliminate utils/restore Metrics#214
tempusfrangit merged 1 commit into
mainfrom
no-more-utils

Conversation

@tempusfrangit
Copy link
Copy Markdown
Contributor

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.

@tempusfrangit tempusfrangit requested a review from a team as a code owner September 15, 2025 21:46
Base automatically changed from cleanup-tmp to main September 16, 2025 15:24
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.
Copy link
Copy Markdown
Contributor

@meatballhat meatballhat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

non-blocking feedback only

Comment thread internal/runner/runner.go
maxConcurrency := max(1, cogYaml.Concurrency.Max)

// Send metrics
go r.sendRunnerMetric(*cogYaml)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Intentionally dereferencing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread internal/server/server.go
"github.com/replicate/cog-runtime/internal/util"
)

const TimeLayout = "2006-01-02T15:04:05.999999-07:00"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: How is this (meaningfully?) different than time.RFC3339Nano?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not! let's use consts!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also likely move to utc always not -700, I'll do that in a fast followup.

@tempusfrangit tempusfrangit merged commit 8768da8 into main Sep 16, 2025
23 checks passed
@tempusfrangit tempusfrangit deleted the no-more-utils branch September 16, 2025 15:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants