Class: Wavefront::Writer::Api

Inherits:
Core
  • Object
show all
Defined in:
lib/wavefront-sdk/writers/api.rb

Overview

Send points direct to Wavefront’s API. This requires an endpoint, a token, and HTTPS egress.

Points are sent in batches of BATCH_SIZE. We attempt to make a summary of how many points are sent or rejected, but it’s quantized by the batch size.

TODO I think this needs a composite response. It makes one or more API calls depending on the amount of metrics to be sent, and the CLI needs to know if there was anything other than a 200. Options are to return the first failure when it happens, or to try all the chunks and return the last non-200, or the highest numbered return code, or some other indication of failure.

Constant Summary collapse

BATCH_SIZE =
100

Instance Attribute Summary

Attributes inherited from Core

#calling_class, #conn, #creds, #logger, #opts, #summary

Instance Method Summary collapse

Methods inherited from Core

#chunk_size, #do_write, #hash_to_wf, #initialize, #log_invalid_point, #prefix_points, #respond, #screen_points, #valid_point?, #write

Methods included from Validators

#uuid?, #wf_account_id?, #wf_alert_id?, #wf_alert_severity?, #wf_apitoken_id?, #wf_aws_external_id?, #wf_cloudintegration_id?, #wf_dashboard_id?, #wf_derivedmetric_id?, #wf_distribution?, #wf_distribution_count?, #wf_distribution_interval?, #wf_distribution_values?, #wf_epoch?, #wf_event_id?, #wf_granularity?, #wf_ingestionpolicy_id?, #wf_integration_id?, #wf_link_id?, #wf_link_template?, #wf_maintenance_window_id?, #wf_message_id?, #wf_metric_name?, #wf_metricspolicy_id?, #wf_monitoredapplication_id?, #wf_monitoredcluster_id?, #wf_ms_ts?, #wf_name?, #wf_notificant_id?, #wf_permission?, #wf_point?, #wf_point_tag?, #wf_point_tags?, #wf_proxy_id?, #wf_role_id?, #wf_sampling_value?, #wf_savedsearch_entity?, #wf_savedsearch_id?, #wf_serviceaccount_id?, #wf_source_id?, #wf_spansamplingpolicy_id?, #wf_string?, #wf_tag?, #wf_trace?, #wf_ts?, #wf_user_id?, #wf_usergroup_id?, #wf_value?, #wf_version?, #wf_webhook_id?

Constructor Details

This class inherits a constructor from Wavefront::Writer::Core

Instance Method Details

#api_pathObject



30
31
32
# File 'lib/wavefront-sdk/writers/api.rb', line 30

def api_path
  '/report'
end

#openObject



26
27
28
# File 'lib/wavefront-sdk/writers/api.rb', line 26

def open
  @conn = Wavefront::ApiCaller.new(self, creds, opts)
end

#send_point(body) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/wavefront-sdk/writers/api.rb', line 46

def send_point(body)
  _send_point(body)
  true
rescue StandardError => e
  summary.unsent += body.size
  logger.log('WARNING: failed to send point(s).')
  logger.log(e.to_s, :debug)
  false
end

#validate_credentials(creds) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wavefront-sdk/writers/api.rb', line 34

def validate_credentials(creds)
  unless creds.key?(:endpoint) && creds[:endpoint]
    raise(Wavefront::Exception::CredentialError,
          'credentials must contain API endpoint')
  end

  return true if creds.key?(:token) && creds[:token]

  raise(Wavefront::Exception::CredentialError,
        'credentials must contain API token')
end