Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.polaris.persistence.relational.jdbc.models;

import jakarta.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -51,6 +52,7 @@ public interface ModelEvent extends Converter<PolarisEvent> {
String getEventId();

// id of the request that generated this event
@Nullable
String getRequestId();

// event type that was created
Expand All @@ -60,6 +62,7 @@ public interface ModelEvent extends Converter<PolarisEvent> {
long getTimestampMs();

// polaris principal who took this action
@Nullable
String getPrincipalName();

// Enum that states the type of resource was being operated on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ CREATE TABLE IF NOT EXISTS events (
realm_id TEXT NOT NULL,
catalog_id TEXT NOT NULL,
event_id TEXT NOT NULL,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side note: assuming event_id values are unique, this table can grow definitely, I guess... Do we have a mechanism to cap its size?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does capping size means not persisting the events when the number of records > threshold or failing unless its fixed, my understanding is failing unless we fix it (like removing last x months events in a cold store type of things and then for users we can make a view which does union from both the stores ?) would be a better way to go if we try to put a cap as we want to repurpose this for audit POV

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the listener to handle capping the size -- or some other maintenance service responsible for pruning this table.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My primary concern is about naive users who deploy pre-built binaries and start accumulating data in this table 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created an issue to track this: #2573

request_id TEXT NOT NULL,
request_id TEXT,
event_type TEXT NOT NULL,
timestamp_ms BIGINT NOT NULL,
principal_name TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ CREATE TABLE IF NOT EXISTS events (
realm_id TEXT NOT NULL,
catalog_id TEXT NOT NULL,
event_id TEXT NOT NULL,
request_id TEXT NOT NULL,
request_id TEXT,
event_type TEXT NOT NULL,
timestamp_ms BIGINT NOT NULL,
principal_name TEXT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.annotation.Nullable;
import java.util.Map;

public class PolarisEvent {
Expand All @@ -32,28 +33,28 @@ public class PolarisEvent {
private static final ObjectMapper MAPPER = new ObjectMapper();

// catalog id
private String catalogId;
private final String catalogId;

// event id
private String id;
private final String id;

// id of the request that generated this event
private String requestId;
// id of the request that generated this event, if any
@Nullable private final String requestId;

// event type that was fired
private String eventType;
private final String eventType;

// timestamp in epoch milliseconds of when this event was emitted
private long timestampMs;
private final long timestampMs;

// polaris principal who took this action
private String principalName;
// polaris principal who took this action, or null if unknown
@Nullable private final String principalName;

// Enum that states the type of resource was being operated on
private ResourceType resourceType;
private final ResourceType resourceType;

// Which resource was operated on
private String resourceIdentifier;
private final String resourceIdentifier;

// Additional parameters that were not earlier recorded
private String additionalProperties;
Expand All @@ -66,6 +67,7 @@ public String getId() {
return id;
}

@Nullable
public String getRequestId() {
return requestId;
}
Expand All @@ -78,6 +80,7 @@ public long getTimestampMs() {
return timestampMs;
}

@Nullable
public String getPrincipalName() {
return principalName;
}
Expand All @@ -97,18 +100,18 @@ public String getAdditionalProperties() {
public PolarisEvent(
String catalogId,
String id,
String requestId,
@Nullable String requestId,
String eventType,
long timestampMs,
String actor,
@Nullable String principalName,
ResourceType resourceType,
String resourceIdentifier) {
this.catalogId = catalogId;
this.id = id;
this.requestId = requestId;
this.eventType = eventType;
this.timestampMs = timestampMs;
this.principalName = actor;
this.principalName = principalName;
this.resourceType = resourceType;
this.resourceIdentifier = resourceIdentifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.common.annotations.VisibleForTesting;
import io.smallrye.common.annotation.Identifier;
import jakarta.annotation.Nullable;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.ApplicationScoped;
Expand Down Expand Up @@ -124,6 +125,7 @@ void shutdown() {
}
}

@Nullable
@Override
String getRequestId() {
if (containerRequestContext != null && containerRequestContext.hasProperty(REQUEST_ID_KEY)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.apache.polaris.service.events.listeners;

import jakarta.annotation.Nullable;
import java.util.Map;
import org.apache.iceberg.TableMetadataParser;
import org.apache.polaris.core.entity.PolarisEvent;
Expand Down Expand Up @@ -111,10 +112,11 @@ public void onAfterCatalogCreated(AfterCatalogCreatedEvent event) {
processEvent(polarisEvent);
}

protected record ContextSpecificInformation(long timestamp, String principalName) {}
protected record ContextSpecificInformation(long timestamp, @Nullable String principalName) {}

abstract ContextSpecificInformation getContextSpecificInformation();

@Nullable
abstract String getRequestId();

abstract void processEvent(PolarisEvent event);
Expand Down