skylight 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/skylight/normalizers.rb +2 -1
- data/lib/skylight/normalizers/moped.rb +139 -0
- data/lib/skylight/normalizers/sql.rb +23 -7
- data/lib/skylight/railtie.rb +1 -1
- data/lib/skylight/version.rb +1 -1
- metadata +4 -3
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 54d9a76b353b8d0a2a6fecce094a8a32802a1b9d
         | 
| 4 | 
            +
              data.tar.gz: c773bed69979daa2fe511a1fef1698699aa6ba42
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: ad2f6c9f9edec7ec1417a89faa026cafbb5b36b9adc6e47c35063793178b8ff4bd75d683c404463fb37e0581be526eeeb7443e9df2314be060fd78d9419a51b6
         | 
| 7 | 
            +
              data.tar.gz: f4b98d9d9b50b111b7c5f33ae57343c7985be52bcaa0cced2781c322bc1231b2186dd8f1ffda1a3b9eb098afec2c98e3572ed3492e21c39b4c8693acd3399dc8
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    
    
        data/lib/skylight/normalizers.rb
    CHANGED
    
    
| @@ -0,0 +1,139 @@ | |
| 1 | 
            +
            module Skylight
         | 
| 2 | 
            +
              module Normalizers
         | 
| 3 | 
            +
                class Moped < Normalizer
         | 
| 4 | 
            +
                  register "query.moped"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                  CAT = "db.mongo.query".freeze
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def normalize(trace, name, payload)
         | 
| 9 | 
            +
                    # payload: { prefix: "  MOPED: #{address.resolved}", ops: operations }
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                    # We can sometimes have multiple operations. However, it seems like this only happens when doing things
         | 
| 12 | 
            +
                    # like an insert, followed by a get last error, so we can probably ignore all but the first.
         | 
| 13 | 
            +
                    operation = payload[:ops] ? payload[:ops].first : nil
         | 
| 14 | 
            +
                    type = operation && operation.class.to_s =~ /^Moped::Protocol::(.+)$/ ? $1 : nil
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                    case type
         | 
| 17 | 
            +
                    when "Query"       then normalize_query(operation)
         | 
| 18 | 
            +
                    when "GetMore"     then normalize_get_more(operation)
         | 
| 19 | 
            +
                    when "Insert"      then normalize_insert(operation)
         | 
| 20 | 
            +
                    when "Update"      then normalize_update(operation)
         | 
| 21 | 
            +
                    when "Delete"      then normalize_delete(operation)
         | 
| 22 | 
            +
                    else :skip
         | 
| 23 | 
            +
                    end
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                private
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  def normalize_query(operation)
         | 
| 29 | 
            +
                    title = normalize_title("QUERY", operation)
         | 
| 30 | 
            +
             | 
| 31 | 
            +
                    hash, binds = extract_binds(operation.selector)
         | 
| 32 | 
            +
                    description = hash.to_json
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    annotations = build_annotations(operation)
         | 
| 35 | 
            +
                    annotations[:skip] = operation.skip
         | 
| 36 | 
            +
                    if operation.fields
         | 
| 37 | 
            +
                      annotations[:fields] = operation.fields.select{|k,v| v == 1 }.keys.map(&:to_s)
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
                    annotations[:binds] = binds unless binds.empty?
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                    [CAT, title, description, annotations]
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                  def normalize_get_more(operation)
         | 
| 45 | 
            +
                    title = normalize_title("GET_MORE", operation)
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                    annotations = build_annotations(operation)
         | 
| 48 | 
            +
                    annotations[:limit] = operation.limit
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                    [CAT, title, nil, annotations]
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  def normalize_insert(operation)
         | 
| 54 | 
            +
                    title = normalize_title("INSERT", operation)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    annotations = build_annotations(operation)
         | 
| 57 | 
            +
                    annotations[:count] = operation.documents.count
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    [CAT, title, nil, annotations]
         | 
| 60 | 
            +
                  end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                  def normalize_update(operation)
         | 
| 63 | 
            +
                    title = normalize_title("UPDATE", operation)
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                    selector_hash, selector_binds = extract_binds(operation.selector)
         | 
| 66 | 
            +
                    update_hash, update_binds = extract_binds(operation.update)
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                    description = { selector: selector_hash, update: update_hash }.to_json
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                    annotations = build_annotations(operation)
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                    binds = {}
         | 
| 73 | 
            +
                    binds[:selector] = selector_binds unless selector_binds.empty?
         | 
| 74 | 
            +
                    binds[:update]   = update_binds   unless update_binds.empty?
         | 
| 75 | 
            +
                    annotations[:binds] = binds unless binds.empty?
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                    [CAT, title, description, annotations]
         | 
| 78 | 
            +
                  end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                  def normalize_delete(operation)
         | 
| 81 | 
            +
                    title = normalize_title("DELETE", operation)
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                    hash, binds = extract_binds(operation.selector)
         | 
| 84 | 
            +
                    description = hash.to_json
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                    annotations = build_annotations(operation)
         | 
| 87 | 
            +
                    annotations[:binds] = binds unless binds.empty?
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                    [CAT, title, description, annotations]
         | 
| 90 | 
            +
                  end
         | 
| 91 | 
            +
             | 
| 92 | 
            +
                  def normalize_title(type, operation)
         | 
| 93 | 
            +
                    "#{type} #{operation.collection}"
         | 
| 94 | 
            +
                  end
         | 
| 95 | 
            +
             | 
| 96 | 
            +
                  def build_annotations(operation)
         | 
| 97 | 
            +
                    annotations = {}
         | 
| 98 | 
            +
             | 
| 99 | 
            +
                    if operation.respond_to?(:flags)
         | 
| 100 | 
            +
                      flags = operation.flags.map{|f| flag_name(f) }
         | 
| 101 | 
            +
                      annotations[:flags] = flags unless flags.empty?
         | 
| 102 | 
            +
                    end
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                    annotations
         | 
| 105 | 
            +
                  end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                  # Some flags used by Moped don't map directly to the Mongo docs
         | 
| 108 | 
            +
                  # See http://docs.mongodb.org/meta-driver/latest/legacy/mongodb-wire-protocol/
         | 
| 109 | 
            +
                  FLAG_MAP = {
         | 
| 110 | 
            +
                    tailable: "TailableCursor",
         | 
| 111 | 
            +
                    multi:    "MultiUpdate"
         | 
| 112 | 
            +
                  }
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  def flag_name(flag)
         | 
| 115 | 
            +
                    FLAG_MAP[flag] || flag.to_s.sub(/^[a-z\d]*/) { $&.capitalize }.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }
         | 
| 116 | 
            +
                  end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                  def extract_binds(hash, binds=[])
         | 
| 119 | 
            +
                    hash = hash.dup
         | 
| 120 | 
            +
             | 
| 121 | 
            +
                    hash.each do |k,v|
         | 
| 122 | 
            +
                      if v.is_a?(Hash)
         | 
| 123 | 
            +
                        hash[k] = extract_binds(v, binds)[0]
         | 
| 124 | 
            +
                      else
         | 
| 125 | 
            +
                        binds << stringify(hash[k])
         | 
| 126 | 
            +
                        hash[k] = '?'
         | 
| 127 | 
            +
                      end
         | 
| 128 | 
            +
                    end
         | 
| 129 | 
            +
             | 
| 130 | 
            +
                    [hash, binds]
         | 
| 131 | 
            +
                  end
         | 
| 132 | 
            +
             | 
| 133 | 
            +
                  def stringify(value)
         | 
| 134 | 
            +
                    value.is_a?(Regexp) ? value.inspect : value.to_s
         | 
| 135 | 
            +
                  end
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                end
         | 
| 138 | 
            +
              end
         | 
| 139 | 
            +
            end
         | 
| @@ -17,16 +17,18 @@ module Skylight | |
| 17 17 | 
             
                      title = payload[:name] || "SQL"
         | 
| 18 18 | 
             
                    end
         | 
| 19 19 |  | 
| 20 | 
            -
                     | 
| 21 | 
            -
             | 
| 20 | 
            +
                    binds = payload[:binds]
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    if binds && !binds.empty?
         | 
| 23 | 
            +
                      binds = binds.map { |col, val| val.inspect }
         | 
| 22 24 | 
             
                    end
         | 
| 23 25 |  | 
| 24 | 
            -
                    extracted_title,  | 
| 26 | 
            +
                    extracted_title, sql, binds, error = extract_binds(payload, binds)
         | 
| 25 27 | 
             
                    title = extracted_title if extracted_title
         | 
| 26 28 |  | 
| 27 | 
            -
                    if  | 
| 29 | 
            +
                    if sql
         | 
| 28 30 | 
             
                      annotations = {
         | 
| 29 | 
            -
                        sql:    | 
| 31 | 
            +
                        sql:   sql,
         | 
| 30 32 | 
             
                        binds: binds,
         | 
| 31 33 | 
             
                      }
         | 
| 32 34 | 
             
                    else
         | 
| @@ -35,7 +37,7 @@ module Skylight | |
| 35 37 | 
             
                      }
         | 
| 36 38 | 
             
                    end
         | 
| 37 39 |  | 
| 38 | 
            -
                    [ name, title,  | 
| 40 | 
            +
                    [ name, title, sql, annotations ]
         | 
| 39 41 | 
             
                  end
         | 
| 40 42 |  | 
| 41 43 | 
             
                private
         | 
| @@ -43,7 +45,21 @@ module Skylight | |
| 43 45 | 
             
                    title, sql, binds = SqlLexer::Lexer.bindify(payload[:sql], precalculated)
         | 
| 44 46 | 
             
                    [ title, sql, binds, nil ]
         | 
| 45 47 | 
             
                  rescue
         | 
| 46 | 
            -
                     | 
| 48 | 
            +
                    # Encode this since we may have improperly incoded strings that can't be to_json'ed
         | 
| 49 | 
            +
                    encoded = encode(payload: payload, precalculated: precalculated)
         | 
| 50 | 
            +
                    [ nil, nil, nil, ["sql_parse", encoded.to_json] ]
         | 
| 51 | 
            +
                  end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                  def encode(body)
         | 
| 54 | 
            +
                    if body.is_a?(Hash)
         | 
| 55 | 
            +
                      body.each{|k,v| body[k] = encode(v) }
         | 
| 56 | 
            +
                    elsif body.is_a?(Array)
         | 
| 57 | 
            +
                      body.each_with_index{|v,i| body[i] = encode(v) }
         | 
| 58 | 
            +
                    elsif body.respond_to?(:encoding) && (body.encoding == Encoding::BINARY || !body.valid_encoding?)
         | 
| 59 | 
            +
                      Base64.encode64(body)
         | 
| 60 | 
            +
                    else
         | 
| 61 | 
            +
                      body
         | 
| 62 | 
            +
                    end
         | 
| 47 63 | 
             
                  end
         | 
| 48 64 | 
             
                end
         | 
| 49 65 | 
             
              end
         | 
    
        data/lib/skylight/railtie.rb
    CHANGED
    
    
    
        data/lib/skylight/version.rb
    CHANGED
    
    
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: skylight
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Tilde, Inc.
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2013-12- | 
| 11 | 
            +
            date: 2013-12-10 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: activesupport
         | 
| @@ -55,6 +55,7 @@ files: | |
| 55 55 | 
             
            - lib/skylight/middleware.rb
         | 
| 56 56 | 
             
            - lib/skylight/normalizers.rb
         | 
| 57 57 | 
             
            - lib/skylight/normalizers/default.rb
         | 
| 58 | 
            +
            - lib/skylight/normalizers/moped.rb
         | 
| 58 59 | 
             
            - lib/skylight/normalizers/process_action.rb
         | 
| 59 60 | 
             
            - lib/skylight/normalizers/render_collection.rb
         | 
| 60 61 | 
             
            - lib/skylight/normalizers/render_partial.rb
         | 
| @@ -160,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 160 161 | 
             
                  version: '0'
         | 
| 161 162 | 
             
            requirements: []
         | 
| 162 163 | 
             
            rubyforge_project: 
         | 
| 163 | 
            -
            rubygems_version: 2.1. | 
| 164 | 
            +
            rubygems_version: 2.1.11
         | 
| 164 165 | 
             
            signing_key: 
         | 
| 165 166 | 
             
            specification_version: 4
         | 
| 166 167 | 
             
            summary: Skylight is a ruby application monitoring tool. Currently in closed beta.
         |