Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mwear committed Aug 2, 2023
1 parent a7bf171 commit cec36a7
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 93 deletions.
2 changes: 1 addition & 1 deletion component/componenttest/nop_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func NewNopHost() component.Host {

func (nh *nopHost) ReportFatalError(_ error) {}

func (hw *nopHost) ReportComponentStatus(event *component.StatusEvent) {}
func (nh *nopHost) ReportComponentStatus(_ *component.StatusEvent) {}

Check warning on line 20 in component/componenttest/nop_host.go

View check run for this annotation

Codecov / codecov/patch

component/componenttest/nop_host.go#L20

Added line #L20 was not covered by tests

func (nh *nopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
return nil
Expand Down
25 changes: 7 additions & 18 deletions component/status.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package component
package component // import "go.opentelemetry.io/collector/component"

import (
"errors"
Expand Down Expand Up @@ -45,12 +34,12 @@ func (ev *StatusEvent) Err() error {
return ev.err
}

// statusEventOption applies options to a StatusEvent.
type statusEventOption func(*StatusEvent) error
// StatusEventOption applies options to a StatusEvent.
type StatusEventOption func(*StatusEvent) error

// WithError sets the error object of the Event. It is optional
// and should only be applied to an Event of type ComponentError.
func WithError(err error) statusEventOption {
func WithError(err error) StatusEventOption {
return func(o *StatusEvent) error {
if o.status == StatusOK {
return errors.New("event with ComponentOK cannot have an error")
Expand All @@ -64,7 +53,7 @@ func WithError(err error) statusEventOption {
// options. Will return an error if an error is provided for a non-error event
// type (status.ComponentOK).
// If the timestamp is not provided will set it to time.Now().
func NewStatusEvent(status Status, options ...statusEventOption) (*StatusEvent, error) {
func NewStatusEvent(status Status, options ...StatusEventOption) (*StatusEvent, error) {
ev := StatusEvent{
status: status,
}
Expand Down
28 changes: 24 additions & 4 deletions component/status_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package component

import (
"fmt"
"errors"
"testing"
"unsafe"

"github.com/stretchr/testify/require"
)

func TestStatusEventSize(t *testing.T) {
fmt.Printf("StatusEvent size=%d", unsafe.Sizeof(StatusEvent{}))
func TestStatusEventOK(t *testing.T) {
event, err := NewStatusEvent(StatusOK)
require.NoError(t, err)
require.Equal(t, StatusOK, event.Status())
require.Nil(t, event.Err())
}

func TestStatusEventOKWithError(t *testing.T) {
event, err := NewStatusEvent(StatusOK, WithError(errors.New("an error")))
require.Error(t, err)
require.Nil(t, event)
}

func TestStatusEventError(t *testing.T) {
eventErr := errors.New("an error")
event, err := NewStatusEvent(StatusError, WithError(eventErr))
require.NoError(t, err)
require.Equal(t, StatusError, event.Status())
require.Equal(t, eventErr, event.Err())
}
13 changes: 1 addition & 12 deletions extension/extensiontest/statuswatcher_extension.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

package extensiontest // import "go.opentelemetry.io/collector/extension/extensiontest"

Expand Down
17 changes: 3 additions & 14 deletions processor/processortest/unhealthy_processor.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// SPDX-License-Identifier: Apache-2.0

package processortest // import "go.opentelemetry.io/collector/component/componenttest"
package processortest // import "go.opentelemetry.io/collector/processor/processortest"

import (
"context"
Expand Down Expand Up @@ -68,7 +57,7 @@ type unhealthyProcessor struct {
consumertest.Consumer
}

func (unhealthyProcessor) Start(ctx context.Context, host component.Host) error {
func (unhealthyProcessor) Start(_ context.Context, host component.Host) error {
go func() {
evt, _ := component.NewStatusEvent(component.StatusError)
host.ReportComponentStatus(evt)
Expand Down
3 changes: 2 additions & 1 deletion service/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ func (host *serviceHost) ReportFatalError(err error) {
}

func (host *serviceHost) ReportComponentStatus(source component.StatusSource, event *component.StatusEvent) {
host.serviceExtensions.NotifyComponentStatusChange(source, event)
// TODO: What should we do if there is an error notifying here?
host.serviceExtensions.NotifyComponentStatusChange(source, event) //nolint:errcheck
}

func (host *serviceHost) GetFactory(kind component.Kind, componentType component.Type) component.Factory {
Expand Down
4 changes: 1 addition & 3 deletions service/internal/components/host_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ func NewHostWrapper(host servicehost.Host, component component.StatusSource, log
func (hw *hostWrapper) ReportFatalError(err error) {
// The logger from the built component already identifies the component.
hw.Logger.Error("Component fatal error", zap.Error(err))
hw.Host.ReportFatalError(err)
hw.Host.ReportFatalError(err) // nolint:staticcheck
}

var emptyComponentID = component.ID{}

func (hw *hostWrapper) ReportComponentStatus(event *component.StatusEvent) {
hw.Host.ReportComponentStatus(hw.component, event)
}
Expand Down
11 changes: 1 addition & 10 deletions service/internal/graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,7 @@ func (g *Graph) StartAll(ctx context.Context, host servicehost.Host) error {
continue
}

statusSource, ok := g.statusSources[node.ID()]

if !ok {
// TODO: this should not happen. I'm not sure this code path will remain, but if it does
// we should ensure that we have a valid nop value for statusSource.
}

// note: there is no longer a per-component logger, hence the zap.NewNop()
// we should be able to remove the logger from components.NewHostWrapper as we deprecate
// and remove host.ReportFatalError
statusSource := g.statusSources[node.ID()]
hostWrapper := components.NewHostWrapper(host, statusSource, zap.NewNop())

if compErr := comp.Start(ctx, hostWrapper); compErr != nil {
Expand Down
15 changes: 3 additions & 12 deletions service/internal/servicehost/host.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package servicehost
package servicehost // import "go.opentelemetry.io/collector/service/internal/servicehost"

import (
"go.opentelemetry.io/collector/component"
Expand Down
25 changes: 7 additions & 18 deletions service/internal/servicehost/nop_host.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
// Copyright The OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package servicehost
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package servicehost // import "go.opentelemetry.io/collector/service/internal/servicehost"

import (
"go.opentelemetry.io/collector/component"
Expand All @@ -21,13 +10,13 @@ import (
// nopHost mocks a receiver.ReceiverHost for test purposes.
type nopHost struct{}

func (n nopHost) ReportFatalError(err error) {
func (n nopHost) ReportFatalError(_ error) {
}

func (n nopHost) ReportComponentStatus(source component.StatusSource, event *component.StatusEvent) {
func (n nopHost) ReportComponentStatus(_ component.StatusSource, _ *component.StatusEvent) {
}

func (n nopHost) GetFactory(kind component.Kind, componentType component.Type) component.Factory {
func (n nopHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
return nil

Check warning on line 20 in service/internal/servicehost/nop_host.go

View check run for this annotation

Codecov / codecov/patch

service/internal/servicehost/nop_host.go#L19-L20

Added lines #L19 - L20 were not covered by tests
}

Expand Down

0 comments on commit cec36a7

Please sign in to comment.