4. Service Instance Logging
You can configure the service broker to be compatible with the Service instance logs CLI plugin in order to tail and stream the logs of the backing application.
If you use Gradle, include the following in your application’s build.gradle
file:
dependencies {
api 'spring-cloud-starter-app-broker-logging:2.4.0'
}
If you use Maven, include the following in your application’s pom.xml
file:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-app-broker-logging</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
Then, include the serviceInstanceLogsEndpoint
in the catalog metadata properties:
spring:
cloud:
openservicebroker:
catalog:
services:
- id: "service-id"
name: "service-name"
metadata:
properties:
serviceInstanceLogsEndpoint: https://scg-service-broker.system.domain.com/logs/
Finally, provide an implementation for ApplicationIdsProvider
in order to retrieve the backing application id given a service instance id, for example:
/*
* Copyright 2016-2024 the original author or authors.
*
* 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
*
* https://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 org.springframework.cloud.appbroker.acceptance.logging;
@Component
class BackingApplicationIdsProvider implements ApplicationIdsProvider {
private final CloudFoundryClient cloudFoundryClient;
private final CloudFoundryOperations cloudFoundryOperations;
BackingApplicationIdsProvider(CloudFoundryClient cloudFoundryClient,
CloudFoundryOperations cloudFoundryOperations) {
this.cloudFoundryClient = cloudFoundryClient;
this.cloudFoundryOperations = cloudFoundryOperations;
}
@Override
public Flux<String> getApplicationIds(String serviceInstanceId) {
return this.cloudFoundryOperations.spaces()
.get(GetSpaceRequest.builder().name(serviceInstanceId).build())
.map(SpaceDetail::getId)
.flatMap((spaceId) -> this.cloudFoundryClient.applicationsV3()
.list(ListApplicationsRequest.builder().spaceIds(spaceId).build()))
.flatMapMany((listApplicationsResponse) -> Flux.fromIterable(listApplicationsResponse.getResources())
.map(ApplicationResource::getId));
}
}