Skip to content

Commit 03fd4de

Browse files
David O'SullivanZPascal
authored andcommitted
logcache fix
1 parent 9183dfc commit 03fd4de

File tree

6 files changed

+64
-39
lines changed

6 files changed

+64
-39
lines changed

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/_DefaultCloudFoundryOperations.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.cloudfoundry.client.v3.spaces.ListSpacesRequest;
2424
import org.cloudfoundry.client.v3.spaces.SpaceResource;
2525
import org.cloudfoundry.doppler.DopplerClient;
26+
import org.cloudfoundry.logcache.v1.LogCacheClient;
2627
import org.cloudfoundry.networking.NetworkingClient;
2728
import org.cloudfoundry.operations.advanced.Advanced;
2829
import org.cloudfoundry.operations.advanced.DefaultAdvanced;
@@ -79,7 +80,7 @@ public Advanced advanced() {
7980
@Override
8081
@Value.Derived
8182
public Applications applications() {
82-
return new DefaultApplications(getCloudFoundryClientPublisher(), getDopplerClientPublisher(), getSpaceId());
83+
return new DefaultApplications(getCloudFoundryClientPublisher(), getDopplerClientPublisher(), getLogCacheClientPublisher(), getSpaceId());
8384
}
8485

8586
@Override
@@ -178,13 +179,26 @@ Mono<CloudFoundryClient> getCloudFoundryClientPublisher() {
178179
@Nullable
179180
abstract DopplerClient getDopplerClient();
180181

182+
/**
183+
* The {@link LogCacheClient} to use for operations functionality
184+
*/
185+
@Nullable
186+
abstract LogCacheClient getLogCacheClient();
187+
181188
@Value.Derived
182189
Mono<DopplerClient> getDopplerClientPublisher() {
183190
return Optional.ofNullable(getDopplerClient())
184191
.map(Mono::just)
185192
.orElse(Mono.error(new IllegalStateException("DopplerClient must be set")));
186193
}
187194

195+
@Value.Derived
196+
Mono<LogCacheClient> getLogCacheClientPublisher() {
197+
return Optional.ofNullable(getLogCacheClient())
198+
.map(Mono::just)
199+
.orElse(Mono.error(new IllegalStateException("LogCacheClient must be set")));
200+
}
201+
188202
/**
189203
* The {@link NetworkingClient} to use for operations functionality
190204
*/

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/Applications.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
package org.cloudfoundry.operations.applications;
1818

1919
import org.cloudfoundry.doppler.LogMessage;
20+
import org.cloudfoundry.logcache.v1.Log;
21+
2022
import reactor.core.publisher.Flux;
2123
import reactor.core.publisher.Mono;
2224

@@ -120,7 +122,7 @@ public interface Applications {
120122
* @param request the application logs request
121123
* @return the applications logs
122124
*/
123-
Flux<LogMessage> logs(LogsRequest request);
125+
Flux<Log> logs(LogsRequest request);
124126

125127
/**
126128
* Push a specific application

cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/applications/DefaultApplications.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
import org.cloudfoundry.doppler.RecentLogsRequest;
157157
import org.cloudfoundry.doppler.StreamRequest;
158158
import org.cloudfoundry.logcache.v1.EnvelopeType;
159+
import org.cloudfoundry.logcache.v1.Log;
159160
import org.cloudfoundry.logcache.v1.LogCacheClient;
160161
import org.cloudfoundry.logcache.v1.ReadRequest;
161162
import org.cloudfoundry.operations.util.OperationsLogging;
@@ -219,29 +220,34 @@ public final class DefaultApplications implements Applications {
219220

220221
private final Mono<DopplerClient> dopplerClient;
221222

223+
private final Mono<LogCacheClient> logCacheClient;
224+
222225
private final RandomWords randomWords;
223226

224227
private final Mono<String> spaceId;
225228

226229
public DefaultApplications(
227230
Mono<CloudFoundryClient> cloudFoundryClient,
228231
Mono<DopplerClient> dopplerClient,
232+
Mono<LogCacheClient> logCacheClient,
229233
Mono<String> spaceId) {
230-
this(cloudFoundryClient, dopplerClient, new WordListRandomWords(), spaceId);
234+
this(cloudFoundryClient, dopplerClient, logCacheClient, new WordListRandomWords(), spaceId);
231235
}
232236

233237
DefaultApplications(
234238
Mono<CloudFoundryClient> cloudFoundryClient,
235239
Mono<DopplerClient> dopplerClient,
240+
Mono<LogCacheClient> logCacheClient,
236241
RandomWords randomWords,
237242
Mono<String> spaceId) {
238243
this.cloudFoundryClient = cloudFoundryClient;
239244
this.dopplerClient = dopplerClient;
245+
this.logCacheClient = logCacheClient;
240246
this.randomWords = randomWords;
241247
this.spaceId = spaceId;
242248
}
243249

244-
@Override
250+
@Override
245251
public Mono<Void> copySource(CopySourceApplicationRequest request) {
246252
return Mono.zip(this.cloudFoundryClient, this.spaceId)
247253
.flatMap(
@@ -535,7 +541,7 @@ public Flux<Task> listTasks(ListApplicationTasksRequest request) {
535541
}
536542

537543
@Override
538-
public Flux<LogMessage> logs(LogsRequest request) {
544+
public Flux<Log> logs(LogsRequest request) {
539545
return Mono.zip(this.cloudFoundryClient, this.spaceId)
540546
.flatMap(
541547
function(
@@ -544,7 +550,7 @@ public Flux<LogMessage> logs(LogsRequest request) {
544550
cloudFoundryClient, request.getName(), spaceId)))
545551
.flatMapMany(
546552
applicationId ->
547-
getLogs(this.dopplerClient, applicationId, request.getRecent()))
553+
getRecentLogs(this.logCacheClient, applicationId))
548554
.transform(OperationsLogging.log("Get Application Logs"))
549555
.checkpoint();
550556
}
@@ -1576,30 +1582,29 @@ private static int getInstances(AbstractApplicationResource resource) {
15761582
.orElse(0);
15771583
}
15781584

1579-
private static Flux<LogMessage> getLogs(
1580-
Mono<DopplerClient> dopplerClient, String applicationId, Boolean recent) {
1585+
/* private static Flux<Log> getLogs(
1586+
Mono<LogCacheClient> logCacheClient, String applicationId, Boolean recent) {
15811587
if (Optional.ofNullable(recent).orElse(false)) {
1582-
return requestLogsRecent(dopplerClient, applicationId)
1583-
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1584-
.map(Envelope::getLogMessage)
1585-
.collectSortedList(LOG_MESSAGE_COMPARATOR)
1586-
.flatMapIterable(d -> d);
1587-
} else {
1588-
return requestLogsStream(dopplerClient, applicationId)
1589-
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1590-
.map(Envelope::getLogMessage)
1591-
.transformDeferred(
1592-
SortingUtils.timespan(LOG_MESSAGE_COMPARATOR, LOG_MESSAGE_TIMESPAN));
1588+
return getRecentLogs(logCacheClient, applicationId);
15931589
}
1590+
}*/
1591+
1592+
private static Flux<Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
1593+
return requestLogsRecentLogCache(logCacheClient, applicationId)
1594+
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1595+
// .collectSortedList(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1596+
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1597+
.map(org.cloudfoundry.logcache.v1.Envelope::getLog);
15941598
}
15951599

1596-
private static Flux<LogMessage> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
1600+
/* private static Flux<org.cloudfoundry.logcache.v1.Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
15971601
return requestLogsRecentLogCache(logCacheClient, applicationId)
15981602
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1603+
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
15991604
.map(org.cloudfoundry.logcache.v1.Envelope::getLog)
1600-
.collectSortedList(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1601-
.flatMapIterable(d -> d);
1602-
}
1605+
.collectList()
1606+
.flatMapIterable(d1 -> d1).cast(org.cloudfoundry.logcache.v1.Log.class);
1607+
} */
16031608

16041609
@SuppressWarnings("unchecked")
16051610
private static Map<String, Object> getMetadataRequest(EventEntity entity) {

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/AbstractOperationsTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.cloudfoundry.client.v3.spaces.SpacesV3;
5252
import org.cloudfoundry.client.v3.tasks.Tasks;
5353
import org.cloudfoundry.doppler.DopplerClient;
54+
import org.cloudfoundry.logcache.v1.LogCacheClient;
5455
import org.cloudfoundry.routing.RoutingClient;
5556
import org.cloudfoundry.routing.v1.routergroups.RouterGroups;
5657
import org.cloudfoundry.uaa.UaaClient;
@@ -101,6 +102,8 @@ public abstract class AbstractOperationsTest {
101102

102103
protected final DopplerClient dopplerClient = mock(DopplerClient.class, RETURNS_SMART_NULLS);
103104

105+
protected final LogCacheClient logCacheClient = mock(LogCacheClient.class, RETURNS_SMART_NULLS);
106+
104107
protected final Events events = mock(Events.class, RETURNS_SMART_NULLS);
105108

106109
protected final FeatureFlags featureFlags = mock(FeatureFlags.class, RETURNS_SMART_NULLS);

cloudfoundry-operations/src/test/java/org/cloudfoundry/operations/applications/DefaultApplicationsTest.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144
import org.cloudfoundry.doppler.LogMessage;
145145
import org.cloudfoundry.doppler.RecentLogsRequest;
146146
import org.cloudfoundry.doppler.StreamRequest;
147+
import org.cloudfoundry.logcache.v1.Log;
148+
import org.cloudfoundry.logcache.v1.LogCacheClient;
149+
import org.cloudfoundry.logcache.v1.ReadRequest;
150+
import org.cloudfoundry.logcache.v1.ReadResponse;
147151
import org.cloudfoundry.operations.AbstractOperationsTest;
148152
import org.cloudfoundry.util.DateUtils;
149153
import org.cloudfoundry.util.FluentMap;
@@ -163,6 +167,7 @@ final class DefaultApplicationsTest extends AbstractOperationsTest {
163167
new DefaultApplications(
164168
Mono.just(this.cloudFoundryClient),
165169
Mono.just(this.dopplerClient),
170+
Mono.just(this.logCacheClient),
166171
this.randomWords,
167172
Mono.just(TEST_SPACE_ID));
168173

@@ -1318,7 +1323,7 @@ void logs() {
13181323
this.applications
13191324
.logs(LogsRequest.builder().name("test-application-name").recent(false).build())
13201325
.as(StepVerifier::create)
1321-
.expectNext(fill(LogMessage.builder(), "log-message-").build())
1326+
.expectNext(fill(Log.builder(), "log-message-").build())
13221327
.expectComplete()
13231328
.verify(Duration.ofSeconds(5));
13241329
}
@@ -1346,12 +1351,12 @@ void logsRecent() {
13461351
"test-application-name",
13471352
TEST_SPACE_ID,
13481353
"test-metadata-id");
1349-
requestLogsRecent(this.dopplerClient, "test-metadata-id");
1354+
requestLogsRecentLogCache(this.logCacheClient, "test-metadata-id");
13501355

13511356
this.applications
13521357
.logs(LogsRequest.builder().name("test-application-name").recent(true).build())
13531358
.as(StepVerifier::create)
1354-
.expectNext(fill(LogMessage.builder(), "log-message-").build())
1359+
.expectNext(fill(Log.builder(), "log-message-").build())
13551360
.expectComplete()
13561361
.verify(Duration.ofSeconds(5));
13571362
}
@@ -1368,7 +1373,7 @@ void logsRecentNotSet() {
13681373
this.applications
13691374
.logs(LogsRequest.builder().name("test-application-name").build())
13701375
.as(StepVerifier::create)
1371-
.expectNext(fill(LogMessage.builder(), "log-message-").build())
1376+
.expectNext(fill(Log.builder(), "log-message-").build())
13721377
.expectComplete()
13731378
.verify(Duration.ofSeconds(5));
13741379
}
@@ -5248,17 +5253,11 @@ private static void requestListTasksEmpty(
52485253
.build()));
52495254
}
52505255

5251-
private static void requestLogsRecent(DopplerClient dopplerClient, String applicationId) {
5252-
when(dopplerClient.recentLogs(
5253-
RecentLogsRequest.builder().applicationId(applicationId).build()))
5256+
private static void requestLogsRecentLogCache(LogCacheClient logCacheClient, String applicationId) {
5257+
when(logCacheClient.recentLogs(
5258+
ReadRequest.builder().sourceId(applicationId).build()))
52545259
.thenReturn(
5255-
Flux.just(
5256-
Envelope.builder()
5257-
.eventType(EventType.LOG_MESSAGE)
5258-
.logMessage(
5259-
fill(LogMessage.builder(), "log-message-").build())
5260-
.origin("rsp")
5261-
.build()));
5260+
Mono.just(ReadResponse.builder().envelopes(fill(org.cloudfoundry.logcache.v1.EnvelopeBatch.builder()).build()).build()));
52625261
}
52635262

52645263
private static void requestLogsStream(DopplerClient dopplerClient, String applicationId) {

integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
import org.cloudfoundry.AbstractIntegrationTest;
2929
import org.cloudfoundry.CloudFoundryVersion;
3030
import org.cloudfoundry.IfCloudFoundryVersion;
31+
import org.cloudfoundry.doppler.Envelope;
3132
import org.cloudfoundry.doppler.LogMessage;
3233
import org.cloudfoundry.doppler.MessageType;
34+
import org.cloudfoundry.logcache.v1.LogType;
3335
import org.cloudfoundry.operations.applications.ApplicationDetail;
3436
import org.cloudfoundry.operations.applications.ApplicationEnvironments;
3537
import org.cloudfoundry.operations.applications.ApplicationEvent;
@@ -503,10 +505,10 @@ public void logs() throws IOException {
503505
.name(applicationName)
504506
.recent(true)
505507
.build()))
506-
.map(LogMessage::getMessageType)
508+
.map(org.cloudfoundry.logcache.v1.Log::getType)
507509
.next()
508510
.as(StepVerifier::create)
509-
.expectNext(MessageType.OUT)
511+
.expectNext(org.cloudfoundry.logcache.v1.LogType.OUT)
510512
.expectComplete()
511513
.verify(Duration.ofMinutes(5));
512514
}

0 commit comments

Comments
 (0)