Skip to content
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

feat: Improve Logging #1892

Merged
merged 2 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,10 @@ private void consumePartitions(
}
consumer.apply(new QueryPartition(partitionQuery, lastCursor, null));
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public String toString() {
return String.format("CollectionGroup{partitionQuery=%s, options=%s}", partitionQuery, options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,11 @@ public boolean equals(Object obj) {
public int hashCode() {
return Objects.hash(type, document, oldIndex, newIndex);
}

@Override
public String toString() {
return String.format(
"DocumentChange{type=%s, document=%s, oldIndex=%d, newIndex=%d}",
type, document, oldIndex, newIndex);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,11 @@ public boolean equals(Object o) {
public int hashCode() {
return Objects.hash(query, this.getDocumentChanges(), this.getDocuments());
}

@Override
public String toString() {
return String.format(
"%s{query=%s, readTime=%s, documentChanges=%s, documents=%s}",
getClass().getSimpleName(), query, readTime, documentChanges, documents);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
*/
final class SilenceableBidiStream<RequestT, ResponseT>
implements BidiStreamObserver<RequestT, ResponseT> {
private static final Logger LOGGER = Logger.getLogger(SilenceableBidiStream.class.getName());

private final ClientStream<RequestT> stream;
private final BidiStreamObserver<RequestT, ResponseT> delegate;
private boolean silence = false;
private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());

SilenceableBidiStream(
BidiStreamObserver<RequestT, ResponseT> responseObserverT,
Expand All @@ -63,17 +63,17 @@ public boolean isSilenced() {
}

public void send(RequestT request) {
LOGGER.info(stream.toString());
LOGGER.fine(stream.toString());
stream.send(request);
}

public void closeSend() {
LOGGER.info(stream::toString);
LOGGER.fine(stream::toString);
stream.closeSend();
}

public void closeSendAndSilence() {
LOGGER.info(stream::toString);
LOGGER.fine(stream::toString);
silence = true;
stream.closeSend();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,9 @@ private boolean isRetryableError(Throwable throwable, Set<StatusCode.Code> retry
}
return false;
}

@Override
public String toString() {
return String.format("%s{options=%s}", getClass().getSimpleName(), options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ VectorQuerySnapshot createSnaphot(
return VectorQuerySnapshot.withDocuments(this, readTime, documents);
}

@SuppressWarnings("MethodDoesntCallSuperMethod")
@Override
public String toString() {
return String.format(
"VectorQuery{query=%s, vectorField=%s, queryVector=%s, limit=%d, distanceMeasure=%s, options=%s, options=%s}",
query, vectorField, queryVector, limit, distanceMeasure, options, options);
}

/**
* The distance measure to use when comparing vectors in a {@link VectorQuery}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ public boolean equals(Object obj) {
&& Objects.equals(distanceThreshold, otherOptions.distanceThreshold);
}

@Override
public String toString() {
return String.format(
"VectorQueryOptions{distanceResultField=%s, distanceThreshold=%s}",
distanceResultField, distanceThreshold);
}

/** Default VectorQueryOptions instance. */
private static VectorQueryOptions DEFAULT = newBuilder().build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ MapValue toProto() {
int size() {
return this.values.length;
}

@Override
public String toString() {
return String.format("VectorValue{values=%s}", Arrays.toString(values));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
* synchronization.
*/
final class Watch implements BidiStreamObserver<ListenRequest, ListenResponse> {
private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());

/**
* Target ID used by watch. Watch uses a fixed target id since we only support one target per
* stream. The actual target ID we use is arbitrary.
Expand Down Expand Up @@ -115,8 +117,6 @@ static class ChangeSet {
List<QueryDocumentSnapshot> updates = new ArrayList<>();
}

private static final Logger LOGGER = Logger.getLogger(Watch.class.getName());

/**
* @param firestore The Firestore Database client.
* @param query The query that is used to order the document snapshots returned by this watch.
Expand Down Expand Up @@ -474,7 +474,7 @@ private void pushSnapshot(final Timestamp readTime, ByteString nextResumeToken)
if (!hasPushed || !changes.isEmpty()) {
final QuerySnapshot querySnapshot =
QuerySnapshot.withChanges(query, readTime, documentSet, changes);
LOGGER.info(querySnapshot.toString());
LOGGER.fine(querySnapshot.toString());
userCallbackExecutor.execute(() -> listener.onEvent(querySnapshot, null));
hasPushed = true;
}
Expand Down
Loading