Class: LogStash::Outputs::Http
- Inherits:
-
Base
- Object
- Base
- LogStash::Outputs::Http
- Includes:
- PluginMixins::HttpClient
- Defined in:
- lib/logstash/outputs/http.rb
Constant Summary collapse
- VALID_METHODS =
["put", "post", "patch", "delete", "get", "head"]
Instance Method Summary collapse
- #close ⇒ Object
-
#multi_receive(events) ⇒ Object
def register.
-
#receive(event, async_type = :background) ⇒ Object
Once we no longer need to support Logstash < 2.2 (pre-ng-pipeline) We don’t need to handle :background style requests.
- #register ⇒ Object
Instance Method Details
#close ⇒ Object
149 150 151 |
# File 'lib/logstash/outputs/http.rb', line 149 def close client.close end |
#multi_receive(events) ⇒ Object
def register
92 93 94 95 |
# File 'lib/logstash/outputs/http.rb', line 92 def multi_receive(events) events.each {|event| receive(event, :parallel)} client.execute! end |
#receive(event, async_type = :background) ⇒ Object
Once we no longer need to support Logstash < 2.2 (pre-ng-pipeline) We don’t need to handle :background style requests
We use :background style requests for Logstash < 2.2 because before the microbatching pipeline performance is greatly improved by having some degree of async behavior.
In Logstash 2.2 and after things are much simpler, we just run each batch in parallel This will make performance much easier to reason about, and more importantly let us guarantee that if multi_receive returns all items have been sent.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/logstash/outputs/http.rb', line 106 def receive(event, async_type=:background) body = event_body(event) # Block waiting for a token token = @request_tokens.pop if async_type == :background # Send the request url = event.sprintf(@url) headers = event_headers(event) # Create an async request request = client.send(async_type).send(@http_method, url, :body => body, :headers => headers) request.on_complete do # Make sure we return the token to the pool @request_tokens << token if async_type == :background end request.on_success do |response| if response.code < 200 || response.code > 299 log_failure( "Encountered non-200 HTTP code #{200}", :response_code => response.code, :url => url, :event => event) end end request.on_failure do |exception| log_failure("Could not fetch URL", :url => url, :method => @http_method, :body => body, :headers => headers, :message => exception., :class => exception.class.name, :backtrace => exception.backtrace ) end request.call if async_type == :background end |
#register ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/logstash/outputs/http.rb', line 67 def register # Handle this deprecated option. TODO: remove the option @ssl_certificate_validation = @verify_ssl if @verify_ssl @http_method = @http_method.to_sym # We count outstanding requests with this queue # This queue tracks the requests to create backpressure # When this queue is empty no new requests may be sent, # tokens must be added back by the client on success @request_tokens = SizedQueue.new(@pool_max) @pool_max.times {|t| @request_tokens << true } @requests = Array.new if @content_type.nil? case @format when "form" ; @content_type = "application/x-www-form-urlencoded" when "json" ; @content_type = "application/json" when "message" ; @content_type = "text/plain" end end validate_format! end |