Skip to content

Commit

Permalink
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
Browse files Browse the repository at this point in the history
…tor-contrib into jmacd/newboundedqueue
  • Loading branch information
jmacd committed Nov 8, 2024
2 parents 336ce77 + 5618c7c commit ff9090a
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 28 deletions.
27 changes: 27 additions & 0 deletions .chloggen/fix_prometheusexporter-shutdown-server-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: prometheusexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Fixes a race condition between the exporter start and shutdown functions."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [36139]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
2 changes: 1 addition & 1 deletion cmd/opampsupervisor/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func getSupervisorConfig(t *testing.T, configType string, extraConfigData map[st
"goos": runtime.GOOS,
"goarch": runtime.GOARCH,
"extension": extension,
"storage_dir": t.TempDir(),
"storage_dir": strings.ReplaceAll(t.TempDir(), "\\", "\\\\"),
}

for key, val := range extraConfigData {
Expand Down
14 changes: 5 additions & 9 deletions exporter/prometheusexporter/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ func (pe *prometheusExporter) Start(ctx context.Context, host component.Host) er
mux := http.NewServeMux()
mux.Handle("/metrics", pe.handler)
srv, err := pe.config.ToServer(ctx, host, pe.settings, mux)
pe.shutdownFunc = func(ctx context.Context) error {
errLn := ln.Close()
if srv == nil {
return errLn
}
errSrv := srv.Shutdown(ctx)
return errors.Join(errLn, errSrv)
}
if err != nil {
return err
lnerr := ln.Close()
return errors.Join(err, lnerr)
}
pe.shutdownFunc = func(ctx context.Context) error {
return srv.Shutdown(ctx)
}
go func() {
_ = srv.Serve(ln)
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/input/windows/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (b *Bookmark) Update(event Event) error {
}

// Render will render the bookmark as xml.
func (b *Bookmark) Render(buffer Buffer) (string, error) {
func (b *Bookmark) Render(buffer *Buffer) (string, error) {
if b.handle == 0 {
return "", fmt.Errorf("bookmark handle is not open")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/operator/input/windows/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (b *Buffer) FirstByte() *byte {
}

// NewBuffer creates a new buffer with the default buffer size
func NewBuffer() Buffer {
return Buffer{
func NewBuffer() *Buffer {
return &Buffer{
buffer: make([]byte, defaultBufferSize),
}
}
11 changes: 0 additions & 11 deletions pkg/stanza/operator/input/windows/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@ func TestBufferReadBytes(t *testing.T) {
require.Equal(t, utf8, bytes)
}

func TestBufferReadBytesOverflow(t *testing.T) {
buffer := NewBuffer()
utf8 := []byte("test")
utf16, _ := unicode.UTF16(unicode.LittleEndian, unicode.UseBOM).NewEncoder().Bytes(utf8)
copy(buffer.buffer, utf16)
offset := uint32(len(utf16))
bytes, err := buffer.ReadBytes(offset * 2)
require.NoError(t, err)
require.Equal(t, utf8, bytes)
}

func TestBufferReadWideBytes(t *testing.T) {
buffer := NewBuffer()
utf8 := []byte("test")
Expand Down
6 changes: 3 additions & 3 deletions pkg/stanza/operator/input/windows/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type Event struct {
}

// GetPublisherName will get the publisher name of the event.
func (e *Event) GetPublisherName(buffer Buffer) (string, error) {
func (e *Event) GetPublisherName(buffer *Buffer) (string, error) {
if e.handle == 0 {
return "", fmt.Errorf("event handle does not exist")
}
Expand Down Expand Up @@ -77,7 +77,7 @@ func NewEvent(handle uintptr) Event {
}

// RenderSimple will render the event as EventXML without formatted info.
func (e *Event) RenderSimple(buffer Buffer) (*EventXML, error) {
func (e *Event) RenderSimple(buffer *Buffer) (*EventXML, error) {
if e.handle == 0 {
return nil, fmt.Errorf("event handle does not exist")
}
Expand All @@ -100,7 +100,7 @@ func (e *Event) RenderSimple(buffer Buffer) (*EventXML, error) {
}

// RenderDeep will render the event as EventXML with all available formatted info.
func (e *Event) RenderDeep(buffer Buffer, publisher Publisher) (*EventXML, error) {
func (e *Event) RenderDeep(buffer *Buffer, publisher Publisher) (*EventXML, error) {
if e.handle == 0 {
return nil, fmt.Errorf("event handle does not exist")
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/input/windows/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
type Input struct {
helper.InputOperator
bookmark Bookmark
buffer Buffer
buffer *Buffer
channel string
maxReads int
startAt string
Expand Down

0 comments on commit ff9090a

Please sign in to comment.