Skip to content

Commit 93e00d3

Browse files
feat: add TelemetryURL support to ApiClient and configuration
- Introduced TelemetryURL in the ApiClient struct to allow separate telemetry endpoint usage. - Updated the agent to utilize TelemetryURL for sending DNS records and network connections. - Enhanced configuration handling to initialize TelemetryURL from the config file, defaulting to APIURL if not specified.
1 parent 8192dfe commit 93e00d3

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

agent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func Run(ctx context.Context, configFilePath string, hostDNSServer DNSServer,
6767
return err
6868
}
6969

70-
apiclient := &ApiClient{Client: &http.Client{Timeout: 3 * time.Second}, APIURL: config.APIURL, DisableTelemetry: config.DisableTelemetry, EgressPolicy: config.EgressPolicy, OneTimeKey: config.OneTimeKey}
70+
apiclient := &ApiClient{Client: &http.Client{Timeout: 3 * time.Second}, APIURL: config.APIURL, TelemetryURL: config.TelemetryURL, DisableTelemetry: config.DisableTelemetry, EgressPolicy: config.EgressPolicy, OneTimeKey: config.OneTimeKey}
7171

7272
config.OneTimeKey = ""
7373
// TODO: pass in an iowriter/ use log library

apiclient.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type NetworkConnection struct {
4141
type ApiClient struct {
4242
Client *http.Client
4343
APIURL string
44+
TelemetryURL string
4445
DisableTelemetry bool
4546
EgressPolicy string
4647
OneTimeKey string
@@ -57,7 +58,7 @@ func (apiclient *ApiClient) sendDNSRecord(correlationId, repo, domainName, ipAdd
5758
dnsRecord.ResolvedIPAddress = ipAddress
5859
dnsRecord.TimeStamp = time.Now().UTC()
5960

60-
url := fmt.Sprintf("%s/github/%s/actions/jobs/%s/dns", apiclient.APIURL, repo, correlationId)
61+
url := fmt.Sprintf("%s/github/%s/actions/jobs/%s/dns", apiclient.TelemetryURL, repo, correlationId)
6162

6263
return apiclient.sendApiRequest("POST", url, dnsRecord)
6364
}
@@ -76,7 +77,7 @@ func (apiclient *ApiClient) sendNetConnection(correlationId, repo, ipAddress, po
7677
networkConnection.TimeStamp = timestamp
7778
networkConnection.Tool = tool
7879

79-
url := fmt.Sprintf("%s/github/%s/actions/jobs/%s/networkconnection", apiclient.APIURL, repo, correlationId)
80+
url := fmt.Sprintf("%s/github/%s/actions/jobs/%s/networkconnection", apiclient.TelemetryURL, repo, correlationId)
8081

8182
return apiclient.sendApiRequest("POST", url, networkConnection)
8283
}

config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type config struct {
1616
RunId string
1717
WorkingDirectory string
1818
APIURL string
19+
TelemetryURL string
1920
OneTimeKey string
2021
Endpoints map[string][]Endpoint
2122
EgressPolicy string
@@ -37,6 +38,7 @@ type configFile struct {
3738
RunId string `json:"run_id"`
3839
WorkingDirectory string `json:"working_directory"`
3940
APIURL string `json:"api_url"`
41+
TelemetryURL string `json:"telemetry_url"`
4042
OneTimeKey string `json:"one_time_key"`
4143
AllowedEndpoints string `json:"allowed_endpoints"`
4244
EgressPolicy string `json:"egress_policy"`
@@ -65,6 +67,10 @@ func (c *config) init(configFilePath string) error {
6567
c.RunId = configFile.RunId
6668
c.WorkingDirectory = configFile.WorkingDirectory
6769
c.APIURL = configFile.APIURL
70+
c.TelemetryURL = configFile.TelemetryURL
71+
if c.TelemetryURL == "" {
72+
c.TelemetryURL = c.APIURL
73+
}
6874
c.Endpoints = parseEndpoints(configFile.AllowedEndpoints)
6975
c.EgressPolicy = configFile.EgressPolicy
7076
c.DisableTelemetry = configFile.DisableTelemetry

0 commit comments

Comments
 (0)