- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Reduce cardinality #5
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
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            14 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      d227308
              
                Update to golang 1.13
              
              
                glennslaven e35e648
              
                Bucket content-type to reduce metric cardinality
              
              
                glennslaven 5b9992f
              
                Force hostname to lowercase
              
              
                glennslaven a8efb05
              
                Force content-type to lowercase to avoid missing metrics
              
              
                glennslaven 5b81f72
              
                Threat hyphens as no hostname
              
              
                glennslaven 378bd6f
              
                Make the nil/empty/- check the first thing we do when sanitizing the …
              
              
                glennslaven f84fc96
              
                Sanitize status code values to only valid HTTP status code values
              
              
                glennslaven 2401719
              
                Don't label metrics by status code by default
              
              
                glennslaven 220c15f
              
                Typo
              
              
                glennslaven f08e20a
              
                Be more restrictive with the list of valid status codes
              
              
                glennslaven f9b4632
              
                Validate hostname to match alphanumeric, dot & hyphen only.
              
              
                glennslaven 289f5da
              
                Check for trailing slash on image content type
              
              
                glennslaven b59fd5f
              
                Allow label names to be sanitized as well as the values
              
              
                glennslaven c2bcf6a
              
                Typo
              
              
                glennslaven 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 | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module github.com/section-io/module-metrics | ||
|  | ||
| go 1.12 | ||
| go 1.13 | ||
|  | ||
| require ( | ||
| github.com/pkg/errors v0.8.1 | ||
|  | ||
  
    
      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 | 
|---|---|---|
|  | @@ -6,6 +6,7 @@ import ( | |
| "fmt" | ||
| "io" | ||
| "os" | ||
| "regexp" | ||
| "strconv" | ||
| "strings" | ||
| "syscall" | ||
|  | @@ -16,31 +17,65 @@ import ( | |
| const maxLabelValueLength = 80 | ||
|  | ||
| var ( | ||
| filepath string | ||
| filepath string | ||
| isValidHostHeader = regexp.MustCompile(`^[a-z0-9.-]+$`).MatchString | ||
| ) | ||
|  | ||
| func sanitizeValue(label string, value interface{}) string { | ||
| func sanitizeLabel(label string, value interface{}) (string, string) { | ||
|  | ||
| // Convert to a string, no matter what underlying type it is | ||
| var labelValue string | ||
| if value != nil { | ||
| labelValue = fmt.Sprintf("%v", value) | ||
| if value == nil || value == "" || value == "-" { | ||
| return label, "" | ||
| } | ||
|  | ||
| // Convert to a string, no matter what underlying type it is | ||
| labelValue := fmt.Sprintf("%v", value) | ||
| labelValue = strings.TrimSpace(labelValue) | ||
|  | ||
| switch label { | ||
| case "content_type": | ||
| labelValue = strings.Split(labelValue, ";")[0] | ||
| label = "content_type_bucket" | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In hingsight, I don't think I like this as much as keeping  | ||
|  | ||
| labelValue = strings.ToLower(labelValue) | ||
| if strings.HasPrefix(labelValue, "image/") { | ||
| labelValue = "image" | ||
| } else if strings.HasPrefix(labelValue, "text/html") { | ||
| labelValue = "html" | ||
| } else if strings.HasPrefix(labelValue, "text/css") { | ||
| labelValue = "css" | ||
| } else if strings.Contains(labelValue, "javascript") { | ||
| labelValue = "javascript" | ||
| } else { | ||
| labelValue = "other" | ||
| } | ||
|  | ||
| case "hostname": | ||
| labelValue = strings.Split(labelValue, ":")[0] | ||
| } | ||
| labelValue = strings.ToLower(labelValue) | ||
|         
                  glennslaven marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| if !isValidHostHeader(labelValue) { | ||
| labelValue = "" | ||
| } | ||
|  | ||
| labelValue = strings.TrimSpace(labelValue) | ||
| case "status": | ||
| statusInt, _ := strconv.Atoi(labelValue) | ||
| switch { | ||
| case statusInt >= 100 && statusInt <= 103: | ||
| case statusInt >= 200 && statusInt <= 208: | ||
| case statusInt >= 300 && statusInt <= 308: | ||
| case statusInt >= 400 && statusInt <= 431: | ||
| case statusInt == 499: | ||
| case statusInt >= 500 && statusInt <= 511: | ||
| default: | ||
| // If it matches any of the above cases, do nothing (leave labelValue as is) | ||
| // otherwise set to blank | ||
| labelValue = "" | ||
| } | ||
| } | ||
|  | ||
| if len(labelValue) > maxLabelValueLength { | ||
| labelValue = labelValue[0:maxLabelValueLength] | ||
| } | ||
|  | ||
| return labelValue | ||
| return label, labelValue | ||
| } | ||
|  | ||
| func getBytes(l map[string]interface{}) int { | ||
|  | @@ -117,8 +152,9 @@ func StartReader(file io.Reader, output io.Writer, errorWriter io.Writer) { | |
| } else { | ||
| labelValues := map[string]string{} | ||
|  | ||
| for _, label := range p8sLabels { | ||
| labelValues[label] = sanitizeValue(label, logline[label]) | ||
| for _, label := range logFieldNames { | ||
| label, value := sanitizeLabel(label, logline[label]) | ||
| labelValues[label] = value | ||
| } | ||
| addRequest(labelValues, getBytes(logline)) | ||
| } | ||
|  | ||
  
    
      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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  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.