From 762a760f5e6b33e81582987060c8c63d5c32fe9f Mon Sep 17 00:00:00 2001 From: keval Date: Thu, 27 Jun 2024 18:35:16 +0530 Subject: [PATCH] fixed pkg/stanza failed checks --- pkg/stanza/operator/parser/json/config.go | 34 --------------- .../k8seventsreceiver/log_agent_success.go | 42 ------------------- .../log_agent_success_test.go | 34 --------------- receiver/k8seventsreceiver/receiver.go | 5 --- 4 files changed, 115 deletions(-) delete mode 100644 receiver/k8seventsreceiver/log_agent_success.go delete mode 100644 receiver/k8seventsreceiver/log_agent_success_test.go diff --git a/pkg/stanza/operator/parser/json/config.go b/pkg/stanza/operator/parser/json/config.go index 65e41e18d1c7..4bf7c0087144 100644 --- a/pkg/stanza/operator/parser/json/config.go +++ b/pkg/stanza/operator/parser/json/config.go @@ -4,13 +4,9 @@ package json // import "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/parser/json" import ( - "context" - "fmt" - jsoniter "github.com/json-iterator/go" "go.opentelemetry.io/collector/component" - "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/entry" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/stanza/operator/helper" ) @@ -50,33 +46,3 @@ func (c Config) Build(set component.TelemetrySettings) (operator.Operator, error json: jsoniter.ConfigFastest, }, nil } - -// Parser is an operator that parses JSON. -type Parser struct { - helper.ParserOperator - json jsoniter.API -} - -// Process will parse an entry for JSON. -func (j *Parser) Process(ctx context.Context, entry *entry.Entry) error { - return j.ParserOperator.ProcessWith(ctx, entry, j.parse) -} - -// parse will parse a value as JSON. -func (j *Parser) parse(value interface{}) (interface{}, error) { - fmt.Println(value) - if j.Flatten == true { - fmt.Println("Requested for flatten...!!") - } - var parsedValue map[string]interface{} - switch m := value.(type) { - case string: - err := j.json.UnmarshalFromString(m, &parsedValue) - if err != nil { - return nil, err - } - default: - return nil, fmt.Errorf("type %T cannot be parsed as JSON", value) - } - return parsedValue, nil -} diff --git a/receiver/k8seventsreceiver/log_agent_success.go b/receiver/k8seventsreceiver/log_agent_success.go deleted file mode 100644 index b8c1e5ce10ec..000000000000 --- a/receiver/k8seventsreceiver/log_agent_success.go +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 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 k8seventsreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8seventsreceiver" - -import ( - "go.opentelemetry.io/collector/pdata/plog" - semconv "go.opentelemetry.io/collector/semconv/v1.6.1" - "go.uber.org/zap" -) - -// k8sEventToLogRecord converts Kubernetes event to plog.LogRecordSlice and adds the resource attributes. -func logk8sClusterSuccessMessage(logger *zap.Logger) plog.Logs { - ld := plog.NewLogs() - rl := ld.ResourceLogs().AppendEmpty() - sl := rl.ScopeLogs().AppendEmpty() - lr := sl.LogRecords().AppendEmpty() - - resourceAttrs := rl.Resource().Attributes() - resourceAttrs.EnsureCapacity(1) - resourceAttrs.PutStr(semconv.AttributeK8SClusterName, "unknown") - - // A static message to show that the middleware agent is running - lr.Body().SetStr("Middleware Agent installed successfully") - - // Log added as type "info" - lr.SetSeverityNumber(9) - // lr.SetSeverityText(ev.Type) - - return ld -} diff --git a/receiver/k8seventsreceiver/log_agent_success_test.go b/receiver/k8seventsreceiver/log_agent_success_test.go deleted file mode 100644 index fcd3bef3ff29..000000000000 --- a/receiver/k8seventsreceiver/log_agent_success_test.go +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 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 k8seventsreceiver - -import ( - "testing" - - "github.com/stretchr/testify/assert" - "go.uber.org/zap" -) - -func TestLogk8sClusterSuccessMessage(t *testing.T) { - - ld := logk8sClusterSuccessMessage(zap.NewNop()) - rl := ld.ResourceLogs().At(0) - resourceAttrs := rl.Resource().Attributes() - lr := rl.ScopeLogs().At(0) - attrs := lr.LogRecords().At(0).Attributes() - assert.Equal(t, ld.ResourceLogs().Len(), 1) - assert.Equal(t, resourceAttrs.Len(), 1) - assert.Equal(t, attrs.Len(), 0) -} diff --git a/receiver/k8seventsreceiver/receiver.go b/receiver/k8seventsreceiver/receiver.go index 4b4a8cba27b0..cb6c99aab2be 100644 --- a/receiver/k8seventsreceiver/receiver.go +++ b/receiver/k8seventsreceiver/receiver.go @@ -59,11 +59,6 @@ func newReceiver( func (kr *k8seventsReceiver) Start(ctx context.Context, _ component.Host) error { kr.ctx, kr.cancel = context.WithCancel(ctx) - // Adding a log entry to indicate that the receiver has started successfully. - ld := logk8sClusterSuccessMessage(kr.settings.Logger) - consumerErr := kr.logsConsumer.ConsumeLogs(ctx, ld) - kr.obsrecv.EndLogsOp(ctx, metadata.Type, 1, consumerErr) - k8sInterface, err := kr.config.getK8sClient() if err != nil { return err