-
Notifications
You must be signed in to change notification settings - Fork 811
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(telemetry): fix MetricsPostProcessor dependency injection (#4224)
Allow registry implementations to be processed by other BeanPostProcessors Fix armory-plugins/armory-observability-plugin#32
- Loading branch information
1 parent
9586ec7
commit d168010
Showing
5 changed files
with
139 additions
and
0 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
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
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
65 changes: 65 additions & 0 deletions
65
orca-web/src/test/java/com/netflix/spinnaker/orca/MeterRegistryProcessorIntTest.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,65 @@ | ||
/* | ||
* Copyright 2019 Google, 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.spinnaker.orca; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import io.micrometer.core.instrument.MeterRegistry; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.BeansException; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringBootTest(classes = {Main.class}) | ||
@ContextConfiguration(classes = {MeterRegistryProcessorTestConfiguration.class}) | ||
@TestPropertySource( | ||
properties = {"spring.config.location=classpath:orca-test.yml", "redis.enabled: false"}) | ||
public class MeterRegistryProcessorIntTest { | ||
|
||
@Autowired TestBeanPostProcessor testBeanPostProcessor; | ||
|
||
@Test | ||
public void test() { | ||
assertEquals(true, testBeanPostProcessor.invoked); | ||
} | ||
|
||
/* | ||
Helper bean post processor used as spy | ||
*/ | ||
public static class TestBeanPostProcessor implements BeanPostProcessor { | ||
boolean invoked = false; | ||
|
||
public TestBeanPostProcessor() {} | ||
|
||
@Override | ||
public final Object postProcessBeforeInitialization(Object bean, String beanName) | ||
throws BeansException { | ||
|
||
if (bean instanceof MeterRegistry) { | ||
invoked = true; | ||
} | ||
|
||
return bean; | ||
} | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...web/src/test/java/com/netflix/spinnaker/orca/MeterRegistryProcessorTestConfiguration.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,68 @@ | ||
/* | ||
* Copyright 2022 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.spinnaker.orca; | ||
|
||
import com.netflix.spinnaker.orca.notifications.AlwaysUnlockedNotificationClusterLock; | ||
import com.netflix.spinnaker.orca.notifications.NotificationClusterLock; | ||
import com.netflix.spinnaker.orca.pipeline.persistence.ExecutionRepository; | ||
import com.netflix.spinnaker.orca.pipeline.persistence.InMemoryExecutionRepository; | ||
import com.netflix.spinnaker.q.memory.InMemoryQueue; | ||
import com.netflix.spinnaker.q.metrics.EventPublisher; | ||
import com.netflix.spinnaker.q.metrics.MonitorableQueue; | ||
import io.micrometer.core.instrument.MeterRegistry; | ||
import io.micrometer.core.instrument.composite.CompositeMeterRegistry; | ||
import io.micrometer.core.instrument.simple.SimpleMeterRegistry; | ||
import java.time.Clock; | ||
import java.time.Duration; | ||
import java.util.Collections; | ||
import org.springframework.beans.factory.config.BeanPostProcessor; | ||
import org.springframework.boot.test.context.TestConfiguration; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Primary; | ||
|
||
@TestConfiguration | ||
public class MeterRegistryProcessorTestConfiguration { | ||
|
||
@Bean | ||
NotificationClusterLock notificationClusterLock() { | ||
return new AlwaysUnlockedNotificationClusterLock(); | ||
} | ||
|
||
@Bean | ||
ExecutionRepository executionRepository() { | ||
return new InMemoryExecutionRepository(); | ||
} | ||
|
||
@Bean | ||
@Primary | ||
MonitorableQueue queue(Clock clock, EventPublisher publisher) { | ||
return new InMemoryQueue( | ||
clock, Duration.ofMinutes(1), Collections.emptyList(), false, publisher); | ||
} | ||
|
||
@Bean | ||
MeterRegistry meterRegistry() { | ||
return new CompositeMeterRegistry( | ||
io.micrometer.core.instrument.Clock.SYSTEM, | ||
Collections.singleton(new SimpleMeterRegistry())); | ||
} | ||
|
||
@Bean | ||
BeanPostProcessor testBeanPostProcessor() { | ||
return new MeterRegistryProcessorIntTest.TestBeanPostProcessor(); | ||
} | ||
} |