Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Urisman authored and Igor Urisman committed Oct 4, 2023
1 parent a6485d1 commit a0a1274
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 26 deletions.
2 changes: 1 addition & 1 deletion bin/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Build server extension API standard library.
#

version=1.0.0
version=1.0.1
root_dir=$(cd $(dirname $0)/..; pwd)

cd $root_dir
Expand Down
Binary file removed lib/variant-server-spi-1.0.0.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<variant.version>1.0.0</variant.version>
<variant.version>1.0.1</variant.version>

</properties>

Expand All @@ -33,7 +33,7 @@
<artifactId>variant-spi</artifactId>
<version>${variant.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/variant-server-spi-${variant.version}.jar</systemPath>
<systemPath>${project.basedir}/lib/variant-spi-${variant.version}.jar</systemPath>
</dependency>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import org.yaml.snakeyaml.Yaml;
import com.variant.share.schema.Variation.Experience;
import com.variant.server.api.FlushableTraceEvent;
import com.variant.server.api.TraceEventFlusher;
import com.variant.server.spi.FlushableTraceEvent;
import com.variant.server.spi.TraceEventFlusher;

/**
* An implementation of {@link TraceEventFlusher}, which writes trace events to a local CSV file.
Expand Down Expand Up @@ -50,7 +50,7 @@ public TraceEventFlusherCsv(String init) throws Exception {
.orElse(Map.of());
out = Files.newBufferedWriter(Paths.get(parseFileName(map)), CREATE, WRITE, TRUNCATE_EXISTING );
if (parseHeader(map)) {
writeLine("event_id", "event_name", "created_on", "session_id", "attributes", "variation", "experience", "is_control");
writeLine("event_id", "event_name", "created_on", "session_id", "owner", "attributes", "variation", "experience", "is_control");
out.flush();
}
}
Expand Down Expand Up @@ -79,6 +79,7 @@ public void flush(FlushableTraceEvent[] events, int size) throws Exception {
event.getName(),
DateTimeFormatter.ISO_INSTANT.format(event.getTimestamp()),
event.getSessionId(),
event.getSessionOwner().orElse(""),
attrs,
e.getVariation().getName(),
e.getName(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.variant.spi.stdlib.flush;

import com.variant.server.api.FlushableTraceEvent;
import com.variant.server.api.TraceEventFlusher;
import com.variant.server.spi.FlushableTraceEvent;
import com.variant.server.spi.TraceEventFlusher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.variant.spi.stdlib.flush;

import com.variant.server.api.FlushableTraceEvent;
import com.variant.server.api.TraceEventFlusher;
import com.variant.server.spi.FlushableTraceEvent;
import com.variant.server.spi.TraceEventFlusher;
import com.variant.share.schema.Variation.Experience;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import com.typesafe.config.Config;
import com.typesafe.config.ConfigFactory;
import com.variant.server.api.ServerException;
import com.variant.server.spi.ServerException;
import com.variant.share.schema.Variation.Experience;
import com.variant.server.api.FlushableTraceEvent;
import com.variant.server.api.TraceEventFlusher;
import com.variant.server.spi.FlushableTraceEvent;
import com.variant.server.spi.TraceEventFlusher;


/**
Expand Down Expand Up @@ -82,7 +82,7 @@ final public void flush(FlushableTraceEvent[] events, int size) throws Exception
final String INSERT_EVENT_EXPERIENCES_SQL =
"INSERT INTO event_experiences (event_id, variation_name, experience_name, is_control) VALUES (?, ?, ?, ?)";

final String INSERT_EVENT_PARAMETERS_SQL =
final String INSERT_EVENT_ATTRIBUTES_SQL =
"INSERT INTO event_attributes (event_id, name, value) VALUES (?, ?, ?)";

JdbcAdapter.executeUpdate(
Expand All @@ -93,40 +93,34 @@ final public void flush(FlushableTraceEvent[] events, int size) throws Exception
public void execute(Connection conn) throws SQLException {

//
// 1. Insert into EVENTS and get the sequence generated IDs back.
// 1. Insert into EVENTS.
//

PreparedStatement stmt = conn.prepareStatement(INSERT_EVENTS_SQL, Statement.RETURN_GENERATED_KEYS);

for (int i = 0; i < size; i++) {
FlushableTraceEvent event = events[i];
stmt.setString(1, event.getId());
stmt.setString(2, event.getSessionId());
stmt.setTimestamp(3, Timestamp.from(event.getTimestamp()));
stmt.setString(4, event.getName());

stmt.addBatch();
}

// Send rows to the database.
stmt.executeBatch();
stmt.close();
conn.commit();

//
// 2. Insert into EVENT_PARAMETERS.
// 2. Insert into EVENT_ATTRIBUTES.
//
stmt = conn.prepareStatement(INSERT_EVENT_PARAMETERS_SQL);
stmt = conn.prepareStatement(INSERT_EVENT_ATTRIBUTES_SQL);
for (int i = 0; i < size; i++) {
FlushableTraceEvent event = events[i];
for (Map.Entry<String, String> param: event.getAttributes().entrySet()) {
stmt.setString(1, event.getId());
stmt.setString(2, param.getKey());
stmt.setString(3, param.getValue().toString());

stmt.setString(3, param.getValue());
stmt.addBatch();
}
}

stmt.executeBatch();
stmt.close();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.variant.spi.stdlib.flush.jdbc;

import com.variant.server.api.TraceEventFlusher;
import com.variant.server.spi.TraceEventFlusher;

/**
* An implementation of {@link TraceEventFlusher}, which writes trace events to an
Expand Down

0 comments on commit a0a1274

Please sign in to comment.