[machine] Start recording when bot_config started running.
Change-Id: Ie545d918c7ad2dd3fe8b18eaae18d0548b0dc315
Reviewed-on: https://skia-review.googlesource.com/c/buildbot/+/302501
Commit-Queue: Joe Gregorio <jcgregorio@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
diff --git a/machine/go/machine/machine.go b/machine/go/machine/machine.go
index 4341bf6..a6652bb 100644
--- a/machine/go/machine/machine.go
+++ b/machine/go/machine/machine.go
@@ -119,6 +119,9 @@
// KubernetesImage is the container image being run.
KubernetesImage string `json:"image"`
+
+ // StartTim is when the bot_config started running.
+ StartTime time.Time `json:"start_time"`
}
// Event is the information a machine should send via Source when
diff --git a/sk8s/go/bot_config/machine/machine.go b/sk8s/go/bot_config/machine/machine.go
index 8382f0f..3f1621b 100644
--- a/sk8s/go/bot_config/machine/machine.go
+++ b/sk8s/go/bot_config/machine/machine.go
@@ -44,6 +44,9 @@
// KubernetesImage is the container image being run.
KubernetesImage string
+ // startTime is the time when this machine started running.
+ startTime time.Time
+
// Metrics
interrogateTimer metrics2.Float64SummaryMetric
interrogateAndSendFailures metrics2.Counter
@@ -61,7 +64,7 @@
}
// New return an instance of *Machine.
-func New(ctx context.Context, local bool, instanceConfig config.InstanceConfig) (*Machine, error) {
+func New(ctx context.Context, local bool, instanceConfig config.InstanceConfig, startTime time.Time) (*Machine, error) {
store, err := store.New(ctx, false, instanceConfig)
if err != nil {
return nil, skerr.Wrapf(err, "Failed to build store instance.")
@@ -86,6 +89,7 @@
MachineID: machineID,
Hostname: hostname,
KubernetesImage: kubernetesImage,
+ startTime: startTime,
interrogateTimer: metrics2.GetFloat64SummaryMetric("bot_config_machine_interrogate_timer", map[string]string{"machine": machineID}),
interrogateAndSendFailures: metrics2.GetCounter("bot_config_machine_interrogate_and_send_errors", map[string]string{"machine": machineID}),
storeWatchArrivalCounter: metrics2.GetCounter("bot_config_machine_store_watch_arrival", map[string]string{"machine": machineID}),
@@ -121,6 +125,8 @@
ret.RunningSwarmingTask = m.runningTask
+ ret.Host.StartTime = m.startTime
+
return ret
}
diff --git a/sk8s/go/bot_config/machine/machine_test.go b/sk8s/go/bot_config/machine/machine_test.go
index 41a70c2..af81da9 100644
--- a/sk8s/go/bot_config/machine/machine_test.go
+++ b/sk8s/go/bot_config/machine/machine_test.go
@@ -93,7 +93,8 @@
}()
// Create a Machine instance.
- m, err := New(ctx, true, instanceConfig)
+ start := time.Date(2020, time.May, 1, 0, 0, 0, 0, time.UTC)
+ m, err := New(ctx, true, instanceConfig, start)
require.NoError(t, err)
assert.Equal(t, "my-test-bot-001", m.MachineID)
@@ -209,7 +210,8 @@
}()
// Create a Machine instance.
- m, err := New(ctx, true, instanceConfig)
+ start := time.Date(2020, time.May, 1, 0, 0, 0, 0, time.UTC)
+ m, err := New(ctx, true, instanceConfig, start)
require.NoError(t, err)
// Set up fakes for adb. We have two sets of 3 since Start calls
@@ -293,7 +295,8 @@
}()
// Create a Machine instance.
- m, err := New(ctx, true, instanceConfig)
+ start := time.Date(2020, time.May, 1, 0, 0, 0, 0, time.UTC)
+ m, err := New(ctx, true, instanceConfig, start)
// We are running a task.
m.runningTask = true
require.NoError(t, err)
@@ -331,8 +334,9 @@
DumpsysThermalService: "",
},
Host: machine.Host{
- Name: "my-test-bot-001",
- PodName: hostname,
+ Name: "my-test-bot-001",
+ PodName: hostname,
+ StartTime: start,
},
RunningSwarmingTask: true,
},
diff --git a/sk8s/go/bot_config/main.go b/sk8s/go/bot_config/main.go
index 44f5118..a847dfe 100644
--- a/sk8s/go/bot_config/main.go
+++ b/sk8s/go/bot_config/main.go
@@ -7,6 +7,7 @@
"flag"
"io"
"os"
+ "time"
"go.skia.org/infra/go/common"
"go.skia.org/infra/go/sklog"
@@ -47,7 +48,7 @@
}
ctx := context.Background()
- m, err := machine.New(ctx, *local, instanceConfig)
+ m, err := machine.New(ctx, *local, instanceConfig, time.Now())
if err != nil {
sklog.Fatal("Failed to create machine: %s", err)
}