- 
                Notifications
    
You must be signed in to change notification settings  - Fork 1k
 
          Delay loading InetAddressResolverProvider until after the agent has started
          #11987
        
          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
          
     Merged
      
      
            trask
  merged 6 commits into
  open-telemetry:main
from
serkan-ozal:fix/init-inetaddress-after-agent
  
      
      
   
  Aug 19, 2024 
      
    
  
     Merged
                    Changes from 5 commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      09cb446
              
                Initialize `java.net.InetAddress` after VM and agent are initialized
              
              
                serkan-ozal ee09b87
              
                Fix review comments
              
              
                serkan-ozal 8b93008
              
                Add test
              
              
                serkan-ozal 1271783
              
                Merge branch 'main' into fix/init-inetaddress-after-agent
              
              
                laurit 2927bf6
              
                rename testing module and a few other changes
              
              
                laurit 31de46a
              
                remove acceidentally added line
              
              
                laurit 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| plugins { | ||
| id("otel.javaagent-testing") | ||
| } | ||
| 
     | 
||
| dependencies { | ||
| compileOnly("io.opentelemetry:opentelemetry-sdk-common") | ||
| } | ||
| 
     | 
||
| otelJava { | ||
| minJavaVersionSupported.set(JavaVersion.VERSION_18) | ||
| } | 
        
          
  
    
      
          
            30 changes: 30 additions & 0 deletions
          
          30 
        
  javaagent-tooling/jdk18-testing/src/main/java/testing/TestResourceProvider.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,30 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| 
     | 
||
| package testing; | ||
| 
     | 
||
| import com.google.auto.service.AutoService; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; | ||
| import io.opentelemetry.sdk.resources.Resource; | ||
| import java.net.InetAddress; | ||
| import java.net.UnknownHostException; | ||
| 
     | 
||
| @AutoService(ResourceProvider.class) | ||
| public class TestResourceProvider implements ResourceProvider { | ||
| 
     | 
||
| @Override | ||
| public Resource createResource(ConfigProperties config) { | ||
| // used in test to determine whether this method was called | ||
| System.setProperty("test.resource.provider.called", "true"); | ||
| // this call trigger loading InetAddressResolverProvider SPI on jdk 18 | ||
| try { | ||
| InetAddress.getLocalHost(); | ||
| } catch (UnknownHostException e) { | ||
| throw new IllegalStateException(e); | ||
| } | ||
| return Resource.empty(); | ||
| } | ||
| } | 
        
          
  
    
      
          
            28 changes: 28 additions & 0 deletions
          
          28 
        
  ...src/test/java/io/opentelemetry/javaagent/tooling/inetaddress/InetAddressResolverTest.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,28 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| 
     | 
||
| package io.opentelemetry.javaagent.tooling.inetaddress; | ||
| 
     | 
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| 
     | 
||
| import java.net.InetAddress; | ||
| import org.junit.jupiter.api.Test; | ||
| 
     | 
||
| public class InetAddressResolverTest { | ||
| 
     | 
||
| @Test | ||
| void agentStartShouldNotTriggerLoadingCustomInetAddressResolvers() throws Exception { | ||
| // This system property is set in TestResourceProvider | ||
| assertThat(System.getProperty("test.resource.provider.called")).isEqualTo("true"); | ||
| // Agent start should not trigger loading (and instantiating) custom InetAddress resolvers | ||
| assertThat(TestAddressResolver.isInstantiated()).isFalse(); | ||
| 
     | 
||
| // Trigger loading (and instantiating) custom InetAddress resolvers manually | ||
| InetAddress.getAllByName("test"); | ||
| 
     | 
||
| // Verify that custom InetAddress resolver loaded and instantiated | ||
| assertThat(TestAddressResolver.isInstantiated()).isTrue(); | ||
| } | ||
| } | 
        
          
  
    
      
          
            40 changes: 40 additions & 0 deletions
          
          40 
        
  ...ing/src/test/java/io/opentelemetry/javaagent/tooling/inetaddress/TestAddressResolver.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,40 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| 
     | 
||
| package io.opentelemetry.javaagent.tooling.inetaddress; | ||
| 
     | 
||
| import java.net.InetAddress; | ||
| import java.net.UnknownHostException; | ||
| import java.net.spi.InetAddressResolver; | ||
| import java.util.stream.Stream; | ||
| 
     | 
||
| public class TestAddressResolver implements InetAddressResolver { | ||
| 
     | 
||
| private static volatile boolean instantiated = false; | ||
| 
     | 
||
| @SuppressWarnings("StaticAssignmentInConstructor") | ||
| public TestAddressResolver() { | ||
| new Exception().printStackTrace(); | ||
| TestAddressResolver.instantiated = true; | ||
| } | ||
| 
     | 
||
| public static boolean isInstantiated() { | ||
| return instantiated; | ||
| } | ||
| 
     | 
||
| @Override | ||
| public Stream<InetAddress> lookupByName(String host, LookupPolicy lookupPolicy) | ||
| throws UnknownHostException { | ||
| if (host.equals("test")) { | ||
| return Stream.of(InetAddress.getByAddress(new byte[] {127, 0, 0, 1})); | ||
| } | ||
| throw new UnknownHostException(); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public String lookupByAddress(byte[] addr) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } | 
        
          
  
    
      
          
            22 changes: 22 additions & 0 deletions
          
          22 
        
  ...test/java/io/opentelemetry/javaagent/tooling/inetaddress/TestAddressResolverProvider.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,22 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| 
     | 
||
| package io.opentelemetry.javaagent.tooling.inetaddress; | ||
| 
     | 
||
| import java.net.spi.InetAddressResolver; | ||
| import java.net.spi.InetAddressResolverProvider; | ||
| 
     | 
||
| public class TestAddressResolverProvider extends InetAddressResolverProvider { | ||
| 
     | 
||
| @Override | ||
| public InetAddressResolver get(Configuration configuration) { | ||
| return new TestAddressResolver(); | ||
| } | ||
| 
     | 
||
| @Override | ||
| public String name() { | ||
| return "Test Internet Address Resolver Provider"; | ||
| } | ||
| } | 
        
          
  
    
      
          
            1 change: 1 addition & 0 deletions
          
          1 
        
  ...k18-testing/src/test/resources/META-INF/services/java.net.spi.InetAddressResolverProvider
  
  
      
      
   
        
      
      
    
  
    
      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 @@ | ||
| io.opentelemetry.javaagent.tooling.inetaddress.TestAddressResolverProvider | 
  
    
      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
    
  
  
    
              
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.