-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmultiple.lua
More file actions
79 lines (65 loc) · 1.85 KB
/
Copy pathmultiple.lua
File metadata and controls
79 lines (65 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
-- Run local dockers if needed for testing
--
-- Mysql:
-- docker run --rm --publish 3306:3306 --env MYSQL_ALLOW_EMPTY_PASSWORD=true mysql
-- Redis:
-- docker run --rm --publish 6379:6379 redis
local http = require('http')
local redis = require('redis')
local mysql = require('mysql')
-- An example to hit some external service
local http_client = nil
local redis_client = nil
local mysql_client = nil
local http_endpoint = os.getenv("HTTP_SERVER") or "http://google.com"
local redis_endpoint = os.getenv("REDIS_SERVER") or "localhost:6379"
local mysql_endpoint = os.getenv("MYSQL_SERVER") or "root@tcp(localhost:3306)/"
function init()
local o = http.Options()
o.Headers = { ["Hello"] = "World" }
o.DiscardResponse = true
http_client, err = http.New(o)
if err ~= nil then
Log:Errorf("http error %v", err)
return err
end
local o = redis.Options()
o.Target = redis_endpoint
local redis, err = redis.New(o)
if err ~= nil then
Log:Errorf("redis %v", err)
return err
end
redis_client = redis.Client
local o = mysql.Options()
o.Target = mysql_endpoint
local mysql, err = mysql.New(o)
if err ~= nil then
Log:Errorf("mysql %v", err)
return err
end
mysql_client = mysql.DB
return nil
end
function tick()
LG:BeginCustomMetrics("foo_custom_metric")
-- http call
resp, err = http_client:Do("GET",
"http://google.com/",nil,"")
if err then
Log:Errorf("http error: %v", err)
end
-- redis call
local cmd = redis_client:IncrBy(LG:Context(), "foo", 2)
if cmd:Err() ~= nil then
Log:Errorf("redis increment failed: %v", cmd:Err())
end
-- mysql call
local r, err = mysql_client:Query("SELECT 1")
if err then
Log:Errorf("mysql error %v\n", err)
end
r:Close()
LG:EndCustomMetrics("foo_custom_metric")
return
end