Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
annieyang committed Nov 11, 2024
1 parent 477741c commit ba568f4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public final class IpcLogEntry {

private String owner;
private IpcResult result;
private IpcSource source;

private String protocol;

Expand Down Expand Up @@ -209,6 +210,14 @@ public IpcLogEntry withResult(IpcResult result) {
return this;
}

/**
* Set the source for this request. See {@link IpcSource} for more information.
*/
public IpcLogEntry withSource(IpcSource source) {
this.source = source;
return this;
}

/**
* Set the high level status for the request. See {@link IpcStatus} for more
* information.
Expand Down Expand Up @@ -936,6 +945,7 @@ public String toString() {
.addField("attempt", attempt)
.addField("attemptFinal", attemptFinal)
.addField("result", result)
.addField("source", source)
.addField("status", status)
.addField("statusDetail", statusDetail)
.addField("exceptionClass", getExceptionClass())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public enum IpcMetric {
IpcTagKey.status
),
EnumSet.of(
IpcTagKey.source,
IpcTagKey.endpoint,
IpcTagKey.method,
IpcTagKey.failureInjected,
Expand All @@ -75,6 +76,7 @@ public enum IpcMetric {
IpcTagKey.status
),
EnumSet.of(
IpcTagKey.source,
IpcTagKey.endpoint,
IpcTagKey.method,
IpcTagKey.clientApp,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/**
* Copyright 2024 Netflix, 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.spectator.ipc;

import com.netflix.spectator.api.Tag;
Expand Down Expand Up @@ -46,7 +61,12 @@ public enum IpcSource implements Tag {
/**
* Data fetched from an in-memory cache.
*/
memory;
memory,

/**
* Data sourced from a user defined business logic handler or root data fetcher.
*/
application;

@Override
public String key() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,15 @@ public void addResponseEndpointHeader() {
Assertions.assertEquals("/api/v1/test", map.get("endpoint"));
}

@Test
public void source() {
String expected = IpcSource.direct.value();
String actual = (String) entry
.withSource(IpcSource.direct)
.convert(this::toMap).get("source");
Assertions.assertEquals(expected, actual);
}

@Test
public void httpStatusOk() {
String actual = (String) entry
Expand Down

0 comments on commit ba568f4

Please sign in to comment.