Skip to content

Commit 96427da

Browse files
authored
Send gather time and cluster ID in agent upload (#199)
* Send gather time and cluster ID in agent upload This will allow agent data to be categorized and stored in preparation for processing async on the backend. Signed-off-by: Charlie Egan <[email protected]> * Use UTC time Signed-off-by: Charlie Egan <[email protected]>
1 parent 667f61a commit 96427da

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

api/agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@ package api
33
// AgentMetadata is metadata about the agent.
44
type AgentMetadata struct {
55
Version string `json:"version"`
6+
// ClusterID is the name of the cluster or host where the agent is running.
7+
// It may send data for other clusters in its datareadings.
8+
ClusterID string `json:"cluster_id"`
69
}

api/datareading.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package api
22

3+
import "time"
4+
35
// DataReadingsPost is the payload in the upload request.
46
type DataReadingsPost struct {
57
AgentMetadata *AgentMetadata `json:"agent_metadata"`
6-
DataReadings []*DataReading `json:"data_readings"`
8+
// DataGatherTime represents the time that the data readings were gathered
9+
DataGatherTime time.Time `json:"data_gather_time"`
10+
DataReadings []*DataReading `json:"data_readings"`
711
}
812

913
// DataReading is the output of a DataGatherer.

pkg/agent/run.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ func getConfiguration(ctx context.Context) (Config, *client.PreflightClient) {
108108
}
109109

110110
agentMetadata := &api.AgentMetadata{
111-
Version: version.PreflightVersion,
111+
Version: version.PreflightVersion,
112+
ClusterID: config.ClusterID,
112113
}
113114
var preflightClient *client.PreflightClient
114115
if credentials != nil {

pkg/client/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io/ioutil"
88
"path/filepath"
9+
"time"
910

1011
"github.com/jetstack/preflight/api"
1112
)
@@ -77,8 +78,9 @@ func (c *PreflightClient) usingOAuth2() bool {
7778
// PostDataReadings sends a slice of readings to Preflight.
7879
func (c *PreflightClient) PostDataReadings(orgID string, readings []*api.DataReading) error {
7980
payload := api.DataReadingsPost{
80-
AgentMetadata: c.agentMetadata,
81-
DataReadings: readings,
81+
AgentMetadata: c.agentMetadata,
82+
DataGatherTime: time.Now().UTC(),
83+
DataReadings: readings,
8284
}
8385
data, err := json.Marshal(payload)
8486
if err != nil {

0 commit comments

Comments
 (0)