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 @@ -580,13 +580,7 @@ public static SinkInfo of(String name, Destination destination) {

LogSink toPb(String projectId) {
LogSink.Builder builder =
LogSink.newBuilder()
.setName(name)
.setDestination(destination.toPb(projectId))
.setOutputVersionFormat(
versionFormat == null
? LogSink.VersionFormat.VERSION_FORMAT_UNSPECIFIED
: versionFormat.toPb());
LogSink.newBuilder().setName(name).setDestination(destination.toPb(projectId));
if (filter != null) {
builder.setFilter(filter);
}
Expand All @@ -596,7 +590,7 @@ LogSink toPb(String projectId) {
static SinkInfo fromPb(LogSink sinkPb) {
Builder builder =
newBuilder(sinkPb.getName(), Destination.fromPb(sinkPb.getDestination()))
.setVersionFormat(VersionFormat.fromPb(sinkPb.getOutputVersionFormat()));
.setVersionFormat(VersionFormat.fromPb(LogSink.VersionFormat.V2));
if (!sinkPb.getFilter().equals("")) {
builder.setFilter(sinkPb.getFilter());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.logging;

import static com.google.cloud.logging.SinkInfo.VersionFormat;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -84,7 +85,9 @@ public class LoggingImplTest {
private static final String PROJECT_PB = "projects/" + PROJECT;
private static final String SINK_NAME = "sink";
private static final SinkInfo SINK_INFO =
SinkInfo.of(SINK_NAME, Destination.BucketDestination.of("bucket"));
SinkInfo.newBuilder(SINK_NAME, Destination.BucketDestination.of("bucket"))
.setVersionFormat(VersionFormat.V2)
.build();
private static final String SINK_NAME_PB = "projects/" + PROJECT + "/sinks/" + SINK_NAME;
private static final String METRIC_NAME = "metric";
private static final String METRIC_NAME_PB = "projects/" + PROJECT + "/metrics/" + METRIC_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SinkInfoTest {
private static final String NAME = "name";
private static final String FILTER =
"logName=projects/my-projectid/logs/syslog AND severity>=ERROR";
private static final VersionFormat VERSION = VersionFormat.V1;
private static final VersionFormat VERSION = VersionFormat.V2;
private static final BucketDestination BUCKET_DESTINATION = BucketDestination.of("bucket");
private static final DatasetDestination DATASET_DESTINATION =
DatasetDestination.of("project", "dataset");
Expand Down Expand Up @@ -154,7 +154,7 @@ public void testToBuilder() {
.setDestination(BUCKET_DESTINATION)
.setName(NAME)
.setFilter(FILTER)
.setVersionFormat(VersionFormat.V1)
.setVersionFormat(VersionFormat.V2)
.build();
assertEquals(BUCKET_SINK_INFO, updatedSinkInfo);
}
Expand All @@ -164,22 +164,24 @@ public void testToAndFromPb() {
compareSinkInfo(BUCKET_SINK_INFO, SinkInfo.fromPb(BUCKET_SINK_INFO.toPb("project")));
compareSinkInfo(DATASET_SINK_INFO, SinkInfo.fromPb(DATASET_SINK_INFO.toPb("project")));
compareSinkInfo(TOPIC_SINK_INFO, SinkInfo.fromPb(TOPIC_SINK_INFO.toPb("project")));
SinkInfo sinkInfo = SinkInfo.of("name", BUCKET_DESTINATION);
SinkInfo sinkInfo =
SinkInfo.newBuilder(NAME, BUCKET_DESTINATION).setVersionFormat(VERSION).build();
compareSinkInfo(sinkInfo, SinkInfo.fromPb(sinkInfo.toPb("project")));
sinkInfo = SinkInfo.of("name", DATASET_DESTINATION);
sinkInfo = SinkInfo.newBuilder(NAME, DATASET_DESTINATION).setVersionFormat(VERSION).build();
compareSinkInfo(sinkInfo, SinkInfo.fromPb(sinkInfo.toPb("project")));
sinkInfo = SinkInfo.of("name", TOPIC_DESTINATION);
sinkInfo = SinkInfo.newBuilder(NAME, TOPIC_DESTINATION).setVersionFormat(VERSION).build();
compareSinkInfo(sinkInfo, SinkInfo.fromPb(sinkInfo.toPb("project")));
}

@Test
public void testToAndFromPb_NoProjectId() {
DatasetDestination datasetDestination = DatasetDestination.of("dataset");
SinkInfo sinkInfo = SinkInfo.of("name", DATASET_DESTINATION);
SinkInfo sinkInfo =
SinkInfo.newBuilder(NAME, DATASET_DESTINATION).setVersionFormat(VERSION).build();
compareSinkInfo(
sinkInfo, SinkInfo.fromPb(SinkInfo.of("name", datasetDestination).toPb("project")));
TopicDestination topicDestination = TopicDestination.of("topic");
sinkInfo = SinkInfo.of("name", TOPIC_DESTINATION);
sinkInfo = SinkInfo.newBuilder(NAME, TOPIC_DESTINATION).setVersionFormat(VERSION).build();
compareSinkInfo(
sinkInfo, SinkInfo.fromPb(SinkInfo.of("name", topicDestination).toPb("project")));
}
Expand Down