-
Notifications
You must be signed in to change notification settings - Fork 320
Introduce LoggregatorV2 Client #1021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
enchobelezirev
wants to merge
1
commit into
cloudfoundry:main
Choose a base branch
from
enchobelezirev:loggregator-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
58 changes: 58 additions & 0 deletions
58
...tor/src/main/java/org/cloudfoundry/reactor/loggregator/AbstractLoggregatorOperations.java
This file contains hidden or 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,58 @@ | ||
/* | ||
* Copyright 2013-2019 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 | ||
* | ||
* 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 org.cloudfoundry.reactor.loggregator; | ||
|
||
import io.netty.channel.ChannelHandler; | ||
import org.cloudfoundry.reactor.ConnectionContext; | ||
import org.cloudfoundry.reactor.TokenProvider; | ||
import org.cloudfoundry.reactor.client.QueryBuilder; | ||
import org.cloudfoundry.reactor.client.v3.FilterBuilder; | ||
import org.cloudfoundry.reactor.util.AbstractReactorOperations; | ||
import org.springframework.web.util.UriComponentsBuilder; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
import reactor.netty.ByteBufFlux; | ||
import reactor.netty.http.client.HttpClientResponse; | ||
|
||
import java.util.function.Function; | ||
|
||
|
||
abstract class AbstractLoggregatorOperations extends AbstractReactorOperations { | ||
|
||
protected AbstractLoggregatorOperations(ConnectionContext connectionContext, Mono<String> root, TokenProvider tokenProvider) { | ||
super(connectionContext, root, tokenProvider); | ||
} | ||
|
||
<T> Flux<T> get(Object requestPayload, Function<UriComponentsBuilder, UriComponentsBuilder> uriTransformer, Function<HttpClientResponse, ChannelHandler> channelHandlerBuilder, | ||
Function<ByteBufFlux, Flux<T>> bodyTransformer) { | ||
return createOperator().flatMapMany(operator -> operator.get() | ||
.uri(queryTransformer(requestPayload).andThen(uriTransformer)) | ||
.response() | ||
.addChannelHandler(channelHandlerBuilder) | ||
.parseBodyToFlux(responseWithBody -> bodyTransformer.apply(responseWithBody.getBody()))); | ||
} | ||
|
||
private static Function<UriComponentsBuilder, UriComponentsBuilder> queryTransformer(Object requestPayload) { | ||
return builder -> { | ||
FilterBuilder.augment(builder, requestPayload); | ||
QueryBuilder.augment(builder, requestPayload); | ||
|
||
return builder; | ||
}; | ||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
...actor/src/main/java/org/cloudfoundry/reactor/loggregator/ReactorLoggregatorEndpoints.java
This file contains hidden or 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,38 @@ | ||
/* | ||
* Copyright 2013-2019 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 | ||
* | ||
* 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 org.cloudfoundry.reactor.loggregator; | ||
|
||
import org.cloudfoundry.doppler.Envelope; | ||
import org.cloudfoundry.loggregator.v2.StreamRequest; | ||
import org.cloudfoundry.reactor.ConnectionContext; | ||
import org.cloudfoundry.reactor.TokenProvider; | ||
import org.cloudfoundry.reactor.doppler.MultipartCodec; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class ReactorLoggregatorEndpoints extends AbstractLoggregatorOperations { | ||
|
||
ReactorLoggregatorEndpoints(ConnectionContext connectionContext, Mono<String> root, TokenProvider tokenProvider) { | ||
super(connectionContext, root, tokenProvider); | ||
} | ||
|
||
public Flux<Envelope> stream(StreamRequest request) { | ||
return get(request, uriComponentsBuilder -> uriComponentsBuilder.pathSegment("v2/read"), MultipartCodec::createSimpleDecoder, MultipartCodec::decodeAsEnvelope) | ||
.map(Envelope::from) | ||
.checkpoint(); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...reactor/src/main/java/org/cloudfoundry/reactor/loggregator/_ReactorLoggregatorClient.java
This file contains hidden or 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,54 @@ | ||
/* | ||
* Copyright 2013-2019 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 | ||
* | ||
* 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 org.cloudfoundry.reactor.loggregator; | ||
|
||
import org.cloudfoundry.doppler.Envelope; | ||
import org.cloudfoundry.loggregator.v2.LoggregatorClient; | ||
import org.cloudfoundry.loggregator.v2.StreamRequest; | ||
import org.cloudfoundry.reactor.ConnectionContext; | ||
import org.cloudfoundry.reactor.TokenProvider; | ||
import org.immutables.value.Value; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Value.Immutable | ||
abstract class _ReactorLoggregatorClient implements LoggregatorClient { | ||
@Override | ||
public Flux<Envelope> stream(StreamRequest request) { | ||
return getLoggregatorEndpoints().stream(request); | ||
} | ||
|
||
@Value.Derived | ||
ReactorLoggregatorEndpoints getLoggregatorEndpoints() { | ||
return new ReactorLoggregatorEndpoints(getConnectionContext(), getRoot(), getTokenProvider()); | ||
} | ||
|
||
@Value.Default | ||
Mono<String> getRoot() { | ||
return getConnectionContext().getRootProvider().getRoot("log_stream", getConnectionContext()); | ||
} | ||
|
||
/** | ||
* The connection context | ||
*/ | ||
abstract ConnectionContext getConnectionContext(); | ||
|
||
/** | ||
* The token provider | ||
*/ | ||
abstract TokenProvider getTokenProvider(); | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package org.cloudfoundry.doppler; | ||
|
||
import org.cloudfoundry.Nullable; | ||
import org.cloudfoundry.loggregator.v2.LoggregatorEnvelope; | ||
import org.immutables.value.Value; | ||
|
||
import java.util.Objects; | ||
|
@@ -41,6 +42,30 @@ public static ContainerMetric from(org.cloudfoundry.dropsonde.events.ContainerMe | |
.build(); | ||
} | ||
|
||
public static ContainerMetric from(LoggregatorEnvelope.Envelope envelope) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires tests in line with |
||
Objects.requireNonNull(envelope.getGauge(), "envelope"); | ||
|
||
LoggregatorEnvelope.Gauge gauge = envelope.getGauge(); | ||
return ContainerMetric.builder() | ||
.applicationId(envelope.getSourceId()) | ||
.instanceIndex(Integer.parseInt(envelope.getInstanceId())) | ||
.cpuPercentage(getMetricsValue(gauge, "cpu")) | ||
.diskBytes(getLongValue(gauge, "disk")) | ||
.diskBytesQuota(getLongValue(gauge, "disk_quota")) | ||
.memoryBytes(getLongValue(gauge, "memory")) | ||
.memoryBytesQuota(getLongValue(gauge, "memory_quota")) | ||
.build(); | ||
} | ||
|
||
private static Long getLongValue(LoggregatorEnvelope.Gauge gauge, String property) { | ||
double metricsValue = getMetricsValue(gauge, property); | ||
return Double.valueOf(metricsValue).longValue(); | ||
} | ||
|
||
private static double getMetricsValue(LoggregatorEnvelope.Gauge gauge, String property) { | ||
return gauge.getMetricsMap().getOrDefault(property, LoggregatorEnvelope.GaugeValue.newBuilder().setValue(0.0).build()).getValue(); | ||
} | ||
|
||
/** | ||
* The ID of the contained application | ||
*/ | ||
|
This file contains hidden or 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 |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
package org.cloudfoundry.doppler; | ||
|
||
import org.cloudfoundry.Nullable; | ||
import org.cloudfoundry.loggregator.v2.LoggregatorEnvelope; | ||
import org.immutables.value.Value; | ||
|
||
import java.util.Objects; | ||
|
@@ -36,6 +37,15 @@ public static CounterEvent from(org.cloudfoundry.dropsonde.events.CounterEvent d | |
.total(dropsonde.total) | ||
.build(); | ||
} | ||
public static CounterEvent from(LoggregatorEnvelope.Counter counter) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Requires tests in line with |
||
Objects.requireNonNull(counter, "counter"); | ||
|
||
return CounterEvent.builder() | ||
.delta(counter.getDelta()) | ||
.name(counter.getName()) | ||
.total(counter.getTotal()) | ||
.build(); | ||
} | ||
|
||
/** | ||
* The amount by which to increment the counter | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requires tests in line with
ReactorDopplerClientTest