-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bumped OpenTelemetry Collector to v0.16.0
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
- Loading branch information
1 parent
f0ea1b8
commit 32f47b1
Showing
5 changed files
with
119 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,61 @@ | ||
package parser | ||
|
||
import "github.com/go-logr/logr" | ||
import ( | ||
"fmt" | ||
|
||
const parserNameOTLP = "__otlp" | ||
"github.com/go-logr/logr" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
var _ ReceiverParser = &OTLPReceiverParser{} | ||
|
||
const ( | ||
parserNameOTLP = "__otlp" | ||
|
||
defaultOTLPLegacyPort int32 = 55680 | ||
defaultOTLPGRPCPort int32 = 4317 | ||
) | ||
|
||
// OTLPReceiverParser parses the configuration for OTLP receivers | ||
type OTLPReceiverParser struct { | ||
logger logr.Logger | ||
name string | ||
config map[interface{}]interface{} | ||
} | ||
|
||
// NewOTLPReceiverParser builds a new parser for OTLP receivers | ||
func NewOTLPReceiverParser(logger logr.Logger, name string, config map[interface{}]interface{}) ReceiverParser { | ||
return &GenericReceiver{ | ||
logger: logger, | ||
name: name, | ||
config: config, | ||
defaultPort: 55680, | ||
parserName: parserNameOTLP, | ||
return &OTLPReceiverParser{ | ||
logger: logger, | ||
name: name, | ||
config: config, | ||
} | ||
} | ||
|
||
// Ports returns all the service ports for all protocols in this parser | ||
func (o *OTLPReceiverParser) Ports() ([]corev1.ServicePort, error) { | ||
port := singlePortFromConfigEndpoint(o.logger, o.name, o.config) | ||
if port != nil { | ||
return []corev1.ServicePort{*port}, nil | ||
} | ||
|
||
return []corev1.ServicePort{ | ||
{ | ||
Port: defaultOTLPGRPCPort, | ||
Name: portName(o.name, defaultGRPCPort), | ||
}, | ||
{ | ||
Port: defaultOTLPLegacyPort, | ||
Name: portName(fmt.Sprintf("%s-legacy", o.name), defaultOTLPLegacyPort), | ||
}, | ||
}, nil | ||
} | ||
|
||
// ParserName returns the name of this parser | ||
func (o *OTLPReceiverParser) ParserName() string { | ||
return parserNameOTLP | ||
} | ||
|
||
func init() { | ||
Register("otlp", NewOTLPReceiverParser) | ||
} |
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 |
---|---|---|
@@ -1,3 +1,65 @@ | ||
package parser | ||
|
||
// all tests for the OTLP parser are currently part of the test TestDownstreamParsers | ||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOTLPSelfRegisters(t *testing.T) { | ||
// verify | ||
assert.True(t, IsRegistered("otlp")) | ||
} | ||
|
||
func TestOTLPIsFoundByName(t *testing.T) { | ||
// test | ||
p := For(logger, "otlp", map[interface{}]interface{}{}) | ||
|
||
// verify | ||
assert.Equal(t, "__otlp", p.ParserName()) | ||
} | ||
|
||
func TestOTLPPortsOverridden(t *testing.T) { | ||
// prepare | ||
builder := NewOTLPReceiverParser(logger, "otlp", map[interface{}]interface{}{ | ||
"endpoint": "0.0.0.0:1234", | ||
}) | ||
|
||
// test | ||
ports, err := builder.Ports() | ||
|
||
// verify | ||
assert.NoError(t, err) | ||
assert.Len(t, ports, 1) | ||
assert.EqualValues(t, 1234, ports[0].Port) | ||
} | ||
|
||
func TestOTLPExposeDefaultPorts(t *testing.T) { | ||
// prepare | ||
builder := NewOTLPReceiverParser(logger, "otlp", map[interface{}]interface{}{}) | ||
|
||
expectedResults := map[string]struct { | ||
portNumber int32 | ||
seen bool | ||
}{ | ||
"otlp": {portNumber: 4317}, | ||
"otlp-legacy": {portNumber: 55680}, | ||
} | ||
|
||
// test | ||
ports, err := builder.Ports() | ||
|
||
// verify | ||
assert.NoError(t, err) | ||
assert.Len(t, ports, 2) | ||
|
||
for _, port := range ports { | ||
r := expectedResults[port.Name] | ||
r.seen = true | ||
expectedResults[port.Name] = r | ||
assert.EqualValues(t, r.portNumber, port.Port) | ||
} | ||
for k, v := range expectedResults { | ||
assert.True(t, v.seen, "the port %s wasn't included in the service ports", k) | ||
} | ||
} |
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