Skip to content

Commit

Permalink
Send gather time and cluster ID in agent upload (#199)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
charlieegan3 authored Oct 14, 2020
1 parent 667f61a commit 96427da
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 3 additions & 0 deletions api/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ package api
// AgentMetadata is metadata about the agent.
type AgentMetadata struct {
Version string `json:"version"`
// ClusterID is the name of the cluster or host where the agent is running.
// It may send data for other clusters in its datareadings.
ClusterID string `json:"cluster_id"`
}
6 changes: 5 additions & 1 deletion api/datareading.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package api

import "time"

// DataReadingsPost is the payload in the upload request.
type DataReadingsPost struct {
AgentMetadata *AgentMetadata `json:"agent_metadata"`
DataReadings []*DataReading `json:"data_readings"`
// DataGatherTime represents the time that the data readings were gathered
DataGatherTime time.Time `json:"data_gather_time"`
DataReadings []*DataReading `json:"data_readings"`
}

// DataReading is the output of a DataGatherer.
Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ func getConfiguration(ctx context.Context) (Config, *client.PreflightClient) {
}

agentMetadata := &api.AgentMetadata{
Version: version.PreflightVersion,
Version: version.PreflightVersion,
ClusterID: config.ClusterID,
}
var preflightClient *client.PreflightClient
if credentials != nil {
Expand Down
6 changes: 4 additions & 2 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"path/filepath"
"time"

"github.com/jetstack/preflight/api"
)
Expand Down Expand Up @@ -77,8 +78,9 @@ func (c *PreflightClient) usingOAuth2() bool {
// PostDataReadings sends a slice of readings to Preflight.
func (c *PreflightClient) PostDataReadings(orgID string, readings []*api.DataReading) error {
payload := api.DataReadingsPost{
AgentMetadata: c.agentMetadata,
DataReadings: readings,
AgentMetadata: c.agentMetadata,
DataGatherTime: time.Now().UTC(),
DataReadings: readings,
}
data, err := json.Marshal(payload)
if err != nil {
Expand Down

0 comments on commit 96427da

Please sign in to comment.