-
Notifications
You must be signed in to change notification settings - Fork 450
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
Improve OpenTelemetry Collector JSON Marshalling #3286
Conversation
Signed-off-by: Israel Blancas <[email protected]>
Signed-off-by: Israel Blancas <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what is actually going on in this PR. From the tests, it seems like everything works correctly, but I don't know why. I've left some comments asking questions, but in general I think you should exhaustively explain the weird marshaling functions in docstrings.
Signed-off-by: Israel Blancas <[email protected]>
I tried to explain it in the changelog:
The problem happens when you want to create one OpenTelemetry Collector instance like this one: apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel
spec:
config:
receivers:
otlp:
http:
grpc: Then, you create it in the cluster with, for instance, kubectl apply -f otelcol.yaml When you get the OpenTelemetry Collector instance, you will get this: $ kubectl get otelcol -o yaml otel
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel
spec:
config:
receivers:
otlp: We have a warning mentioning this can happen, but it can be difficult for users to see. I'll add more info to the changelog.
I just added some comments to the source code. |
Signed-off-by: Israel Blancas <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still not entirely sure how or why this works... maybe we can talk about it in slack?
// This allows you to embed the struct safely within itself without triggering that infinite loop. | ||
type Alias Config | ||
// Ensure we call the custom marshaller for AnyConfig for the Receivers | ||
receiversJSON, err := json.Marshal(c.Receivers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we only need to do this for receivers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iblancasa bump on this
Signed-off-by: Israel Blancas <[email protected]>
Just messaged you. |
The E2E tests are failing because there was a problem while downloading a dependency or something. |
@jaronoff97 @swiatekm do you have any other questions or concerns regarding this PR? |
// This allows you to embed the struct safely within itself without triggering that infinite loop. | ||
type Alias Config | ||
// Ensure we call the custom marshaller for AnyConfig for the Receivers | ||
receiversJSON, err := json.Marshal(c.Receivers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iblancasa bump on this
testScheme := scheme.Scheme | ||
err := AddToScheme(testScheme) | ||
require.NoError(t, err) | ||
|
||
testEnv := &envtest.Environment{ | ||
CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, | ||
} | ||
|
||
cfg, err := testEnv.Start() | ||
require.NoError(t, err) | ||
defer func() { | ||
errStop := testEnv.Stop() | ||
require.NoError(t, errStop) | ||
}() | ||
|
||
k8sClient, err := client.New(cfg, client.Options{Scheme: testScheme}) | ||
if err != nil { | ||
fmt.Printf("failed to setup a Kubernetes client: %v", err) | ||
os.Exit(1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ive found this fake client package a lot more usable
name: stateful-collector-85dbe673 | ||
name: stateful-collector-57be076a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OOC why are the hashes changing? id be interested to understand how the full content is being changed.
Closing this PR because the changes introduced in #3333 workaround the problem. Since it seems it was a problem for so many people to follow what's going on this PR, I'll add an explanation here just as a reference. The issueAfter creating an apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel
spec:
config:
receivers:
otlp:
protocols:
http:
grpc: If you get the kubectl get otelcol -o yaml otel this is what you get: apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel
spec:
config:
receivers:
otlp:
protocols: The values for This is not supported by other tools like The operator shows a warning in this situation. The fixThe fix is based on this blog article. I was implementing the I added a unit test to ensure this situation, which seems to be reproducible only when the object is created + retrieved in Kubernetes, didn't reproduce again. The unexpected workaroundWith #3333, all those keys that would not have any value, have now a value by default. So, the issue is there but users will not suffer it anymore. |
@iblancasa I think I finally understand, thanks for being so patient with us! Could we actually keep the tests you've written, and skip them for the time being? We've been talking about alternative solutions to this issue, and the tests would be very helpful as benchmarks. I'd also hate for your hard work to go to waste this way. |
Fixes #3281