Skip to content
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

Enable lint on windows via GOOS playground #22

Closed
wants to merge 7 commits 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
2 changes: 2 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ jobs:
key: go-lint-build-${{ matrix.group }}-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
- name: Lint
run: make -j2 golint GROUP=${{ matrix.group }}
- name: Lint with GOOS=windows
run: GOOS=windows make -j2 golint GROUP=${{ matrix.group }}
lint:
if: ${{ github.actor != 'dependabot[bot]' && always() }}
runs-on: ubuntu-latest
Expand Down
5 changes: 2 additions & 3 deletions pkg/stanza/fileconsumer/file_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/fileconsumer/internal/reader"
)

func (m *Manager) preConsume(ctx context.Context, newReaders []*reader.Reader) {
return
func (m *Manager) preConsume(_ context.Context, _ []*reader.Reader) {
}

// On windows, we close files immediately after reading becauase they cannot be moved while open.
// On windows, we close files immediately after reading because they cannot be moved while open.
func (m *Manager) postConsume(readers []*reader.Reader) {
m.previousPollFiles = readers
m.closePreviousFiles()
Expand Down
2 changes: 1 addition & 1 deletion pkg/stanza/operator/input/journald/journald_nonlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
)

func (c Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
func (c Config) Build(_ *zap.SugaredLogger) (operator.Operator, error) {
return nil, errors.New("journald input operator is only supported on linux")
}
5 changes: 3 additions & 2 deletions pkg/stanza/operator/input/namedpipe/namedpipe_nonlinux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ package namedpipe // import "github.com/open-telemetry/opentelemetry-collector-c
import (
"errors"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
)

func (c *Config) Build(logger *zap.SugaredLogger) (operator.Operator, error) {
func (c *Config) Build(_ *zap.SugaredLogger) (operator.Operator, error) {
return nil, errors.New("namedpipe input operator is only supported on linux")
}
23 changes: 12 additions & 11 deletions pkg/stanza/operator/input/windows/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package windows // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/windows"

import (
"errors"
"syscall"
"unsafe"

Expand Down Expand Up @@ -68,7 +69,7 @@ const (
// evtSubscribe is the direct syscall implementation of EvtSubscribe (https://docs.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtsubscribe)
func evtSubscribe(session uintptr, signalEvent windows.Handle, channelPath *uint16, query *uint16, bookmark uintptr, context uintptr, callback uintptr, flags uint32) (uintptr, error) {
handle, _, err := subscribeProc.Call(session, uintptr(signalEvent), uintptr(unsafe.Pointer(channelPath)), uintptr(unsafe.Pointer(query)), bookmark, context, callback, uintptr(flags))
if err != ErrorSuccess {
if !errors.Is(err, ErrorSuccess) {
return 0, err
}

Expand All @@ -78,29 +79,29 @@ func evtSubscribe(session uintptr, signalEvent windows.Handle, channelPath *uint
// evtNext is the direct syscall implementation of EvtNext (https://docs.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtnext)
func evtNext(resultSet uintptr, eventsSize uint32, events *uintptr, timeout uint32, flags uint32, returned *uint32) error {
_, _, err := nextProc.Call(resultSet, uintptr(eventsSize), uintptr(unsafe.Pointer(events)), uintptr(timeout), uintptr(flags), uintptr(unsafe.Pointer(returned)))
if err != ErrorSuccess {
if !errors.Is(err, ErrorSuccess) {
return err
}

return nil
}

// evtRender is the direct syscall implementation of EvtRender (https://docs.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtrender)
func evtRender(context uintptr, fragment uintptr, flags uint32, bufferSize uint32, buffer *byte) (*uint32, *uint32, error) {
func evtRender(context uintptr, fragment uintptr, flags uint32, bufferSize uint32, buffer *byte) (*uint32, error) {
bufferUsed := new(uint32)
propertyCount := new(uint32)
_, _, err := renderProc.Call(context, fragment, uintptr(flags), uintptr(bufferSize), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(bufferUsed)), uintptr(unsafe.Pointer(propertyCount)))
if err != ErrorSuccess {
return bufferUsed, propertyCount, err
if !errors.Is(err, ErrorSuccess) {
return bufferUsed, err
}

return bufferUsed, propertyCount, nil
return bufferUsed, nil
}

// evtClose is the direct syscall implementation of EvtClose (https://docs.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtclose)
func evtClose(handle uintptr) error {
_, _, err := closeProc.Call(handle)
if err != ErrorSuccess {
if !errors.Is(err, ErrorSuccess) {
return err
}

Expand All @@ -110,7 +111,7 @@ func evtClose(handle uintptr) error {
// evtCreateBookmark is the direct syscall implementation of EvtCreateBookmark (https://docs.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtcreatebookmark)
func evtCreateBookmark(bookmarkXML *uint16) (uintptr, error) {
handle, _, err := createBookmarkProc.Call(uintptr(unsafe.Pointer(bookmarkXML)))
if err != ErrorSuccess {
if !errors.Is(err, ErrorSuccess) {
return 0, err
}

Expand All @@ -120,7 +121,7 @@ func evtCreateBookmark(bookmarkXML *uint16) (uintptr, error) {
// evtUpdateBookmark is the direct syscall implementation of EvtUpdateBookmark (https://docs.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtcreatebookmark)
func evtUpdateBookmark(bookmark uintptr, event uintptr) error {
_, _, err := updateBookmarkProc.Call(bookmark, event)
if err != ErrorSuccess {
if !errors.Is(err, ErrorSuccess) {
return err
}

Expand All @@ -130,7 +131,7 @@ func evtUpdateBookmark(bookmark uintptr, event uintptr) error {
// evtOpenPublisherMetadata is the direct syscall implementation of EvtOpenPublisherMetadata (https://docs.microsoft.com/en-us/windows/win32/api/winevt/nf-winevt-evtopenpublishermetadata)
func evtOpenPublisherMetadata(session uintptr, publisherIdentity *uint16, logFilePath *uint16, locale uint32, flags uint32) (uintptr, error) {
handle, _, err := openPublisherMetadataProc.Call(session, uintptr(unsafe.Pointer(publisherIdentity)), uintptr(unsafe.Pointer(logFilePath)), uintptr(locale), uintptr(flags))
if err != ErrorSuccess {
if !errors.Is(err, ErrorSuccess) {
return 0, err
}

Expand All @@ -141,7 +142,7 @@ func evtOpenPublisherMetadata(session uintptr, publisherIdentity *uint16, logFil
func evtFormatMessage(publisherMetadata uintptr, event uintptr, messageID uint32, valueCount uint32, values uintptr, flags uint32, bufferSize uint32, buffer *byte) (*uint32, error) {
bufferUsed := new(uint32)
_, _, err := formatMessageProc.Call(publisherMetadata, event, uintptr(messageID), uintptr(valueCount), values, uintptr(flags), uintptr(bufferSize), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(bufferUsed)))
if err != ErrorSuccess {
if !errors.Is(err, ErrorSuccess) {
return bufferUsed, err
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/stanza/operator/input/windows/bookmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package windows // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/input/windows"

import (
"errors"
"fmt"
"syscall"
)
Expand Down Expand Up @@ -59,8 +60,8 @@ func (b *Bookmark) Render(buffer Buffer) (string, error) {
return "", fmt.Errorf("bookmark handle is not open")
}

bufferUsed, _, err := evtRender(0, b.handle, EvtRenderBookmark, buffer.SizeBytes(), buffer.FirstByte())
if err == ErrorInsufficientBuffer {
bufferUsed, err := evtRender(0, b.handle, EvtRenderBookmark, buffer.SizeBytes(), buffer.FirstByte())
if errors.Is(err, ErrorInsufficientBuffer) {
buffer.UpdateSizeBytes(*bufferUsed)
return b.Render(buffer)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/stanza/operator/input/windows/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ func (e *Event) RenderSimple(buffer Buffer) (EventXML, error) {
return EventXML{}, fmt.Errorf("event handle does not exist")
}

bufferUsed, _, err := evtRender(0, e.handle, EvtRenderEventXML, buffer.SizeBytes(), buffer.FirstByte())
if err == ErrorInsufficientBuffer {
bufferUsed, err := evtRender(0, e.handle, EvtRenderEventXML, buffer.SizeBytes(), buffer.FirstByte())
if errors.Is(err, ErrorInsufficientBuffer) {
buffer.UpdateSizeBytes(*bufferUsed)
return e.RenderSimple(buffer)
}
Expand All @@ -50,7 +50,7 @@ func (e *Event) RenderFormatted(buffer Buffer, publisher Publisher) (EventXML, e
}

bufferUsed, err := evtFormatMessage(publisher.handle, e.handle, 0, 0, 0, EvtFormatMessageXML, buffer.SizeWide(), buffer.FirstByte())
if err == ErrorInsufficientBuffer {
if errors.Is(err, ErrorInsufficientBuffer) {
// If the bufferUsed is 0 return an error as we don't want to make a recursive call with no buffer
if *bufferUsed == 0 {
return EventXML{}, errUnknownNextFrame
Expand Down Expand Up @@ -91,8 +91,8 @@ func (e *Event) RenderRaw(buffer Buffer) (EventRaw, error) {
return EventRaw{}, fmt.Errorf("event handle does not exist")
}

bufferUsed, _, err := evtRender(0, e.handle, EvtRenderEventXML, buffer.SizeBytes(), buffer.FirstByte())
if err == ErrorInsufficientBuffer {
bufferUsed, err := evtRender(0, e.handle, EvtRenderEventXML, buffer.SizeBytes(), buffer.FirstByte())
if errors.Is(err, ErrorInsufficientBuffer) {
// If the bufferUsed is 0 return an error as we don't want to make a recursive call with no buffer
if *bufferUsed == 0 {
return EventRaw{}, errUnknownNextFrame
Expand Down
5 changes: 3 additions & 2 deletions pkg/stanza/operator/input/windows/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ import (
"sync"
"time"

"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator"
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper"
"go.uber.org/zap"
)

func init() {
Expand Down Expand Up @@ -81,7 +82,7 @@ func (e *Input) Start(persister operator.Persister) error {
offsetXML, err := e.getBookmarkOffset(ctx)
if err != nil {
e.Errorf("Failed to open bookmark, continuing without previous bookmark: %s", err)
e.persister.Delete(ctx, e.channel)
_ = e.persister.Delete(ctx, e.channel)
}

if offsetXML != "" {
Expand Down
12 changes: 9 additions & 3 deletions pkg/stanza/operator/input/windows/publishercache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (

func TestGetValidPublisher(t *testing.T) {
publisherCache := newPublisherCache()
defer publisherCache.evictAll()
defer func() {
require.NoError(t, publisherCache.evictAll())
}()

// Provider "Application" exists in all Windows versions.
publisher, openPublisherErr := publisherCache.get("Application")
Expand All @@ -29,7 +31,9 @@ func TestGetValidPublisher(t *testing.T) {

func TestGetInvalidPublisher(t *testing.T) {
publisherCache := newPublisherCache()
defer publisherCache.evictAll()
defer func() {
require.NoError(t, publisherCache.evictAll())
}()

// Provider "InvalidProvider" does not exist in any Windows version.
publisher, openPublisherErr := publisherCache.get("InvalidProvider")
Expand All @@ -44,7 +48,9 @@ func TestGetInvalidPublisher(t *testing.T) {

func TestValidAndInvalidPublishers(t *testing.T) {
publisherCache := newPublisherCache()
defer publisherCache.evictAll()
defer func() {
require.NoError(t, publisherCache.evictAll())
}()

// Provider "Application" exists in all Windows versions.
publisher, openPublisherErr := publisherCache.get("Application")
Expand Down
6 changes: 4 additions & 2 deletions pkg/stanza/operator/input/windows/subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ func (s *Subscription) Open(channel string, startAt string, bookmark Bookmark) e
if err != nil {
return fmt.Errorf("failed to create signal handle: %w", err)
}
defer windows.CloseHandle(signalEvent)
defer func() {
_ = windows.CloseHandle(signalEvent)
}()

channelPtr, err := syscall.UTF16PtrFromString(channel)
if err != nil {
Expand Down Expand Up @@ -74,7 +76,7 @@ func (s *Subscription) Read(maxReads int) ([]Event, error) {
var eventsRead uint32
err := evtNext(s.handle, uint32(maxReads), &eventHandles[0], 0, 0, &eventsRead)

if err == ErrorInvalidOperation && eventsRead == 0 {
if errors.Is(err, ErrorInvalidOperation) && eventsRead == 0 {
return nil, nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/winperfcounters/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package winperfcounters // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/winperfcounters"

import (
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -104,8 +105,8 @@ func (pc *perfCounter) Path() string {

func (pc *perfCounter) ScrapeData() ([]CounterValue, error) {
if err := pc.query.CollectData(); err != nil {
pdhErr, ok := err.(*win_perf_counters.PdhError)
if !ok || pdhErr.ErrorCode != win_perf_counters.PDH_CALC_NEGATIVE_DENOMINATOR {
var pdhErr *win_perf_counters.PdhError
if !errors.As(err, &pdhErr) || pdhErr.ErrorCode != win_perf_counters.PDH_CALC_NEGATIVE_DENOMINATOR {
return nil, fmt.Errorf("failed to collect data for performance counter '%s': %w", pc.path, err)
}

Expand Down
7 changes: 1 addition & 6 deletions receiver/podmanreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,5 @@ func createMetricsReceiver(
consumer consumer.Metrics,
) (receiver.Metrics, error) {
podmanConfig := config.(*Config)
dsr, err := newMetricsReceiver(ctx, params, podmanConfig, consumer, nil)
if err != nil {
return nil, err
}

return dsr, nil
return newMetricsReceiver(ctx, params, podmanConfig, consumer, nil)
}
8 changes: 4 additions & 4 deletions receiver/podmanreceiver/receiver_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (

func newMetricsReceiver(
_ context.Context,
settings receiver.CreateSettings,
config *Config,
nextConsumer consumer.Metrics,
clientFactory any,
_ receiver.CreateSettings,
_ *Config,
_ consumer.Metrics,
_ any,
) (receiver.Metrics, error) {
return nil, fmt.Errorf("podman receiver is not supported on windows")
}
6 changes: 3 additions & 3 deletions receiver/sqlserverreceiver/factory_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/sqlserverreceiver/internal/metadata"
)

var errConfigNotSqlServer = errors.New("config was not a sqlserver receiver config")
var errConfigNotSQLServer = errors.New("config was not a sqlserver receiver config")

// createMetricsReceiver creates a metrics receiver based on provided config.
func createMetricsReceiver(
Expand All @@ -29,9 +29,9 @@ func createMetricsReceiver(
) (receiver.Metrics, error) {
cfg, ok := receiverCfg.(*Config)
if !ok {
return nil, errConfigNotSqlServer
return nil, errConfigNotSQLServer
}
sqlServerScraper := newSqlServerScraper(params, cfg)
sqlServerScraper := newSQLServerScraper(params, cfg)

scraper, err := scraperhelper.NewScraper(metadata.Type, sqlServerScraper.scrape,
scraperhelper.WithStart(sqlServerScraper.start),
Expand Down
2 changes: 1 addition & 1 deletion receiver/sqlserverreceiver/factory_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestCreateMetricsReceiver(t *testing.T) {
nil,
consumertest.NewNop(),
)
require.ErrorIs(t, err, errConfigNotSqlServer)
require.ErrorIs(t, err, errConfigNotSQLServer)
},
},
}
Expand Down
10 changes: 5 additions & 5 deletions receiver/sqlserverreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type watcherRecorder struct {
// it needs metadata.MetricsBuilder and timestamp as arguments.
type curriedRecorder func(*metadata.MetricsBuilder, pcommon.Timestamp)

// newSqlServerScraper returns a new sqlServerScraper.
func newSqlServerScraper(params receiver.CreateSettings, cfg *Config) *sqlServerScraper {
// newSQLServerScraper returns a new sqlServerScraper.
func newSQLServerScraper(params receiver.CreateSettings, cfg *Config) *sqlServerScraper {
return &sqlServerScraper{
logger: params.Logger,
config: cfg,
Expand All @@ -48,7 +48,7 @@ func newSqlServerScraper(params receiver.CreateSettings, cfg *Config) *sqlServer
}

// start creates and sets the watchers for the scraper.
func (s *sqlServerScraper) start(ctx context.Context, host component.Host) error {
func (s *sqlServerScraper) start(_ context.Context, _ component.Host) error {
s.watcherRecorders = []watcherRecorder{}

for _, pcr := range perfCounterRecorders {
Expand All @@ -72,7 +72,7 @@ func (s *sqlServerScraper) start(ctx context.Context, host component.Host) error
}

// scrape collects windows performance counter data from all watchers and then records/emits it using the metricBuilder
func (s *sqlServerScraper) scrape(ctx context.Context) (pmetric.Metrics, error) {
func (s *sqlServerScraper) scrape(_ context.Context) (pmetric.Metrics, error) {
recordersByDatabase, errs := recordersPerDatabase(s.watcherRecorders)

for dbName, recorders := range recordersByDatabase {
Expand Down Expand Up @@ -133,7 +133,7 @@ func (s *sqlServerScraper) emitMetricGroup(recorders []curriedRecorder, database
}

// shutdown stops all of the watchers for the scraper.
func (s sqlServerScraper) shutdown(ctx context.Context) error {
func (s sqlServerScraper) shutdown(_ context.Context) error {
var errs error
for _, wr := range s.watcherRecorders {
err := wr.watcher.Close()
Expand Down
Loading
Loading