Skip to content
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

engine: report go version on startup #159

Merged
merged 2 commits into from
Dec 17, 2024
Merged

Conversation

kevinburkesegment
Copy link
Contributor

The first time you report any metric, additionally report the running Go version. Add two flags that can be used to disable this behavior.

README.md Outdated Show resolved Hide resolved
engine.go Outdated
Comment on lines 155 to 193
if len(parts) == 2 || len(parts) == 3 {
maj, err := strconv.Atoi(parts[0])
if err == nil {
eng.measure_(t, "go_version.major", maj, Gauge)
}
min, err := strconv.Atoi(parts[1])
if err == nil {
eng.measure_(t, "go_version.minor", min, Gauge)
}
if len(parts) == 3 {
patch, err := strconv.Atoi(parts[2])
if err == nil {
eng.measure_(t, "go_version.patch", patch, Gauge)
}
}
}
Copy link

Choose a reason for hiding this comment

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

Would it be sufficient to just ship the version string (but keep that trimmed prefix, good looking out) and let folks on the consumer side manage/mangle/parse the value as they see fit? I'm not sure Major or Minor have much utility in isolation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see a way to report a string instead of a number, but I will look again

Copy link

Choose a reason for hiding this comment

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

Yeah fair, I don't know the stats stack intimately so maybe it's just not a thing. Thanks for checking.

Choose a reason for hiding this comment

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

What if we put the version string in a tag, and set a gauge/counter to 1? Then you can sum by version tag.

@kevinburkesegment kevinburkesegment requested a review from a team June 20, 2024 21:49
@kevinburkesegment kevinburkesegment force-pushed the report-go-version branch 4 times, most recently from 99245fc to 4d3877b Compare June 21, 2024 21:58
ABHINAV-SUREKA
ABHINAV-SUREKA previously approved these changes Jun 26, 2024
Copy link

@mckern mckern left a comment

Choose a reason for hiding this comment

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

Thank you for working on this. I've gone over this a bit, but I'm kind of torn on this implementation because while code that exists is generally preferable to code that doesn't, I'm still not convinced that this should be shipped as 3 separate values using gauges.

What you turned up from the procstats subpackage may be what we really need for our use-cases.

@kevinburkesegment kevinburkesegment force-pushed the report-go-version branch 3 times, most recently from 4b5de05 to 267cde5 Compare September 9, 2024 21:58
@kevinburkesegment
Copy link
Contributor Author

@etiennep @mckern I reworked this to just publish a single metric with a value of "1" and the go version as a tag.

ABHINAV-SUREKA
ABHINAV-SUREKA previously approved these changes Sep 11, 2024
engine.go Outdated
@@ -144,7 +149,24 @@ func (eng *Engine) ClockAt(name string, start time.Time, tags ...Tag) *Clock {
}
}

var GoVersionReportingEnabled = os.Getenv("STATS_DISABLE_GO_VERSION_REPORTING") != "true"
Copy link

Choose a reason for hiding this comment

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

Suggestion: setting boolean environment variables to "yes", "1", etc. is pretty common. Checking for emptiness/"false"/"f"/"0" may be safer than only looking for "true".

engine.go Outdated
Comment on lines 157 to 195
vsn := strings.TrimPrefix(runtime.Version(), "go")
parts := strings.Split(vsn, ".")
// this filters out weird compiled Go versions like tip.
// older Go version might be "go1.13"
if len(parts) == 2 || len(parts) == 3 {
eng.measureOne(t, "go_version", 1, Gauge, []Tag{{"go_version", vsn}}...)
}
})
}
Copy link

@mckern mckern Oct 16, 2024

Choose a reason for hiding this comment

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

Doesn't really matter how many parts are in the version string now, right?

Suggested change
vsn := strings.TrimPrefix(runtime.Version(), "go")
parts := strings.Split(vsn, ".")
// this filters out weird compiled Go versions like tip.
// older Go version might be "go1.13"
if len(parts) == 2 || len(parts) == 3 {
eng.measureOne(t, "go_version", 1, Gauge, []Tag{{"go_version", vsn}}...)
}
})
}
vsn := strings.TrimPrefix(runtime.Version(), "go")
eng.measureOne(t, "go_version", 1, Gauge, []Tag{{"go_version", vsn}}...)
})
}

Comment on lines 66 to 84
vsn := strings.TrimPrefix(runtime.Version(), "go")
parts := strings.Split(vsn, ".")
measures := h.Measures()
if len(parts) == 2 || len(parts) == 3 {
if len(measures) != 1+1 {
t.Fatalf("expecting to get %d metrics, got back %d: %v", 1+1, len(measures), measures)
}
}
Copy link

Choose a reason for hiding this comment

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

I don't think this tests the new implementation?

@kevinburkesegment kevinburkesegment force-pushed the report-go-version branch 5 times, most recently from 524ce55 to ad56b2a Compare December 12, 2024 21:12
@kevinburkesegment kevinburkesegment force-pushed the report-go-version branch 2 times, most recently from 50672eb to 1924b42 Compare December 12, 2024 21:42
The first time you report any metric, additionally report the running
Go version. Add two flags that can be used to disable this behavior.
@kevinburkesegment kevinburkesegment force-pushed the report-go-version branch 2 times, most recently from e9608fd to f81e32d Compare December 12, 2024 21:54
etiennep
etiennep previously approved these changes Dec 12, 2024
Turn off the thing where the tests can pass even though lint fails
- it's as good as not running the linter at all.

The "stats" name import next to "github.com/segmentio/stats/v5" is not
necessary but was prompted by golangci-lint at one point.
@kevinburkesegment kevinburkesegment merged commit 4b63042 into main Dec 17, 2024
8 checks passed
@kevinburkesegment kevinburkesegment deleted the report-go-version branch December 17, 2024 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants