Set user agent as soon as the scale set is created, and remove the proxy info (#8)

* Set user agent as soon as the scale set is created

* fix test
This commit is contained in:
Nikola Jokic
2025-10-31 14:16:02 +01:00
committed by GitHub
parent 1f22d2441c
commit 83fb2e2837
3 changed files with 15 additions and 12 deletions
+5 -10
View File
@@ -118,8 +118,6 @@ type UserAgentInfo struct {
CommitSHA string
// ScaleSetID is the ID of the scale set
ScaleSetID int
// HasProxy is true if the controller is running behind a proxy
HasProxy bool
// Subsystem is the subsystem such as listener, controller, etc.
// Each system may pick its own subsystem name.
Subsystem string
@@ -131,12 +129,7 @@ func (u UserAgentInfo) String() string {
scaleSetID = strconv.Itoa(u.ScaleSetID)
}
proxy := "Proxy/disabled"
if u.HasProxy {
proxy = "Proxy/enabled"
}
return fmt.Sprintf("%s/%s (%s; %s) ScaleSetID/%s (%s)", u.System, u.Version, u.CommitSHA, u.Subsystem, scaleSetID, proxy)
return fmt.Sprintf("%s/%s (%s; %s) ScaleSetID/%s", u.System, u.Version, u.CommitSHA, u.Subsystem, scaleSetID)
}
func WithLogger(logger slog.Logger) Option {
@@ -193,8 +186,10 @@ func NewClient(githubConfigURL string, creds *ActionsAuth, options ...Option) (*
ac.userAgent.Store(
UserAgentInfo{
Version: "N/A",
CommitSHA: "N/A",
System: "scaleset-client",
Version: "NA",
CommitSHA: "NA",
Subsystem: "NA",
ScaleSetID: 0,
}.String())
+1 -2
View File
@@ -1669,14 +1669,13 @@ func TestUserAgentInfoString(t *testing.T) {
Version: "0.1.0",
CommitSHA: "1234567890abcdef",
ScaleSetID: 10,
HasProxy: true,
Subsystem: "test",
}
userAgent := userAgentInfo.String()
expectedProduct := "actions-runner-controller/0.1.0 (1234567890abcdef; test)"
assert.Contains(t, userAgent, expectedProduct)
expectedScaleSet := "ScaleSetID/10 (Proxy/enabled)"
expectedScaleSet := "ScaleSetID/10"
assert.Contains(t, userAgent, expectedScaleSet)
}
+9
View File
@@ -91,6 +91,15 @@ func run(ctx context.Context, c Config) error {
return fmt.Errorf("failed to create runner scale set: %w", err)
}
// Set the user agent for the scaleset client now that we have the scale set ID
scalesetClient.SetUserAgent(scaleset.UserAgentInfo{
System: "dockerscaleset",
Version: "0.1.0",
CommitSHA: "unknown",
ScaleSetID: scaleSet.ID,
Subsystem: scaleSet.Name,
})
defer func() {
logger.Info(
"Deleting runner scale set",