-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cf): Logs support for run job stage and app instance (#3900)
* Added the Logs (doppler) service for the Cloud Foundry Client Implemented the `recentLogs` endpoint only. * Ensuring the jobName is unique * Implemented CloudFoundryInstanceProvider.getConsoleOutput() using Doppler's recent logs. Supports retrieving task or app logs.
- Loading branch information
Pierre Delagrave
authored and
Jammy Louie
committed
Jul 29, 2019
1 parent
cf45247
commit 345c551
Showing
21 changed files
with
1,172 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,6 @@ public interface CloudFoundryClient { | |
ServiceKeys getServiceKeys(); | ||
|
||
Tasks getTasks(); | ||
|
||
Logs getLogs(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...loudfoundry/src/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/Logs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2019 Pivotal, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.clouddriver.cloudfoundry.client; | ||
|
||
import static com.netflix.spinnaker.clouddriver.cloudfoundry.client.CloudFoundryClientUtils.safelyCall; | ||
import static java.util.stream.Collectors.joining; | ||
|
||
import com.netflix.spinnaker.clouddriver.cloudfoundry.client.api.DopplerService; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.cloudfoundry.dropsonde.events.EventFactory.Envelope; | ||
import org.cloudfoundry.dropsonde.events.EventFactory.Envelope.EventType; | ||
import org.cloudfoundry.dropsonde.events.LogFactory.LogMessage; | ||
|
||
@RequiredArgsConstructor | ||
public class Logs { | ||
private final DopplerService api; | ||
|
||
public String recentApplicationLogs(String applicationGuid, int instanceIndex) { | ||
return recentLogsFiltered(applicationGuid, "APP/PROC/WEB", instanceIndex); | ||
} | ||
|
||
public String recentTaskLogs(String applicationGuid, String taskName) { | ||
return recentLogsFiltered(applicationGuid, "APP/TASK/" + taskName, 0); | ||
} | ||
|
||
public List<Envelope> recentLogs(String applicationGuid) { | ||
return safelyCall(() -> api.recentLogs(applicationGuid)) | ||
.orElseThrow(IllegalStateException::new); | ||
} | ||
|
||
private String recentLogsFiltered( | ||
String applicationGuid, String logSourceFilter, int instanceIndex) { | ||
List<Envelope> envelopes = recentLogs(applicationGuid); | ||
|
||
return envelopes.stream() | ||
.filter(e -> e.getEventType().equals(EventType.LogMessage)) | ||
.map(Envelope::getLogMessage) | ||
.filter( | ||
logMessage -> | ||
logSourceFilter.equals(logMessage.getSourceType()) | ||
&& logMessage.getSourceInstance().equals(String.valueOf(instanceIndex))) | ||
.sorted(Comparator.comparingLong(LogMessage::getTimestamp)) | ||
.map(msg -> msg.getMessage().toStringUtf8()) | ||
.collect(joining("\n")); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...c/main/java/com/netflix/spinnaker/clouddriver/cloudfoundry/client/api/DopplerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2019 Pivotal, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.netflix.spinnaker.clouddriver.cloudfoundry.client.api; | ||
|
||
import java.util.List; | ||
import org.cloudfoundry.dropsonde.events.EventFactory.Envelope; | ||
import retrofit.http.GET; | ||
import retrofit.http.Path; | ||
|
||
public interface DopplerService { | ||
@GET("/apps/{guid}/recentlogs") | ||
List<Envelope> recentLogs(@Path("guid") String appGuid); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.