Skip to content

Commit 4f18179

Browse files
authored
Refactor logsapi package (#129)
* Refactor logsapi * Add test for subscribing to logs API * Further abstract sending logs api subscription request * Make sure to close logsapi server at test end and unset env vars * Test with different port * Improve and consolidate tests * Allow logsapi listenerhost to be set for testing * Minor improvements * Respond with status code 500 if json cannot be unmarshalled * No reason to close the body, the server does * Fix variable names and other updates from code review * Don't use a variable for the error in the method signature * Add code review suggestion that was overwritten by a push with --force * Don't initialize logsAPIListener in function, it's already defined * No need to send request in go routine if a buffered channel is used * Cancel the background context when a shutdown event is received * Define UnmarshalJSON function for a LogEvent * Handle case when json doesn't unmarshal correctly * Use anon struct in UnmarshalJSON function * Simplify UnmarshalJSON function * Check first byte of record to determine if it's an object or string * Use json.Decoder in test
1 parent 50c1105 commit 4f18179

File tree

9 files changed

+480
-339
lines changed

9 files changed

+480
-339
lines changed

apm-lambda-extension/logsapi/client.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"io/ioutil"
25-
"log"
2625
"net/http"
2726

2827
"github.com/pkg/errors"
@@ -130,8 +129,18 @@ type SubscribeResponse struct {
130129
}
131130

132131
// Subscribe calls the Logs API to subscribe for the log events.
133-
func (c *Client) Subscribe(types []EventType, bufferingCfg BufferingCfg, destination Destination, extensionId string) (*SubscribeResponse, error) {
134-
132+
func (c *Client) Subscribe(types []EventType, destinationURI URI, extensionId string) (*SubscribeResponse, error) {
133+
bufferingCfg := BufferingCfg{
134+
MaxItems: 10000,
135+
MaxBytes: 262144,
136+
TimeoutMS: 25,
137+
}
138+
destination := Destination{
139+
Protocol: HttpProto,
140+
URI: destinationURI,
141+
HttpMethod: HttpPost,
142+
Encoding: JSON,
143+
}
135144
data, err := json.Marshal(
136145
&SubscribeRequest{
137146
SchemaVersion: SchemaVersionLatest,
@@ -153,7 +162,6 @@ func (c *Client) Subscribe(types []EventType, bufferingCfg BufferingCfg, destina
153162
defer resp.Body.Close()
154163

155164
if resp.StatusCode == http.StatusAccepted {
156-
log.Println("Logs API is not supported. Is this extension running in a local sandbox?")
157165
return nil, errors.Errorf("Logs API is not supported in this environment")
158166
} else if resp.StatusCode != http.StatusOK {
159167
body, err := ioutil.ReadAll(resp.Body)

apm-lambda-extension/logsapi/http_listener.go

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

apm-lambda-extension/logsapi/http_listener_test.go

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

apm-lambda-extension/logsapi/init.go

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

0 commit comments

Comments
 (0)