Skip to content

Commit 068668f

Browse files
David O'SullivanZPascal
authored andcommitted
logcache fix
1 parent 8731259 commit 068668f

File tree

6 files changed

+67
-177
lines changed

6 files changed

+67
-177
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
@@ -190,13 +191,26 @@ Mono<CloudFoundryClient> getCloudFoundryClientPublisher() {
190191
@Nullable
191192
abstract DopplerClient getDopplerClient();
192193

194+
/**
195+
* The {@link LogCacheClient} to use for operations functionality
196+
*/
197+
@Nullable
198+
abstract LogCacheClient getLogCacheClient();
199+
193200
@Value.Derived
194201
Mono<DopplerClient> getDopplerClientPublisher() {
195202
return Optional.ofNullable(getDopplerClient())
196203
.map(Mono::just)
197204
.orElse(Mono.error(new IllegalStateException("DopplerClient must be set")));
198205
}
199206

207+
@Value.Derived
208+
Mono<LogCacheClient> getLogCacheClientPublisher() {
209+
return Optional.ofNullable(getLogCacheClient())
210+
.map(Mono::just)
211+
.orElse(Mono.error(new IllegalStateException("LogCacheClient must be set")));
212+
}
213+
200214
/**
201215
* The {@link NetworkingClient} to use for operations functionality
202216
*/

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

Lines changed: 3 additions & 15 deletions
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

@@ -115,27 +117,13 @@ public interface Applications {
115117
Flux<Task> listTasks(ListApplicationTasksRequest request);
116118

117119
/**
118-
* List the applications logs. Uses Doppler under the hood.
119-
* Only works with {@code Loggregator < 107.0}, shipped in {@code CFD < 24.3}
120-
* and {@code TAS < 4.0}.
120+
* List the applications logs
121121
*
122122
* @param request the application logs request
123123
* @return the applications logs
124-
* @deprecated Use {@link #logs(ApplicationLogsRequest)} instead.
125124
*/
126-
@Deprecated
127125
Flux<LogMessage> logs(LogsRequest request);
128126

129-
/**
130-
* List the applications logs.
131-
* Only works with {@code Loggregator < 107.0}, shipped in {@code CFD < 24.3}
132-
* and {@code TAS < 4.0}.
133-
*
134-
* @param request the application logs request
135-
* @return the applications logs
136-
*/
137-
Flux<ApplicationLog> logs(ApplicationLogsRequest request);
138-
139127
/**
140128
* Push a specific application
141129
*

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
}
@@ -1596,30 +1602,29 @@ private static int getInstances(AbstractApplicationResource resource) {
15961602
.orElse(0);
15971603
}
15981604

1599-
private static Flux<LogMessage> getLogs(
1600-
Mono<DopplerClient> dopplerClient, String applicationId, Boolean recent) {
1605+
/* private static Flux<Log> getLogs(
1606+
Mono<LogCacheClient> logCacheClient, String applicationId, Boolean recent) {
16011607
if (Optional.ofNullable(recent).orElse(false)) {
1602-
return requestLogsRecent(dopplerClient, applicationId)
1603-
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1604-
.map(Envelope::getLogMessage)
1605-
.collectSortedList(LOG_MESSAGE_COMPARATOR)
1606-
.flatMapIterable(d -> d);
1607-
} else {
1608-
return requestLogsStream(dopplerClient, applicationId)
1609-
.filter(e -> EventType.LOG_MESSAGE == e.getEventType())
1610-
.map(Envelope::getLogMessage)
1611-
.transformDeferred(
1612-
SortingUtils.timespan(LOG_MESSAGE_COMPARATOR, LOG_MESSAGE_TIMESPAN));
1608+
return getRecentLogs(logCacheClient, applicationId);
16131609
}
1610+
}*/
1611+
1612+
private static Flux<Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
1613+
return requestLogsRecentLogCache(logCacheClient, applicationId)
1614+
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1615+
// .collectSortedList(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1616+
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1617+
.map(org.cloudfoundry.logcache.v1.Envelope::getLog);
16141618
}
16151619

1616-
private static Flux<LogMessage> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
1620+
/* private static Flux<org.cloudfoundry.logcache.v1.Log> getRecentLogs(Mono<LogCacheClient> logCacheClient, String applicationId) {
16171621
return requestLogsRecentLogCache(logCacheClient, applicationId)
16181622
.filter(e -> EnvelopeType.LOG.getValue().equals(e.getLog().getType().getValue()))
1623+
.sort(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
16191624
.map(org.cloudfoundry.logcache.v1.Envelope::getLog)
1620-
.collectSortedList(LOG_MESSAGE_COMPARATOR_LOG_CACHE)
1621-
.flatMapIterable(d -> d);
1622-
}
1625+
.collectList()
1626+
.flatMapIterable(d1 -> d1).cast(org.cloudfoundry.logcache.v1.Log.class);
1627+
} */
16231628

16241629
@SuppressWarnings("unchecked")
16251630
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
@@ -53,6 +53,7 @@
5353
import org.cloudfoundry.client.v3.stacks.StacksV3;
5454
import org.cloudfoundry.client.v3.tasks.Tasks;
5555
import org.cloudfoundry.doppler.DopplerClient;
56+
import org.cloudfoundry.logcache.v1.LogCacheClient;
5657
import org.cloudfoundry.routing.RoutingClient;
5758
import org.cloudfoundry.routing.v1.routergroups.RouterGroups;
5859
import org.cloudfoundry.uaa.UaaClient;
@@ -104,6 +105,8 @@ public abstract class AbstractOperationsTest {
104105

105106
protected final DopplerClient dopplerClient = mock(DopplerClient.class, RETURNS_SMART_NULLS);
106107

108+
protected final LogCacheClient logCacheClient = mock(LogCacheClient.class, RETURNS_SMART_NULLS);
109+
107110
protected final Events events = mock(Events.class, RETURNS_SMART_NULLS);
108111

109112
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
}
@@ -5317,17 +5322,11 @@ private static void requestListTasksEmpty(
53175322
.build()));
53185323
}
53195324

5320-
private static void requestLogsRecent(DopplerClient dopplerClient, String applicationId) {
5321-
when(dopplerClient.recentLogs(
5322-
RecentLogsRequest.builder().applicationId(applicationId).build()))
5325+
private static void requestLogsRecentLogCache(LogCacheClient logCacheClient, String applicationId) {
5326+
when(logCacheClient.recentLogs(
5327+
ReadRequest.builder().sourceId(applicationId).build()))
53235328
.thenReturn(
5324-
Flux.just(
5325-
Envelope.builder()
5326-
.eventType(EventType.LOG_MESSAGE)
5327-
.logMessage(
5328-
fill(LogMessage.builder(), "log-message-").build())
5329-
.origin("rsp")
5330-
.build()));
5329+
Mono.just(ReadResponse.builder().envelopes(fill(org.cloudfoundry.logcache.v1.EnvelopeBatch.builder()).build()).build()));
53315330
}
53325331

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

0 commit comments

Comments
 (0)