4. 服务实例日志记录
您可以将 Service Broker 配置为与 Service instance logs CLI 插件兼容,以便跟踪和流式传输后备应用程序的日志。
如果您使用 Gradle,请在应用程序的build.gradle
文件:
dependencies {
api 'spring-cloud-starter-app-broker-logging:2.4.0'
}
如果您使用 Maven,请在应用程序的pom.xml
文件:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-app-broker-logging</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
然后,包括serviceInstanceLogsEndpoint
在 Catalog 元数据属性中:
spring:
cloud:
openservicebroker:
catalog:
services:
- id: "service-id"
name: "service-name"
metadata:
properties:
serviceInstanceLogsEndpoint: https://scg-service-broker.system.domain.com/logs/
最后,为ApplicationIdsProvider
为了检索给定服务实例 ID 的后备应用程序 ID,例如:
/*
* 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));
}
}