-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ipc: make constructor with logger config public (#1152)
Update the visibility to allow the config to be customized. The default http client wrapper now sets up the config to delegate to system properties.
- Loading branch information
1 parent
6351649
commit c0f3e5f
Showing
4 changed files
with
91 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
45 changes: 45 additions & 0 deletions
45
spectator-ext-ipc/src/main/java/com/netflix/spectator/ipc/http/Defaults.java
This file contains 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,45 @@ | ||
/* | ||
* Copyright 2014-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.http; | ||
|
||
import com.netflix.spectator.api.Spectator; | ||
import com.netflix.spectator.ipc.IpcLogger; | ||
import com.netflix.spectator.ipc.IpcLoggerConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** Default instances for IPC loggers used with HTTP client wrapper. */ | ||
final class Defaults { | ||
|
||
private Defaults() { | ||
} | ||
|
||
/** Use HttpClient for the slf4j logger instance. */ | ||
static final Logger LOGGER = LoggerFactory.getLogger(HttpClient.class); | ||
|
||
/** Logger config that delegates to system properties. */ | ||
static final IpcLoggerConfig IPC_LOGGER_CONFIG = Defaults::getProperty; | ||
|
||
/** IPC logger using global registry and with default config. */ | ||
static final IpcLogger IPC_LOGGER = | ||
new IpcLogger(Spectator.globalRegistry(), LOGGER, IPC_LOGGER_CONFIG); | ||
|
||
/** Delegate to system properties and change default to disable inflight metrics. */ | ||
private static String getProperty(String key) { | ||
String dflt = "spectator.ipc.inflight-metrics-enabled".equals(key) ? "false" : null; | ||
return System.getProperty(key, dflt); | ||
} | ||
} |
This file contains 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
42 changes: 42 additions & 0 deletions
42
spectator-ext-ipc/src/test/java/com/netflix/spectator/ipc/http/DefaultsTest.java
This file contains 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,42 @@ | ||
/* | ||
* Copyright 2014-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.http; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class DefaultsTest { | ||
|
||
private static final String infightProp = "spectator.ipc.inflight-metrics-enabled"; | ||
|
||
@Test | ||
public void inflightDefaultsFalse() { | ||
System.clearProperty(infightProp); | ||
Assertions.assertFalse(Defaults.IPC_LOGGER_CONFIG.inflightMetricsEnabled()); | ||
} | ||
|
||
@Test | ||
public void inflightSetFalse() { | ||
System.setProperty(infightProp, "false"); | ||
Assertions.assertFalse(Defaults.IPC_LOGGER_CONFIG.inflightMetricsEnabled()); | ||
} | ||
|
||
@Test | ||
public void inflightSetTrue() { | ||
System.setProperty(infightProp, "true"); | ||
Assertions.assertTrue(Defaults.IPC_LOGGER_CONFIG.inflightMetricsEnabled()); | ||
} | ||
} |