-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: export policy condition types #58
Conversation
@nvvfedorov do you mind a look at this one or assigning it to someone who can help review? |
@sanjams2 , I have two requests:
|
Thanks @nvvfedorov Here is an example: ch, err := dcgm.ListenForPolicyViolations(ctx, dcgm.XidPolicy)
for notif := range ch {
xidCondition := notif.Data.(dcgm.XidPolicyCondition) // <-- This casting is not possible without this change
fmt.Printf("Received Xid violation with ErrNum: %d", xidCondition.ErrNum)
} Commit has also been signed. |
The current implementation does not allow insights into specific structures types that is because An alternative to above proposed approach is to define a new type for
And, each of the condition can implement
Now a caller now, need not re-cast types, e.g.:
Let me know if this alternative approach helps you achieve your goal as it does not require end user to know policy violation condition type or its internal structure. |
@rohit-arora-dev thanks for proposing an alternative. I dont quite see how it solves the original problem though. For example, how do I get the |
The
Do you have a use case where a direct access to the underlying struct attributes is required instead of getting them in string format? |
Yes. In particular, different Xid error codes can have different remediation actions (i.e. restart process, terminate host, etc.). But beyond that, the data within these structs is only useful to have in the first place if you can access it directly. |
Thanks for the context, if the purpose is more than logging Xid error and use that information to perform other actions then access to Struct as well as its attributes is required. |
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.
/LGTM
== Motivation == Allow package consumers to use typed PolicyViolation 'Data' field == Details == Currently, consumers of this library do not have access to the specific struct types that the 'Data' field of the PolicyViolation object can take on. This makes it near impossible (at least not without brittle reflection based techniques) to access inner fields of the struct in the 'Data' field. An example inner field is the 'ErrNum' field on an Xid PolicyViolation which is crucial for understanding the device health. This change attempts to solve this by exporting the different struct types that the data field can take on. This allows consumers to cast the data field to a type which they will be able to more safely handle in their code. == Testing == - built package Signed-off-by: sanjams <sanjams2@users.noreply.github.com>
signature was incorrect. Had to resign |
== Motivation ==
Allow package consumers to use typed PolicyViolation 'Data' field
== Details ==
Currently, consumers of this library do not have access to the specific struct types that the 'Data' field of the PolicyViolation object can take on. This makes it near impossible (at least not without brittle reflection based techniques) to access inner fields of the struct in the 'Data' field. An example inner field is the 'ErrNum' field on an Xid PolicyViolation which is crucial for understanding the device health.
This change attempts to solve this by exporting the different struct types that the data field can take on. This allows consumers to cast the data field to a type which they will be able to more safely handle in their code.
== Testing ==