Skip to content

Commit 11de56c

Browse files
authored
chore: Remove extra validation (#19)
* chore: Don't validate file sizes * chore: Allow flexibility in config defs and docs file frontmatter schemas * chore: Update agent type naming * chore: Update validation to allow as much data to be sent as possible
1 parent 503424c commit 11de56c

File tree

16 files changed

+217
-712
lines changed

16 files changed

+217
-712
lines changed

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ inputs:
88
description: 'NewRelic private key content (pass from secrets)'
99
required: true
1010
agent-type:
11-
description: 'The type of agent in all lowercase eg. dotnet'
11+
description: 'The type of agent in all lowercase eg. dotnet-agent'
1212
required: false
1313
default: ''
1414
version:

cmd/agent-metadata-action/main.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,21 @@ func run() error {
7070
return fmt.Errorf("error reading configs: %w", err)
7171
}
7272

73+
fmt.Println("::notice::Successfully read configs file")
74+
fmt.Printf("::debug::Found %d configs\n", len(configs))
75+
76+
// @todo need to update this to read a list of files for future use
7377
agentControl, err := loader.LoadAndEncodeAgentControl(workspace)
7478
if err != nil {
75-
return fmt.Errorf("error reading agent control: %w", err)
79+
fmt.Printf("::debug::Unable to read agent control file: %s\n", workspace)
80+
} else {
81+
fmt.Println("::notice::Successfully read agent control file")
7682
}
7783

78-
fmt.Println("::notice::Successfully read configs file")
79-
fmt.Printf("::debug::Found %d configs\n", len(configs))
80-
8184
metadata := loader.LoadMetadataForAgents(agentVersion)
8285

86+
// @todo will need to add agentRequirements here in a future PR
87+
8388
agentMetadata := models.AgentMetadata{
8489
ConfigurationDefinitions: configs,
8590
Metadata: metadata,
@@ -99,23 +104,23 @@ func run() error {
99104
fmt.Println("::debug::Docs scenario")
100105

101106
metadata, err := loader.LoadMetadataForDocs()
102-
103107
if err != nil {
104-
return fmt.Errorf("error reading metadata: %w", err)
105-
}
106-
107-
for _, currMetadata := range metadata {
108-
fmt.Printf("::debug::Found metadata for %s %s \n", currMetadata.AgentType, currMetadata.AgentMetadataFromDocs.Version)
109-
printJSON("Docs Metadata", currMetadata.AgentMetadataFromDocs)
110-
111-
currAgentMetadata := models.AgentMetadata{
112-
Metadata: currMetadata.AgentMetadataFromDocs,
113-
}
114-
115-
if err := metadataClient.SendMetadata(ctx, currMetadata.AgentType, &currAgentMetadata); err != nil {
116-
fmt.Printf("::warn::Failed to send docs metadata to instrumentation service for agent type: %s \n", currMetadata.AgentType)
117-
} else {
118-
fmt.Printf("::notice::Successfully sent docs metadata to instrumentation service for agent type: %s \n", currMetadata.AgentType)
108+
// warn but don't fail the docs push - this data is useful but not required at this time
109+
fmt.Printf("::warn::Error reading metadata %s \n", err)
110+
} else {
111+
for _, currMetadata := range metadata {
112+
fmt.Printf("::debug::Found metadata for %s %s \n", currMetadata.AgentType, currMetadata.AgentMetadataFromDocs["version"])
113+
printJSON("Docs Metadata", currMetadata.AgentMetadataFromDocs)
114+
115+
currAgentMetadata := models.AgentMetadata{
116+
Metadata: currMetadata.AgentMetadataFromDocs,
117+
}
118+
119+
if err := metadataClient.SendMetadata(ctx, currMetadata.AgentType, &currAgentMetadata); err != nil {
120+
fmt.Printf("::warn::Failed to send docs metadata to instrumentation service for agent type: %s \n", currMetadata.AgentType)
121+
} else {
122+
fmt.Printf("::notice::Successfully sent docs metadata to instrumentation service for agent type: %s \n", currMetadata.AgentType)
123+
}
119124
}
120125
}
121126
}

cmd/agent-metadata-action/main_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Release notes content here.
132132
assert.Contains(t, stderrStr, "::notice::Loaded metadata for 1 out of 1 changed MDX files")
133133

134134
// Verify output contains agent metadata
135-
assert.Contains(t, outputStr, "JavaAgent")
135+
assert.Contains(t, outputStr, "java-agent")
136136
assert.Contains(t, outputStr, "1.3.0")
137137
assert.Contains(t, outputStr, "New feature 1")
138138
assert.Contains(t, outputStr, "Bug fix 1")

internal/client/instrumentation.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import (
55
"context"
66
"encoding/json"
77
"fmt"
8+
"io"
89
"net/http"
910
"time"
1011

11-
"agent-metadata-action/internal/fileutil"
1212
"agent-metadata-action/internal/models"
1313
)
1414

@@ -46,15 +46,15 @@ func (c *InstrumentationClient) SendMetadata(ctx context.Context, agentType stri
4646
fmt.Println("::error::Agent type is required but was empty")
4747
return fmt.Errorf("agent type is required")
4848
}
49-
if metadata.Metadata.Version == "" {
49+
if metadata.Metadata["version"] == "" {
5050
fmt.Println("::error::Agent version is required but was empty in metadata")
5151
return fmt.Errorf("agent version is required in metadata")
5252
}
5353
fmt.Printf("::debug::Agent type: %s\n", agentType)
54-
fmt.Printf("::debug::Agent version: %s\n", metadata.Metadata.Version)
54+
fmt.Printf("::debug::Agent version: %s\n", metadata.Metadata["version"])
5555

5656
// Construct URL
57-
url := fmt.Sprintf("%s/v1/agents/%s/versions/%s", c.baseURL, "TestAgent", metadata.Metadata.Version) // @todo update TestAgent after testing
57+
url := fmt.Sprintf("%s/v1/agents/%s/versions/%s", c.baseURL, "TestAgent", metadata.Metadata["version"]) // @todo update TestAgent after testing
5858
fmt.Printf("::debug::Target URL: %s\n", url)
5959
fmt.Printf("::debug::Base URL: %s\n", c.baseURL)
6060

@@ -100,7 +100,7 @@ func (c *InstrumentationClient) SendMetadata(ctx context.Context, agentType stri
100100

101101
// Read response body for error details (with size limit)
102102
fmt.Println("::debug::Reading response body...")
103-
body, err := fileutil.ReadAllSafe(resp.Body, fileutil.MaxHTTPResponseSize)
103+
body, err := io.ReadAll(resp.Body)
104104
if err != nil {
105105
fmt.Printf("::error::Failed to read response body: %v\n", err)
106106
return fmt.Errorf("failed to read response: %w", err)

internal/client/instrumentation_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestSendMetadata_Success(t *testing.T) {
4949
var metadata models.AgentMetadata
5050
err = json.Unmarshal(body, &metadata)
5151
require.NoError(t, err)
52-
assert.Equal(t, "1.2.3", metadata.Metadata.Version)
52+
assert.Equal(t, "1.2.3", metadata.Metadata["version"])
5353

5454
// Send success response
5555
w.WriteHeader(http.StatusOK)
@@ -61,7 +61,7 @@ func TestSendMetadata_Success(t *testing.T) {
6161

6262
metadata := &models.AgentMetadata{
6363
Metadata: models.Metadata{
64-
Version: "1.2.3",
64+
"version": "1.2.3",
6565
},
6666
ConfigurationDefinitions: []models.ConfigurationDefinition{},
6767
AgentControl: []models.AgentControl{},
@@ -103,7 +103,7 @@ func TestSendMetadata_EmptyAgentType(t *testing.T) {
103103

104104
metadata := &models.AgentMetadata{
105105
Metadata: models.Metadata{
106-
Version: "1.2.3",
106+
"version": "1.2.3",
107107
},
108108
}
109109

@@ -123,7 +123,7 @@ func TestSendMetadata_EmptyAgentVersion(t *testing.T) {
123123

124124
metadata := &models.AgentMetadata{
125125
Metadata: models.Metadata{
126-
Version: "", // Empty version
126+
"version": "", // Empty version
127127
},
128128
}
129129

@@ -189,7 +189,7 @@ func TestSendMetadata_HTTPErrors(t *testing.T) {
189189

190190
metadata := &models.AgentMetadata{
191191
Metadata: models.Metadata{
192-
Version: "1.2.3",
192+
"version": "1.2.3",
193193
},
194194
ConfigurationDefinitions: []models.ConfigurationDefinition{},
195195
AgentControl: []models.AgentControl{},
@@ -221,7 +221,7 @@ func TestSendMetadata_LargeResponseBodyTruncation(t *testing.T) {
221221

222222
metadata := &models.AgentMetadata{
223223
Metadata: models.Metadata{
224-
Version: "1.2.3",
224+
"version": "1.2.3",
225225
},
226226
ConfigurationDefinitions: []models.ConfigurationDefinition{},
227227
AgentControl: []models.AgentControl{},
@@ -244,7 +244,7 @@ func TestSendMetadata_NetworkError(t *testing.T) {
244244

245245
metadata := &models.AgentMetadata{
246246
Metadata: models.Metadata{
247-
Version: "1.2.3",
247+
"version": "1.2.3",
248248
},
249249
ConfigurationDefinitions: []models.ConfigurationDefinition{},
250250
AgentControl: []models.AgentControl{},
@@ -273,7 +273,7 @@ func TestSendMetadata_ContextCancellation(t *testing.T) {
273273

274274
metadata := &models.AgentMetadata{
275275
Metadata: models.Metadata{
276-
Version: "1.2.3",
276+
"version": "1.2.3",
277277
},
278278
ConfigurationDefinitions: []models.ConfigurationDefinition{},
279279
AgentControl: []models.AgentControl{},
@@ -305,7 +305,7 @@ func TestSendMetadata_SuccessWithResponseBody(t *testing.T) {
305305

306306
metadata := &models.AgentMetadata{
307307
Metadata: models.Metadata{
308-
Version: "1.2.3",
308+
"version": "1.2.3",
309309
},
310310
ConfigurationDefinitions: []models.ConfigurationDefinition{},
311311
AgentControl: []models.AgentControl{},
@@ -346,24 +346,24 @@ func TestSendMetadata_WithConfigurationDefinitionsAndAgentControl(t *testing.T)
346346

347347
metadata := &models.AgentMetadata{
348348
Metadata: models.Metadata{
349-
Version: "1.2.3",
349+
"version": "1.2.3",
350350
},
351351
ConfigurationDefinitions: []models.ConfigurationDefinition{
352352
{
353-
Version: "1.0.0",
354-
Platform: "linux",
355-
Description: "Config 1",
356-
Type: "string",
357-
Format: "text",
358-
Schema: "schema1",
353+
"version": "1.0.0",
354+
"platform": "linux",
355+
"description": "Config 1",
356+
"type": "string",
357+
"format": "text",
358+
"schema": "schema1",
359359
},
360360
{
361-
Version: "1.0.0",
362-
Platform: "windows",
363-
Description: "Config 2",
364-
Type: "string",
365-
Format: "text",
366-
Schema: "schema2",
361+
"version": "1.0.0",
362+
"platform": "windows",
363+
"description": "Config 2",
364+
"type": "string",
365+
"format": "text",
366+
"schema": "schema2",
367367
},
368368
},
369369
AgentControl: []models.AgentControl{

internal/fileutil/fileutil.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)