-
Notifications
You must be signed in to change notification settings - Fork 326
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
PoC: Telemetry for Data.read
#12385
Open
Akirathan
wants to merge
17
commits into
develop
Choose a base branch
from
wip/akirathan/12090-telemetry
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+413
−131
Open
PoC: Telemetry for Data.read
#12385
Changes from 7 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
58bbd85
Generalize enso_cloud log API access
Akirathan 5e98e7b
No point in making uri abstract.
Akirathan 0e2f2e7
Move most functionality from AuditLogMessage to the base class
Akirathan e150c32
Introduce TelemetryLog
Akirathan 296b926
Add Telemetry_Log_Spec test
Akirathan d485a52
Handle null EnsoProject
Akirathan 0d7ce6b
Add some telemetry to Data.read
Akirathan 5300f35
Remove IO.println from Logging
Akirathan 51db71e
[WIP] Add more logging
Akirathan c540239
Revert "[WIP] Add more logging"
Akirathan 6ecdd77
LogMessage may have extraM<eta and extraPayload
Akirathan 0f3b719
Merge branch 'develop' into wip/akirathan/12090-telemetry
Akirathan 963f088
Move Telemetry to private module
Akirathan 19212cf
Move Telemetry_Log_Spec to Base_Internal_Tests
Akirathan 039b279
Make classes package-private
Akirathan 1874832
Mock PostLogHandler treats projectId as optional field
Akirathan 965443f
Update project name in Telemetry_Log_Spec
Akirathan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
74 changes: 11 additions & 63 deletions
74
std-bits/base/src/main/java/org/enso/base/enso_cloud/audit/AuditLogMessage.java
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,81 +1,29 @@ | ||
package org.enso.base.enso_cloud.audit; | ||
|
||
import com.fasterxml.jackson.databind.node.JsonNodeFactory; | ||
import com.fasterxml.jackson.databind.node.NullNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.fasterxml.jackson.databind.node.TextNode; | ||
import java.util.Objects; | ||
import org.enso.base.CurrentEnsoProject; | ||
import org.enso.base.enso_cloud.CloudAPI; | ||
import org.enso.base.enso_cloud.logging.LogMessage; | ||
|
||
class AuditLogMessage implements AuditLogApiAccess.LogMessage { | ||
|
||
/** | ||
* A reserved field that is currently added by the cloud backend. Duplicating it will lead to | ||
* internal server errors and log messages being discarded. | ||
*/ | ||
private static final String RESERVED_TYPE = "type"; | ||
final class AuditLogMessage extends LogMessage { | ||
|
||
private static final String OPERATION = "operation"; | ||
private static final String PROJECT_NAME = "projectName"; | ||
private static final String PROJECT_ID = "projectId"; | ||
private static final String PROJECT_SESSION_ID = "projectSessionId"; | ||
private static final String LOCAL_TIMESTAMP = "localTimestamp"; | ||
|
||
private final String projectId; | ||
private final String projectName; | ||
private final String operation; | ||
private final String message; | ||
private final ObjectNode metadata; | ||
|
||
public AuditLogMessage(String operation, String message, ObjectNode metadata) { | ||
this.operation = Objects.requireNonNull(operation); | ||
this.message = Objects.requireNonNull(message); | ||
this.metadata = Objects.requireNonNull(metadata); | ||
checkNoRestrictedField(metadata, RESERVED_TYPE); | ||
checkNoRestrictedField(metadata, OPERATION); | ||
checkNoRestrictedField(metadata, PROJECT_NAME); | ||
checkNoRestrictedField(metadata, PROJECT_SESSION_ID); | ||
checkNoRestrictedField(metadata, LOCAL_TIMESTAMP); | ||
|
||
this.projectId = CloudAPI.getCloudProjectId(); | ||
|
||
var currentProject = CurrentEnsoProject.get(); | ||
this.projectName = currentProject == null ? null : currentProject.fullName(); | ||
private AuditLogMessage(String message, ObjectNode metadata) { | ||
super(message, metadata); | ||
} | ||
|
||
private static void checkNoRestrictedField(ObjectNode metadata, String fieldName) { | ||
if (metadata.has(fieldName)) { | ||
throw new IllegalArgumentException( | ||
"Metadata cannot contain a field named '" + fieldName + "'"); | ||
} | ||
} | ||
|
||
private ObjectNode computedMetadata() { | ||
public static AuditLogMessage create(String operation, String message, ObjectNode metadata) { | ||
Objects.requireNonNull(operation); | ||
Objects.requireNonNull(message); | ||
Objects.requireNonNull(metadata); | ||
var copy = metadata.deepCopy(); | ||
copy.set(OPERATION, TextNode.valueOf(operation)); | ||
|
||
// The project name may be null if a script is run outside a project. | ||
if (projectName != null) { | ||
copy.set(PROJECT_NAME, TextNode.valueOf(projectName)); | ||
} | ||
|
||
String projectSessionId = CloudAPI.getCloudSessionId(); | ||
if (projectSessionId != null) { | ||
copy.set(PROJECT_SESSION_ID, TextNode.valueOf(projectSessionId)); | ||
} | ||
|
||
return copy; | ||
return new AuditLogMessage(message, copy); | ||
} | ||
|
||
@Override | ||
public String payload() { | ||
var payload = new ObjectNode(JsonNodeFactory.instance); | ||
payload.set("message", TextNode.valueOf(message)); | ||
payload.set( | ||
PROJECT_ID, projectId == null ? NullNode.getInstance() : TextNode.valueOf(projectId)); | ||
payload.set("metadata", computedMetadata()); | ||
payload.set("kind", TextNode.valueOf("Lib")); | ||
return payload.toString(); | ||
protected String kind() { | ||
return "Lib"; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Sending home the file path might reveal customer internals we are not interested in. File size and mime type should be generic enough, however.