chili_logger 0.1.2 → 0.1.3

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: 61d8df3241131a360ca82cbc122ccde86989a46b8b67227e9f686136b792115b
4
- data.tar.gz: 5250e4ba9b5f27b8ed56ef0d6bb619b306783c390c17d27ee34dada2e29a862b
3
+ metadata.gz: fc07fd046be4d08dd0bf3e972ab83f5db6468186ca7d41c2ec868dd698f308d7
4
+ data.tar.gz: 850be7ee87e9e30fd203236d274755d02c75976ec8a1e467a94c83c50fd9894c
5
5
  SHA512:
6
- metadata.gz: 00fbfa5e42ac2ec4190665535d7e30d6faf47528a0be7924714a15a6dda60dcf65d9c629ddec9b1201d69164201df4cde86fd07a3191b4fabad189ba65046ebe
7
- data.tar.gz: e1a02abebf9d9f437d707647d94c26bd03f22853029f3053c94cf05ec7ebaa1920482bf0cef6eb6499cdae9f4301dfe17c361a38387e3e7c447de47d64fbf3a9
6
+ metadata.gz: 322027d12c0e96b227d67e0c60cca022c65945da4477fd8f7dfac8749dd194111db11cd5a8ca09e44334807ab949b510bf8b169ea0258ba1472a854d7bb5d00c
7
+ data.tar.gz: c79b0c42deadf14c4119ab6084151977c0e31f829ce9d3323cdf92502d9a79f9977cbfe4ed944cded842c6f2b48825774afce8390cce1ef40589e49423aa7631
@@ -1,4 +1,30 @@
1
1
  continue
2
+ sqs_queue_attrs.attributes['ApproximateNumberOfMessages'].to_i.positive?
3
+ sqs_queue_attrs.attributes['ApproximateNumberOfMessages'].to_i
4
+ sqs_queue_attrs
5
+ continue
6
+ sqs_queue_attrs
7
+ continue
8
+ sqs_queue_attrs
9
+ continue
10
+ sqs_queue_attrs
11
+ continue
12
+ remaining_msgs
13
+ remaining_msgs.positive?
14
+ continue
15
+ remaining_msgs.positive?
16
+ remaining_msgs
17
+ continue
18
+ remaining_msgs
19
+ continue
20
+ remaining_msgs
21
+ quit
22
+ remaining_msgs
23
+ messages
24
+ quit
25
+ msgs.count
26
+ msgs
27
+ continue
2
28
  @sqs_config[:region]
3
29
  @sqs_config['region']
4
30
  @sqs_config
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chili_logger (0.1.2)
4
+ chili_logger (0.1.3)
5
5
  aws-sdk-secretsmanager (~> 1.36.0)
6
6
  aws-sdk-sqs (~> 1.30.0)
7
7
  bunny
data/README.md CHANGED
@@ -49,6 +49,7 @@ ChiliLogger is a gem developed by Chiligum Creatives for internal use. It is use
49
49
  * [update_modified_records](#update_modified_records)
50
50
  * [add_modified_record](#add_modified_record)
51
51
  * [clear_log_info](#clear_log_info)
52
+ * [Republishing Unpublished Logs](#republishing-unpublished-logs)
52
53
  * [Snippets For Quicker Logging](#snippets-for-quicker-logging)
53
54
  * [Papertrail Optional Use](#papertrail-optional-use)
54
55
  * [Logging Transactions in HTP Requests](#logging-transactions-in-http-requests)
@@ -104,9 +105,11 @@ So if you are going to change anything in ChiliLogger, you have to keep this in
104
105
 
105
106
  ![ChiliLogger usual Flow](assets/images/chili-logger-flow.png)
106
107
 
108
+ Every time we use ChiliLogger to publish a log, it will try to publish it to what has been configured as its `msg_broker`. If the msg_broker is down or some other unexpected error occurs, ChiliLogger will send the log and error message to what has been configured as its `fallback_broker`. This way, no logs are lost and [ChiliLogger can later try to republish these unpublished logs](#republishing-unpublished-logs).
109
+
107
110
  For the time being, only `RabbitMQ` is supported as the main message broker. Only `AWS SQS` is available as a fallback broker.
108
111
 
109
- If both the main message broker and the fallback message broker are down, ChiliLogger wil discard the log to keep the application running without raising any error. That's because raising errors would make the app crash and make it impossible to be used while the brokers are down.
112
+ If both the main message broker and the fallback message broker are down, ChiliLogger wil discard the log to keep the application running without raising any error. That's because raising errors would make the app crash and make it impossible to be used while the brokers are down. For this reason, it is important to use a main message broker and a fallback broker with high availability.
110
113
 
111
114
 
112
115
  ### Anatomy of a Chiligum Log
@@ -809,6 +812,19 @@ current_log.errors
809
812
  sets user, desc, and main_content to their default values.
810
813
 
811
814
 
815
+ ### Republishing Unpublished Logs
816
+ >
817
+ > This functionality was introduced in version 0.1.2 of ChiliLogger. If you are using ChiliLogger 0.0.12 or below, you must first upgrade it.
818
+ >
819
+
820
+ [As previously explained](#overview), if logs can't be published to the main `message broker`, then these unpublished logs will be sent to the `fallback broker`. We can easily tell ChiliLogger to try and republish these logs any time, just by running the following:
821
+
822
+ ```ruby
823
+ ChiliLogger.instance.republish_unpublished_logs
824
+ ```
825
+ When running the above snippet, ChiliLogger will fetch the unpublished logs and try to republish them to the main `message broker`. If the main message broker is still unavailable, ChiliLogger will once again send the logs to `fallback broker`.
826
+
827
+
812
828
  ## Snippets for Quicker Logging
813
829
  Following is a series of snippets for quickly setting up some basic logging functionality.
814
830
  **Please notice that the snippets in this section use the [paper_trail gem](https://github.com/paper-trail-gem/paper_trail/blob/v9.2.0/README.md#1c-basic-usage) for improving logs. Its use is optional, but recommended.**
@@ -32,12 +32,12 @@ class ChiliLogger
32
32
  def fetch_messages
33
33
  return if ChiliLogger.instance.deactivated
34
34
 
35
- remaining_msgs = num_of_msgs_in_queue
36
35
  messages = []
36
+ remaining_msgs = num_of_msgs_in_queue
37
+ return messages unless remaining_msgs.positive?
37
38
 
38
39
  @poller.poll do |sqs_msg|
39
- log = JSON.parse(sqs_msg.body)['body']['log']
40
- messages << { log: log, fallback_broker_msg: sqs_msg }
40
+ messages << { fallback_broker_msg: sqs_msg, log: JSON.parse(sqs_msg.body)['body']['log'] }
41
41
 
42
42
  remaining_msgs -= 1
43
43
  throw :stop_polling if remaining_msgs <= 0 # prevents infinite loop
@@ -66,8 +66,8 @@ class ChiliLogger
66
66
  end
67
67
 
68
68
  def num_of_msgs_in_queue
69
- sqs_queue_attrs = @sqs.get_queue_attributes(queue_url: queue_url(@queue_name), attribute_names: ['All']).attributes
70
- sqs_queue_attrs['ApproximateNumberOfMessages'].to_i
69
+ sqs_queue_attrs = @sqs.get_queue_attributes(queue_url: queue_url(@queue_name), attribute_names: ['All'])
70
+ sqs_queue_attrs.attributes['ApproximateNumberOfMessages'].to_i
71
71
  end
72
72
 
73
73
  def sqs_config(custom_config)
@@ -1,3 +1,3 @@
1
1
  class ChiliLogger
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.3'.freeze
3
3
  end
@@ -19,7 +19,6 @@ class ChiliLogger
19
19
 
20
20
  private
21
21
 
22
- # rubocop:disable Metrics/MethodLength
23
22
  # Use this code snippet in your app.
24
23
  # If you need more information about configurations or implementing the sample code, visit the AWS docs:
25
24
  # https://aws.amazon.com/developers/getting-started/ruby/
@@ -29,34 +28,11 @@ class ChiliLogger
29
28
  # See https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html
30
29
  # We rethrow the exception by default.
31
30
  get_secret_value_response = @client.get_secret_value(secret_id: secret_name)
32
- rescue Aws::SecretsManager::Errors::DecryptionFailure => _e
33
- # Secrets Manager can't decrypt the protected secret text using the provided KMS key.
34
- # Deal with the exception here, and/or rethrow at your discretion.
35
- raise
36
- rescue Aws::SecretsManager::Errors::InternalServiceError => _e
37
- # An error occurred on the server side.
38
- # Deal with the exception here, and/or rethrow at your discretion.
39
- raise
40
- rescue Aws::SecretsManager::Errors::InvalidParameterException => _e
41
- # You provided an invalid value for a parameter.
42
- # Deal with the exception here, and/or rethrow at your discretion.
43
- raise
44
- rescue Aws::SecretsManager::Errors::InvalidRequestException => _e
45
- # You provided a parameter value that is not valid for the current state of the resource.
46
- # Deal with the exception here, and/or rethrow at your discretion.
47
- raise
48
- rescue Aws::SecretsManager::Errors::ResourceNotFoundException => _e
49
- # We can't find the resource that you asked for.
50
- # Deal with the exception here, and/or rethrow at your discretion.
51
- raise
52
- else
53
- # This block is ran if there were no exceptions.
54
31
 
55
32
  # Decrypts secret using the associated KMS CMK.
56
33
  # Depending on whether the secret is a string or binary, one of these fields will be populated.
57
34
  get_secret_value_response.secret_string || Base64.decode64(get_secret_value_response.secret_binary)
58
35
  end
59
- # rubocop:enable Metrics/MethodLength
60
36
  end
61
37
  end
62
38
  end
@@ -16,6 +16,7 @@ class ChiliLogger
16
16
 
17
17
  def republish
18
18
  unpub_logs = @logging_error_handler.fetch_unpublished_logs
19
+
19
20
  unpub_logs.each do |unpub_log|
20
21
  fallback_broker_msg = unpub_log[:fallback_broker_msg]
21
22
  log = unpub_log[:log]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chili_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - lucas sandeville
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-sqs