- 
                Notifications
    
You must be signed in to change notification settings  - Fork 25.6k
 
[EIS] Validate EIS Gateway URL if set #114600
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
      
      
            timgrein
  merged 6 commits into
  elastic:main
from
timgrein:throw-error-on-invalid-eis-gateway-uri-scheme
  
      
      
   
  Oct 15, 2024 
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c7205e3
              
                Validate EIS Gateway URL if set
              
              
                timgrein ab0c679
              
                Merge branch 'main' into throw-error-on-invalid-eis-gateway-uri-scheme
              
              
                timgrein 00d3942
              
                Remove Test annotations
              
              
                timgrein e18359d
              
                Merge branch 'main' into throw-error-on-invalid-eis-gateway-uri-scheme
              
              
                elasticmachine 0457fac
              
                Add debug log, whether eis-gateway URL is set or not
              
              
                timgrein 4a18314
              
                Merge branch 'main' into throw-error-on-invalid-eis-gateway-uri-scheme
              
              
                elasticmachine 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
    
  
  
    
              
        
          
          
            64 changes: 64 additions & 0 deletions
          
          64 
        
  .../elasticsearch/xpack/inference/services/elastic/ElasticInferenceServiceSettingsTests.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,64 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| 
     | 
||
| package org.elasticsearch.xpack.inference.services.elastic; | ||
| 
     | 
||
| import org.elasticsearch.test.ESTestCase; | ||
| 
     | 
||
| public class ElasticInferenceServiceSettingsTests extends ESTestCase { | ||
| 
     | 
||
| public void testEisGatewayURLValidator_Validate_ThrowError_OnMissingURIScheme() { | ||
| expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> new ElasticInferenceServiceSettings.EisGatewayURLValidator().validate("www.missing-scheme-gateway-url.com") | ||
| ); | ||
| } | ||
| 
     | 
||
| public void testEisGatewayURLValidator_Validate_ThrowError_OnWrongURIScheme() { | ||
| expectThrows( | ||
| IllegalArgumentException.class, | ||
| () -> new ElasticInferenceServiceSettings.EisGatewayURLValidator().validate("file://www.missing-scheme-gateway-url.com") | ||
| ); | ||
| } | ||
| 
     | 
||
| public void testEisGatewayURLValidator_Validate_DoesNotThrowError_ForHTTP() { | ||
| var scheme = "http"; | ||
| 
     | 
||
| try { | ||
| new ElasticInferenceServiceSettings.EisGatewayURLValidator().validate(scheme + "://www.valid-gateway-url.com"); | ||
| } catch (Exception e) { | ||
| fail(e, "Should not throw exception for " + "[" + scheme + "]"); | ||
| } | ||
| } | ||
| 
     | 
||
| public void testEisGatewayURLValidator_Validate_DoesNotThrowError_ForHTTPS() { | ||
| var scheme = "https"; | ||
| 
     | 
||
| try { | ||
| new ElasticInferenceServiceSettings.EisGatewayURLValidator().validate(scheme + "://www.valid-gateway-url.com"); | ||
| } catch (Exception e) { | ||
| fail(e, "Should not throw exception for " + "[" + scheme + "]"); | ||
| } | ||
| } | ||
| 
     | 
||
| public void testEisGatewayURLValidator_Validate_DoesNotThrowError_IfURLNull() { | ||
| try { | ||
| new ElasticInferenceServiceSettings.EisGatewayURLValidator().validate(null); | ||
| } catch (Exception e) { | ||
| fail(e, "Should not throw exception for, if eis-gateway URL is null"); | ||
| } | ||
| } | ||
| 
     | 
||
| public void testEisGatewayURLValidator_Validate_DoesNotThrowError_IfURLEmpty() { | ||
| try { | ||
| new ElasticInferenceServiceSettings.EisGatewayURLValidator().validate(""); | ||
| } catch (Exception e) { | ||
| fail(e, "Should not throw exception for, if eis-gateway URL is empty"); | ||
| } | ||
| } | ||
| 
     | 
||
| } | 
  
    
      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.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to write to the logs that EIS is not enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked what gets logged on startup and it feels like it's rather uncommon to log something as specific as this (at least on the
INFOlevel). There are only a few plugins logging, whether they're enabled (on a whole plugin level) like APM and security. But I think it probably doesn't cause any harm to log it onDEBUGlevel, so adding it with Add debug log, whether eis-gateway URL is set or not.