Skip to content

Commit 5136f27

Browse files
committed
version 0.4.0
1 parent 07c91af commit 5136f27

File tree

4 files changed

+49
-3
lines changed

4 files changed

+49
-3
lines changed

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 0.4.0
2+
* restclient retries request on the following status code - [issue #10](https://github.com/yokawasa/azure-log-analytics-data-collector/issues/10)
3+
* 429 - Too Many Requests
4+
* 500 - Internal Server Error
5+
* 503 - Service Unavailable
6+
17
## 0.3.0
28
* Enhance log type validation: check not only alpha but also numeric, underscore, and character length (may not exceed 100) - [issue #11](https://github.com/yokawasa/azure-log-analytics-data-collector/issues/11)
39

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@
33
[Azure Log Analytics Data Collector API](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-collector-api) Client Libraries for Ruby. The repository was originally created for multiple programming languages, but it was refactored as a dedicated one for Ruby client. Python and PHP client libraries were moved to [azure-log-analytics-data-colloector-python](https://github.com/yokawasa/azure-log-analytics-data-collector-python) and [azure-log-analytics-data-colloector-php](https://github.com/yokawasa/azure-log-analytics-data-collector-php) respectively.
44

55

6+
## Retry policy
7+
8+
The client internal leverage [rest-client] to send HTTP request to the API. The client library retries request using the rest-client on the following status code (which is [recommended action](https://docs.microsoft.com/en-us/azure/azure-monitor/platform/data-collector-api)).
9+
* `429` - Too Many Requests
10+
* `500` - Internal Server Error
11+
* `503` - Service Unavailable
12+
13+
By default, the client library retres for a total of `3` times, sleeping `5 sec` between retries. The number of retries and sleeping time between retries can be changed with `set_retries` in the client class.
14+
15+
```ruby
16+
def set_retries(max_retries, retry_sleep_period)
17+
@max_retries = max_retries
18+
@retry_sleep_period = retry_sleep_period
19+
end
20+
```
21+
622
## Installation
723
```bash
824
gem install azure-loganalytics-datacollector-api

lib/azure/loganalytics/datacollectorapi/client.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ module Datacollectorapi
88

99
class Client
1010

11+
DEFAUT_MAX_RETRIES = 3.freeze
12+
DEFAULT_RETRY_SLEEP_PERIOD = 5.freeze
13+
1114
def initialize (customer_id, shared_key, endpoint ='ods.opinsights.azure.com')
1215
require 'rest-client'
1316
require 'json'
@@ -19,6 +22,9 @@ def initialize (customer_id, shared_key, endpoint ='ods.opinsights.azure.com')
1922
@shared_key = shared_key
2023
@endpoint = endpoint
2124
@default_azure_resource_id = ''
25+
26+
@max_retries = DEFAUT_MAX_RETRIES
27+
@retry_sleep_period = DEFAULT_RETRY_SLEEP_PERIOD
2228
end
2329

2430
def post_data(log_type, json_records, record_timestamp ='', azure_resource_id ='' )
@@ -40,8 +46,21 @@ def post_data(log_type, json_records, record_timestamp ='', azure_resource_id ='
4046
'time-generated-field' => record_timestamp
4147
}
4248

43-
res = RestClient.post( uri, body, headers)
44-
res
49+
retries = 0
50+
begin
51+
res = RestClient.post( uri, body, headers)
52+
res
53+
rescue => e
54+
c = e.response.code.to_i
55+
if c == 429 || c == 500 || c==503
56+
if retries < @max_retries
57+
retries += 1
58+
sleep(@retry_sleep_period)
59+
retry
60+
end
61+
end
62+
raise e
63+
end
4564
end
4665

4766
def set_proxy(proxy='')
@@ -51,6 +70,11 @@ def set_proxy(proxy='')
5170
def set_default_azure_resoruce_id(azure_resource_id)
5271
@default_azure_resource_id = azure_resource_id
5372
end
73+
74+
def set_retres(max_retries, retry_sleep_period)
75+
@max_retries = max_retries
76+
@retry_sleep_period = retry_sleep_period
77+
end
5478

5579
def self.is_success(res)
5680
return (res.code == 200) ? true : false
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Azure
22
module Loganalytics
33
module Datacollectorapi
4-
VERSION = "0.3.0"
4+
VERSION = "0.4.0"
55
end
66
end
77
end

0 commit comments

Comments
 (0)