aliyun-log 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c29e47df03c69ea213e48e43e272714f950887b5ab8efaa60321e4506b4d4bd
4
- data.tar.gz: fd5dcd273e40f70f93bd69e1fc9dbc392171d90c9881650503c420b18cf0cd5d
3
+ metadata.gz: ba1bcbd83277ca8da27978ecd7a603a205a19c1600b11f359135e2629e6f61c4
4
+ data.tar.gz: d1e731f6b181167ef11004c7c79bbbef9acd290be531a08a24bb6f87134cfaac
5
5
  SHA512:
6
- metadata.gz: 6a4a990ac42f07d0ce44fe018604a5af553f5d53a74cdb0b3abfd9a6b15f891f434bc3fada83afdae815c3bbf5477d72be9520f6926609ec356fe9aa8b6098d5
7
- data.tar.gz: 0addf200ac1e5328fd5fbd4a459cf756a52f0b8ad1bc53f775676340147af385dc8758da2b7b0d63c8285b409820e4ab8778a822d0505172d554e12865ad7567
6
+ metadata.gz: 850989116e4820287e15fbe5361319f1043d4a1c3e7991bab947187bcac2d0114ee9244df26c4c132cd29d400752b4f18a6c0a3bcccaaabdda151858829b19e4
7
+ data.tar.gz: c03afaddd81499c4cb36be357d9894eccf2574fa009afa2d57f7d01e61885534a60b94f4bc2dfaa315e5db0862481225966fc71f27fb8ce1d6a1686284f90e40
@@ -100,6 +100,7 @@ module Aliyun
100
100
  raw_conf = JSON.parse(conf_res)
101
101
  index_conf = raw_conf.deep_dup
102
102
  field_index_types.each do |k, v|
103
+ index_conf['keys'] ||= {}
103
104
  index_conf['keys'][k.to_s] ||= {}
104
105
  index_conf['keys'][k.to_s].merge!(v.as_json)
105
106
  end
@@ -162,11 +162,15 @@ module Aliyun
162
162
  end
163
163
 
164
164
  def count
165
- # @opts[:select] = 'COUNT(*) as count'
166
- _sql = to_sql
167
- sql = "SELECT COUNT(*) as count"
168
- sql += " FROM(#{_sql})" if _sql.present?
169
165
  query = @opts.dup
166
+ if query[:select].blank?
167
+ @opts[:select] = 'COUNT(*) as count'
168
+ sql = to_sql
169
+ else
170
+ _sql = to_sql
171
+ sql = "SELECT COUNT(*) as count"
172
+ sql += " FROM(#{_sql})" if _sql.present?
173
+ end
170
174
  query[:query] = "#{query[:search] || '*'}|#{sql}"
171
175
  res = execute(query)
172
176
  res.dig(0, 'count').to_i
@@ -204,6 +208,7 @@ module Aliyun
204
208
  end
205
209
 
206
210
  def to_sql
211
+ return @opts[:sql] if @opts[:sql].present?
207
212
  opts = @opts.dup
208
213
  sql_query = []
209
214
  sql_query << "WHERE #{opts[:where]}" if opts[:where].present?
@@ -7,6 +7,8 @@ require 'digest'
7
7
  require 'date'
8
8
  require 'zlib'
9
9
 
10
+ require_relative 'utils'
11
+
10
12
  module Aliyun
11
13
  module Log
12
14
  class Request
@@ -16,25 +18,6 @@ module Aliyun
16
18
  @config = config
17
19
  end
18
20
 
19
- def get_resource_path(resources = {})
20
- resources ||= {}
21
- res = '/'
22
- if resources[:logstore]
23
- res = "#{res}logstores"
24
- res = "#{res}/#{resources[:logstore]}" unless resources[:logstore].empty?
25
- end
26
- res = "#{res}/#{resources[:action]}" if resources[:action]
27
- res
28
- end
29
-
30
- def get_request_url(resources = {})
31
- resources ||= {}
32
- url = URI.parse(@config.endpoint)
33
- url.host = "#{resources[:project]}." + url.host if resources[:project]
34
- url.path = get_resource_path(resources)
35
- url.to_s
36
- end
37
-
38
21
  def get(resources, payload = {})
39
22
  do_request('GET', resources, payload)
40
23
  end
@@ -52,10 +35,11 @@ module Aliyun
52
35
  end
53
36
 
54
37
  def do_request(verb, resources, payload)
55
- resource_path = get_resource_path(resources)
38
+ resource_path = Utils.get_resource_path(resources)
39
+ url = Utils.get_request_url(@config.endpoint, resources)
56
40
  request_options = {
57
41
  method: verb,
58
- url: get_request_url(resources),
42
+ url: url,
59
43
  open_timeout: @config.open_timeout,
60
44
  read_timeout: @config.read_timeout
61
45
  }
@@ -75,15 +59,17 @@ module Aliyun
75
59
  response = request.execute do |resp|
76
60
  if resp.code >= 300
77
61
  e = ServerError.new(resp)
78
- logger.error(e.to_s)
62
+ logger.error("#{e.to_s} #{resp.code} #{resp}")
79
63
  raise e
80
64
  else
81
65
  resp.return!
82
66
  end
83
67
  end
84
68
 
85
- logger.debug("Received HTTP response, code: #{response.code}, headers: " \
86
- "#{response.headers}, body: #{response.body.force_encoding('UTF-8')}")
69
+ logger.debug("Received HTTP response, code: #{response.code}, " \
70
+ "url: #{request_options[:url]}, " \
71
+ "method: #{verb}, headers: #{response.headers}, " \
72
+ "body: #{response.body.force_encoding('UTF-8')}")
87
73
 
88
74
  response
89
75
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext'
4
+
5
+ module Aliyun
6
+ module Log
7
+ module Utils
8
+ module_function
9
+ def get_resource_path(resources = {})
10
+ resources ||= {}
11
+ res = '/'
12
+ if resources[:logstore]
13
+ res = "#{res}logstores"
14
+ res = "#{res}/#{resources[:logstore]}" unless resources[:logstore].empty?
15
+ end
16
+ res = "#{res}/#{resources[:action]}" if resources[:action]
17
+ res
18
+ end
19
+
20
+ def get_request_url(endpoint, resources = {})
21
+ resources ||= {}
22
+ url = URI.parse(endpoint)
23
+ url.host = "#{resources[:project]}." + url.host if resources[:project]
24
+ url.path = get_resource_path(resources)
25
+ url.to_s
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Aliyun
4
4
  module Log
5
- VERSION = '0.2.11'
5
+ VERSION = '0.2.12'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aliyun-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yingce Liu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-07 00:00:00.000000000 Z
11
+ date: 2020-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '3.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: webmock
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.0'
117
131
  description: Aliyun Log SDK for Ruby 阿里云日志服务(SLS) Ruby SDK, 目前仅实现基于Restfull部分接口和简单Model映射
118
132
  email:
119
133
  - yingce@live.com
@@ -128,7 +142,6 @@ files:
128
142
  - lib/aliyun/log/common/logging.rb
129
143
  - lib/aliyun/log/config.rb
130
144
  - lib/aliyun/log/logstore.rb
131
- - lib/aliyun/log/logtail.rb
132
145
  - lib/aliyun/log/project.rb
133
146
  - lib/aliyun/log/protobuf.rb
134
147
  - lib/aliyun/log/protocol.rb
@@ -142,6 +155,7 @@ files:
142
155
  - lib/aliyun/log/record/type_casting.rb
143
156
  - lib/aliyun/log/request.rb
144
157
  - lib/aliyun/log/server_error.rb
158
+ - lib/aliyun/log/utils.rb
145
159
  - lib/aliyun/version.rb
146
160
  homepage: https://github.com/yingce/aliyun-log
147
161
  licenses:
@@ -1,13 +0,0 @@
1
- module Aliyun
2
- module Log
3
- class LogTail < Common::AttrStruct
4
- attrs :name, :log_type, :log_path, :file_pattern, :localstore, :time_format,
5
- :log_begin_regex, :regex, :key, :topic_format,
6
- :filterKey, :filter_regex, :file_encoding
7
- def initialize(opts, protocol)
8
- super(opts)
9
- @protocol = protocol
10
- end
11
- end
12
- end
13
- end