Skip to content

reproducer for logsDropped #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions go-example-telemetry-api-extension/function/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
console.log('Hello from function initalization');
console.log("Hello from function initalization");

exports.handler = async (event, context) => {
console.log('Hello from function handler', {event});
}
for (let i = 0; i < 1000; i++) {
console.log(`I'm log ${i}`);
}
const response = {
statusCode: 200,
body: "hello, world",
};
return response;
};
4 changes: 2 additions & 2 deletions go-example-telemetry-api-extension/telemetryApi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ type SubscribeResponse struct {
func (c *Client) Subscribe(ctx context.Context, extensionId string, listenerUri string) (*SubscribeResponse, error) {
eventTypes := []EventType{
Platform,
// Function,
// Extension,
Function,
Extension,
}

bufferingConfig := BufferingCfg{
Expand Down
27 changes: 11 additions & 16 deletions go-example-telemetry-api-extension/telemetryApi/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
package telemetryApi

import (
"bytes"
"context"
"encoding/json"
"net/http"
"os"
"strconv"
"strings"

"github.com/golang-collections/go-datastructures/queue"
)
Expand Down Expand Up @@ -40,20 +40,15 @@ func NewDispatcher() *Dispatcher {
}

func (d *Dispatcher) Dispatch(ctx context.Context, logEventsQueue *queue.Queue, force bool) {
if !logEventsQueue.Empty() && (force || logEventsQueue.Len() >= d.minBatchSize) {
l.Info("[dispatcher:Dispatch] Dispatching", logEventsQueue.Len(), "log events")
logEntries, _ := logEventsQueue.Get(logEventsQueue.Len())
bodyBytes, _ := json.Marshal(logEntries)
req, err := http.NewRequestWithContext(ctx, "POST", d.postUri, bytes.NewBuffer(bodyBytes))
if err != nil {
panic(err)
}
_, err = d.httpClient.Do(req)
if err != nil {
l.Error("[dispatcher:Dispatch] Failed to dispatch, returning to queue:", err)
for logEntry := range logEntries {
logEventsQueue.Put(logEntry)
}
}
l.Info("[dispatcher:Dispatch] Dispatching", logEventsQueue.Len(), "log events")
logEntries, _ := logEventsQueue.Get(logEventsQueue.Len())
body, err := json.Marshal(logEntries)
if err != nil {
l.Error("[dispatcher:Dispatch] Failed to marshal log entries", err)
return
}
l.Info("[dispatcher:Dispatch] Dispatched", logEventsQueue.Len(), "log events")
if strings.Contains(string(body), "logsDropped") {
l.Info("[dispatcher:Dispatch] LOG DROPPED!")
}
}