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 +4 -4
- data/lib/aliyun/log/record/persistence.rb +1 -0
- data/lib/aliyun/log/record/relation.rb +9 -4
- data/lib/aliyun/log/request.rb +10 -24
- data/lib/aliyun/log/utils.rb +29 -0
- data/lib/aliyun/version.rb +1 -1
- metadata +17 -3
- data/lib/aliyun/log/logtail.rb +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba1bcbd83277ca8da27978ecd7a603a205a19c1600b11f359135e2629e6f61c4
|
4
|
+
data.tar.gz: d1e731f6b181167ef11004c7c79bbbef9acd290be531a08a24bb6f87134cfaac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 850989116e4820287e15fbe5361319f1043d4a1c3e7991bab947187bcac2d0114ee9244df26c4c132cd29d400752b4f18a6c0a3bcccaaabdda151858829b19e4
|
7
|
+
data.tar.gz: c03afaddd81499c4cb36be357d9894eccf2574fa009afa2d57f7d01e61885534a60b94f4bc2dfaa315e5db0862481225966fc71f27fb8ce1d6a1686284f90e40
|
@@ -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?
|
data/lib/aliyun/log/request.rb
CHANGED
@@ -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:
|
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},
|
86
|
-
"#{
|
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
|
data/lib/aliyun/version.rb
CHANGED
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.
|
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-
|
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:
|
data/lib/aliyun/log/logtail.rb
DELETED
@@ -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
|