Class: ElasticGraph::GraphQL::QueryDetailsTracker

Inherits:
Struct
  • Object
show all
Defined in:
lib/elastic_graph/graphql/query_details_tracker.rb

Overview

Class used to track details of what happens during a single GraphQL query for the purposes of logging. Here we use ‘Struct` instead of `Data` specifically because it is designed to be mutable.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#datastore_query_client_duration_msObject

Returns the value of attribute datastore_query_client_duration_ms

Returns:

  • (Object)

    the current value of datastore_query_client_duration_ms



17
18
19
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 17

def datastore_query_client_duration_ms
  @datastore_query_client_duration_ms
end

#datastore_query_server_duration_msObject

Returns the value of attribute datastore_query_server_duration_ms

Returns:

  • (Object)

    the current value of datastore_query_server_duration_ms



17
18
19
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 17

def datastore_query_server_duration_ms
  @datastore_query_server_duration_ms
end

#hidden_typesObject

Returns the value of attribute hidden_types

Returns:

  • (Object)

    the current value of hidden_types



17
18
19
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 17

def hidden_types
  @hidden_types
end

#mutexObject

Returns the value of attribute mutex

Returns:

  • (Object)

    the current value of mutex



17
18
19
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 17

def mutex
  @mutex
end

#query_counts_per_datastore_requestObject

Returns the value of attribute query_counts_per_datastore_request

Returns:

  • (Object)

    the current value of query_counts_per_datastore_request



17
18
19
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 17

def query_counts_per_datastore_request
  @query_counts_per_datastore_request
end

#search_index_expressionsObject

Returns the value of attribute search_index_expressions

Returns:

  • (Object)

    the current value of search_index_expressions



17
18
19
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 17

def search_index_expressions
  @search_index_expressions
end

#shard_routing_valuesObject

Returns the value of attribute shard_routing_values

Returns:

  • (Object)

    the current value of shard_routing_values



17
18
19
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 17

def shard_routing_values
  @shard_routing_values
end

Class Method Details

.emptyObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 26

def self.empty
  new(
    hidden_types: ::Set.new,
    shard_routing_values: ::Set.new,
    search_index_expressions: ::Set.new,
    query_counts_per_datastore_request: [],
    datastore_query_server_duration_ms: 0,
    datastore_query_client_duration_ms: 0,
    mutex: ::Thread::Mutex.new
  )
end

Instance Method Details

#record_datastore_queries_for_single_request(queries) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 38

def record_datastore_queries_for_single_request(queries)
  mutex.synchronize do
    shard_routing_values.merge(queries.flat_map { |q| q.shard_routing_values || [] })
    search_index_expressions.merge(queries.map(&:search_index_expression))
    query_counts_per_datastore_request << queries.size
  end
end

#record_datastore_query_duration_ms(client:, server:) ⇒ Object



52
53
54
55
56
57
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 52

def record_datastore_query_duration_ms(client:, server:)
  mutex.synchronize do
    self.datastore_query_client_duration_ms += client
    self.datastore_query_server_duration_ms += server if server
  end
end

#record_hidden_type(type) ⇒ Object



46
47
48
49
50
# File 'lib/elastic_graph/graphql/query_details_tracker.rb', line 46

def record_hidden_type(type)
  mutex.synchronize do
    hidden_types << type
  end
end