-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
756cb79
commit 1525128
Showing
222 changed files
with
41,506 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (C) 2022 IBM, Inc. | ||
* | ||
* 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 api | ||
|
||
type OtlpEncode struct { | ||
// grpcaddress and httpaddress are mutually exclusive | ||
// TODO: Should we change these 2 fields to 3 fields: protocol (grpc/http), address, port? | ||
GrpcAddress string `yaml:"grpcaddress" json:"grpcaddress" doc:"address of Otlp Collector (including port) using grpc protocol"` | ||
HttpAddress string `yaml:"httpaddress" json:"httpaddress" doc:"address of Otlp Collector (including port) using http protocol"` | ||
TLS *ClientTLS `yaml:"tls" json:"tls" doc:"TLS client configuration (optional)"` | ||
Headers map[string]string `yaml:"headers" json:"headers" doc:"headers to add to messages (optional)"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright (C) 2023 IBM, Inc. | ||
* | ||
* 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 opentelemetry | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
otel "github.com/agoda-com/opentelemetry-logs-go" | ||
"github.com/agoda-com/opentelemetry-logs-go/logs" | ||
"github.com/netobserv/flowlogs-pipeline/pkg/api" | ||
"github.com/netobserv/flowlogs-pipeline/pkg/config" | ||
"github.com/netobserv/flowlogs-pipeline/pkg/operational" | ||
"github.com/netobserv/flowlogs-pipeline/pkg/pipeline/encode" | ||
"github.com/netobserv/flowlogs-pipeline/pkg/test" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const testOtlpConfig = `--- | ||
log-level: debug | ||
pipeline: | ||
- name: encode1 | ||
parameters: | ||
- name: encode1 | ||
encode: | ||
type: otlp | ||
otlp: | ||
grpcaddress: localhost:4317 | ||
` | ||
|
||
type fakeOltpLoggerProvider struct { | ||
} | ||
type fakeOltpLogger struct { | ||
} | ||
|
||
var receivedData []logs.LogRecord | ||
|
||
func (f *fakeOltpLogger) Emit(msg logs.LogRecord) { | ||
receivedData = append(receivedData, msg) | ||
} | ||
|
||
func (f *fakeOltpLoggerProvider) Logger(name string, options ...logs.LoggerOption) logs.Logger { | ||
return &fakeOltpLogger{} | ||
} | ||
|
||
func initNewEncodeOltp(t *testing.T) encode.Encoder { | ||
receivedData = []logs.LogRecord{} | ||
v, cfg := test.InitConfig(t, testOtlpConfig) | ||
require.NotNil(t, v) | ||
|
||
newEncode, err := NewEncodeOtlpLogs(operational.NewMetrics(&config.MetricsSettings{}), cfg.Parameters[0]) | ||
require.NoError(t, err) | ||
|
||
// intercept the loggerProvider function | ||
loggerProvider := fakeOltpLoggerProvider{} | ||
otel.SetLoggerProvider(&loggerProvider) | ||
return newEncode | ||
} | ||
|
||
func Test_EncodeOtlp(t *testing.T) { | ||
newEncode := initNewEncodeOltp(t) | ||
encodeOtlp := newEncode.(*EncodeOtlpLogs) | ||
require.Equal(t, "localhost:4317", encodeOtlp.cfg.GrpcAddress) | ||
require.Nil(t, encodeOtlp.cfg.TLS) | ||
require.Empty(t, encodeOtlp.cfg.HttpAddress) | ||
require.Empty(t, encodeOtlp.cfg.Headers) | ||
|
||
entry1 := test.GetIngestMockEntry(true) | ||
entry2 := test.GetIngestMockEntry(false) | ||
newEncode.Encode(entry1) | ||
newEncode.Encode(entry2) | ||
// verify contents of the output | ||
require.Len(t, receivedData, 2) | ||
expected1, _ := json.Marshal(entry1) | ||
expected2, _ := json.Marshal(entry2) | ||
require.Equal(t, string(expected1), *receivedData[0].Body()) | ||
require.Equal(t, string(expected2), *receivedData[1].Body()) | ||
} | ||
|
||
func Test_TLSConfigEmpty(t *testing.T) { | ||
cfg := config.StageParam{Encode: &config.Encode{Otlp: &api.OtlpEncode{HttpAddress: "1.2.3.4:999", TLS: nil}}} | ||
newEncode, err := NewEncodeOtlpLogs(operational.NewMetrics(&config.MetricsSettings{}), cfg) | ||
require.NoError(t, err) | ||
require.NotNil(t, newEncode) | ||
} | ||
|
||
func Test_TLSConfigNotEmpty(t *testing.T) { | ||
cfg := config.StageParam{Encode: &config.Encode{Otlp: &api.OtlpEncode{HttpAddress: "1.2.3.4:999", TLS: &api.ClientTLS{InsecureSkipVerify: true}}}} | ||
newEncode, err := NewEncodeOtlpLogs(operational.NewMetrics(&config.MetricsSettings{}), cfg) | ||
require.NoError(t, err) | ||
require.NotNil(t, newEncode) | ||
} | ||
|
||
func Test_HeadersNotEmpty(t *testing.T) { | ||
headers := make(map[string]string) | ||
headers["key1"] = "value1" | ||
headers["key2"] = "value2" | ||
cfg := config.StageParam{Encode: &config.Encode{Otlp: &api.OtlpEncode{HttpAddress: "1.2.3.4:999", Headers: headers}}} | ||
newEncode, err := NewEncodeOtlpLogs(operational.NewMetrics(&config.MetricsSettings{}), cfg) | ||
require.NoError(t, err) | ||
require.NotNil(t, newEncode) | ||
} |
Oops, something went wrong.