Skip to content

Commit ec05e70

Browse files
author
Oluwole Fadeyi
authored
Merge pull request #261 from jetstack/update-datareadings-endpoint
These changes will update the agent's datareadings endpoint. The new saas endpoint comes with better memory usage and fewer limitations compared to the old one. The old `api/v1/org/<orgID>/datareadings` endpoint will become deprecated.
2 parents 7d3d1bd + ef93798 commit ec05e70

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

pkg/agent/run.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ func gatherData(ctx context.Context, config Config, dataGatherers map[string]dat
329329

330330
func postData(config Config, preflightClient *client.PreflightClient, readings []*api.DataReading) error {
331331
baseURL := config.Server
332-
var err error
333332

334333
log.Println("Running Agent...")
335334
log.Println("Posting data to:", baseURL)
@@ -358,12 +357,18 @@ func postData(config Config, preflightClient *client.PreflightClient, readings [
358357
return fmt.Errorf("Received response with status code %d. Body: %s", code, errorContent)
359358
}
360359
log.Println("Data sent successfully.")
361-
} else {
362-
err := preflightClient.PostDataReadings(config.OrganizationID, readings)
363-
if err != nil {
364-
return fmt.Errorf("Post to server failed: %+v", err)
365-
}
366-
log.Println("Data sent successfully.")
360+
return err
367361
}
368-
return err
362+
363+
if config.ClusterID == "" {
364+
return fmt.Errorf("Post to server failed: missing clusterID from agent configuration")
365+
}
366+
367+
err := preflightClient.PostDataReadings(config.OrganizationID, config.ClusterID, readings)
368+
if err != nil {
369+
return fmt.Errorf("Post to server failed: %+v", err)
370+
}
371+
log.Println("Data sent successfully.")
372+
373+
return nil
369374
}

pkg/client/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (c *PreflightClient) usingOAuth2() bool {
7676
}
7777

7878
// PostDataReadings sends a slice of readings to Preflight.
79-
func (c *PreflightClient) PostDataReadings(orgID string, readings []*api.DataReading) error {
79+
func (c *PreflightClient) PostDataReadings(orgID, clusterID string, readings []*api.DataReading) error {
8080
payload := api.DataReadingsPost{
8181
AgentMetadata: c.agentMetadata,
8282
DataGatherTime: time.Now().UTC(),
@@ -87,7 +87,7 @@ func (c *PreflightClient) PostDataReadings(orgID string, readings []*api.DataRea
8787
return err
8888
}
8989

90-
res, err := c.Post(filepath.Join("/api/v1/org", orgID, "datareadings"), bytes.NewBuffer(data))
90+
res, err := c.Post(filepath.Join("/api/v1/org", orgID, "datareadings", clusterID), bytes.NewBuffer(data))
9191
if err != nil {
9292
return err
9393
}

0 commit comments

Comments
 (0)