couchbase 3.9.0-aarch64-linux-musl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +202 -0
  3. data/README.md +154 -0
  4. data/ext/extconf.rb +0 -0
  5. data/lib/active_support/cache/couchbase_store.rb +407 -0
  6. data/lib/couchbase/3.2/libcouchbase.so +0 -0
  7. data/lib/couchbase/3.3/libcouchbase.so +0 -0
  8. data/lib/couchbase/3.4/libcouchbase.so +0 -0
  9. data/lib/couchbase/4.0/libcouchbase.so +0 -0
  10. data/lib/couchbase/analytics_options.rb +109 -0
  11. data/lib/couchbase/authenticator.rb +80 -0
  12. data/lib/couchbase/binary_collection.rb +145 -0
  13. data/lib/couchbase/binary_collection_options.rb +26 -0
  14. data/lib/couchbase/bucket.rb +173 -0
  15. data/lib/couchbase/cluster.rb +555 -0
  16. data/lib/couchbase/cluster_registry.rb +49 -0
  17. data/lib/couchbase/collection.rb +770 -0
  18. data/lib/couchbase/collection_options.rb +401 -0
  19. data/lib/couchbase/config_profiles.rb +57 -0
  20. data/lib/couchbase/configuration.rb +58 -0
  21. data/lib/couchbase/datastructures/couchbase_list.rb +192 -0
  22. data/lib/couchbase/datastructures/couchbase_map.rb +231 -0
  23. data/lib/couchbase/datastructures/couchbase_queue.rb +161 -0
  24. data/lib/couchbase/datastructures/couchbase_set.rb +145 -0
  25. data/lib/couchbase/datastructures.rb +26 -0
  26. data/lib/couchbase/deprecations.rb +61 -0
  27. data/lib/couchbase/diagnostics.rb +183 -0
  28. data/lib/couchbase/errors.rb +438 -0
  29. data/lib/couchbase/fork_hooks.rb +41 -0
  30. data/lib/couchbase/get_replica_strategy.rb +89 -0
  31. data/lib/couchbase/json_transcoder.rb +41 -0
  32. data/lib/couchbase/key_value_scan.rb +119 -0
  33. data/lib/couchbase/libcouchbase.rb +6 -0
  34. data/lib/couchbase/logger.rb +87 -0
  35. data/lib/couchbase/management/analytics_index_manager.rb +1160 -0
  36. data/lib/couchbase/management/bucket_manager.rb +479 -0
  37. data/lib/couchbase/management/collection_manager.rb +515 -0
  38. data/lib/couchbase/management/collection_query_index_manager.rb +247 -0
  39. data/lib/couchbase/management/query_index_manager.rb +671 -0
  40. data/lib/couchbase/management/scope_search_index_manager.rb +267 -0
  41. data/lib/couchbase/management/search_index_manager.rb +649 -0
  42. data/lib/couchbase/management/user_manager.rb +639 -0
  43. data/lib/couchbase/management/view_index_manager.rb +332 -0
  44. data/lib/couchbase/management.rb +31 -0
  45. data/lib/couchbase/metrics/logging_meter.rb +108 -0
  46. data/lib/couchbase/metrics/logging_value_recorder.rb +50 -0
  47. data/lib/couchbase/metrics/meter.rb +27 -0
  48. data/lib/couchbase/metrics/noop_meter.rb +30 -0
  49. data/lib/couchbase/metrics/noop_value_recorder.rb +27 -0
  50. data/lib/couchbase/metrics/value_recorder.rb +25 -0
  51. data/lib/couchbase/mutation_state.rb +65 -0
  52. data/lib/couchbase/options.rb +3097 -0
  53. data/lib/couchbase/protostellar/binary_collection.rb +55 -0
  54. data/lib/couchbase/protostellar/bucket.rb +59 -0
  55. data/lib/couchbase/protostellar/client.rb +97 -0
  56. data/lib/couchbase/protostellar/cluster.rb +182 -0
  57. data/lib/couchbase/protostellar/collection.rb +156 -0
  58. data/lib/couchbase/protostellar/connect_options.rb +63 -0
  59. data/lib/couchbase/protostellar/error_handling.rb +204 -0
  60. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_pb.rb +54 -0
  61. data/lib/couchbase/protostellar/generated/admin/analytics/v1/analytics_services_pb.rb +51 -0
  62. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_pb.rb +42 -0
  63. data/lib/couchbase/protostellar/generated/admin/bucket/v1/bucket_services_pb.rb +51 -0
  64. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_pb.rb +38 -0
  65. data/lib/couchbase/protostellar/generated/admin/collection/v1/collection_services_pb.rb +52 -0
  66. data/lib/couchbase/protostellar/generated/admin/query/v1/query_pb.rb +42 -0
  67. data/lib/couchbase/protostellar/generated/admin/query/v1/query_services_pb.rb +55 -0
  68. data/lib/couchbase/protostellar/generated/admin/search/v1/search_pb.rb +51 -0
  69. data/lib/couchbase/protostellar/generated/admin/search/v1/search_services_pb.rb +67 -0
  70. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_pb.rb +31 -0
  71. data/lib/couchbase/protostellar/generated/analytics/v1/analytics_services_pb.rb +40 -0
  72. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_pb.rb +51 -0
  73. data/lib/couchbase/protostellar/generated/internal/hooks/v1/hooks_services_pb.rb +54 -0
  74. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_pb.rb +46 -0
  75. data/lib/couchbase/protostellar/generated/internal/xdcr/v1/xdcr_services_pb.rb +56 -0
  76. data/lib/couchbase/protostellar/generated/kv/v1/kv_pb.rb +74 -0
  77. data/lib/couchbase/protostellar/generated/kv/v1/kv_services_pb.rb +93 -0
  78. data/lib/couchbase/protostellar/generated/query/v1/query_pb.rb +35 -0
  79. data/lib/couchbase/protostellar/generated/query/v1/query_services_pb.rb +40 -0
  80. data/lib/couchbase/protostellar/generated/routing/v2/routing_pb.rb +26 -0
  81. data/lib/couchbase/protostellar/generated/routing/v2/routing_services_pb.rb +43 -0
  82. data/lib/couchbase/protostellar/generated/search/v1/search_pb.rb +78 -0
  83. data/lib/couchbase/protostellar/generated/search/v1/search_services_pb.rb +41 -0
  84. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_pb.rb +36 -0
  85. data/lib/couchbase/protostellar/generated/transactions/v1/transactions_services_pb.rb +66 -0
  86. data/lib/couchbase/protostellar/generated/view/v1/view_pb.rb +30 -0
  87. data/lib/couchbase/protostellar/generated/view/v1/view_services_pb.rb +39 -0
  88. data/lib/couchbase/protostellar/generated.rb +9 -0
  89. data/lib/couchbase/protostellar/management/bucket_manager.rb +67 -0
  90. data/lib/couchbase/protostellar/management/collection_manager.rb +94 -0
  91. data/lib/couchbase/protostellar/management/collection_query_index_manager.rb +124 -0
  92. data/lib/couchbase/protostellar/management/query_index_manager.rb +112 -0
  93. data/lib/couchbase/protostellar/management.rb +24 -0
  94. data/lib/couchbase/protostellar/request.rb +79 -0
  95. data/lib/couchbase/protostellar/request_behaviour.rb +42 -0
  96. data/lib/couchbase/protostellar/request_generator/admin/bucket.rb +124 -0
  97. data/lib/couchbase/protostellar/request_generator/admin/collection.rb +96 -0
  98. data/lib/couchbase/protostellar/request_generator/admin/query.rb +132 -0
  99. data/lib/couchbase/protostellar/request_generator/admin.rb +24 -0
  100. data/lib/couchbase/protostellar/request_generator/kv.rb +488 -0
  101. data/lib/couchbase/protostellar/request_generator/query.rb +133 -0
  102. data/lib/couchbase/protostellar/request_generator/search.rb +403 -0
  103. data/lib/couchbase/protostellar/request_generator.rb +26 -0
  104. data/lib/couchbase/protostellar/response_converter/admin/bucket.rb +55 -0
  105. data/lib/couchbase/protostellar/response_converter/admin/collection.rb +42 -0
  106. data/lib/couchbase/protostellar/response_converter/admin/query.rb +59 -0
  107. data/lib/couchbase/protostellar/response_converter/admin.rb +24 -0
  108. data/lib/couchbase/protostellar/response_converter/kv.rb +151 -0
  109. data/lib/couchbase/protostellar/response_converter/query.rb +84 -0
  110. data/lib/couchbase/protostellar/response_converter/search.rb +136 -0
  111. data/lib/couchbase/protostellar/response_converter.rb +26 -0
  112. data/lib/couchbase/protostellar/retry/action.rb +38 -0
  113. data/lib/couchbase/protostellar/retry/orchestrator.rb +61 -0
  114. data/lib/couchbase/protostellar/retry/reason.rb +67 -0
  115. data/lib/couchbase/protostellar/retry/strategies/best_effort.rb +49 -0
  116. data/lib/couchbase/protostellar/retry/strategies/fail_fast.rb +33 -0
  117. data/lib/couchbase/protostellar/retry/strategies.rb +27 -0
  118. data/lib/couchbase/protostellar/retry.rb +28 -0
  119. data/lib/couchbase/protostellar/scope.rb +61 -0
  120. data/lib/couchbase/protostellar/timeout_defaults.rb +30 -0
  121. data/lib/couchbase/protostellar/timeouts.rb +83 -0
  122. data/lib/couchbase/protostellar.rb +29 -0
  123. data/lib/couchbase/query_options.rb +122 -0
  124. data/lib/couchbase/railtie.rb +47 -0
  125. data/lib/couchbase/raw_binary_transcoder.rb +39 -0
  126. data/lib/couchbase/raw_json_transcoder.rb +40 -0
  127. data/lib/couchbase/raw_string_transcoder.rb +42 -0
  128. data/lib/couchbase/scope.rb +272 -0
  129. data/lib/couchbase/search_options.rb +1744 -0
  130. data/lib/couchbase/subdoc.rb +293 -0
  131. data/lib/couchbase/tracing/noop_span.rb +29 -0
  132. data/lib/couchbase/tracing/noop_tracer.rb +29 -0
  133. data/lib/couchbase/tracing/request_span.rb +34 -0
  134. data/lib/couchbase/tracing/request_tracer.rb +28 -0
  135. data/lib/couchbase/tracing/threshold_logging_span.rb +112 -0
  136. data/lib/couchbase/tracing/threshold_logging_tracer.rb +231 -0
  137. data/lib/couchbase/transcoder_flags.rb +64 -0
  138. data/lib/couchbase/utils/generic_logger_adapter.rb +40 -0
  139. data/lib/couchbase/utils/hdr_histogram.rb +55 -0
  140. data/lib/couchbase/utils/observability.rb +263 -0
  141. data/lib/couchbase/utils/observability_constants.rb +200 -0
  142. data/lib/couchbase/utils/stdlib_logger_adapter.rb +65 -0
  143. data/lib/couchbase/utils/time.rb +71 -0
  144. data/lib/couchbase/utils.rb +23 -0
  145. data/lib/couchbase/version.rb +25 -0
  146. data/lib/couchbase/view_options.rb +67 -0
  147. data/lib/couchbase.rb +32 -0
  148. data/lib/rails/generators/couchbase/config/config_generator.rb +29 -0
  149. metadata +228 -0
@@ -0,0 +1,332 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020-2021 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require "couchbase/errors"
18
+ require "couchbase/options"
19
+
20
+ module Couchbase
21
+ module Management
22
+ module Options
23
+ module View
24
+ # Options for {ViewIndexManager#get_design_document}
25
+ class GetDesignDocument < Couchbase::Options::Base
26
+ # Creates an instance of options for {ViewIndexManager#get_design_document}
27
+ #
28
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
29
+ # @param [Symbol, nil] retry_strategy ignored by this operation
30
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
31
+ #
32
+ # @yieldparam [GetDesignDocument]
33
+ def initialize(timeout: nil,
34
+ retry_strategy: nil,
35
+ parent_span: nil)
36
+ super
37
+ yield self if block_given?
38
+ end
39
+
40
+ # @api private
41
+ DEFAULT = new.freeze
42
+ end
43
+
44
+ # Options for {ViewIndexManager#get_all_design_documents}
45
+ class GetAllDesignDocuments < Couchbase::Options::Base
46
+ # Creates an instance of options for {ViewIndexManager#get_all_design_documents}
47
+ #
48
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
49
+ # @param [Symbol, nil] retry_strategy ignored by this operation
50
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
51
+ #
52
+ # @yieldparam [GetAllDesignDocuments]
53
+ def initialize(timeout: nil,
54
+ retry_strategy: nil,
55
+ parent_span: nil)
56
+ super
57
+ yield self if block_given?
58
+ end
59
+
60
+ # @api private
61
+ DEFAULT = new.freeze
62
+ end
63
+
64
+ # Options for {ViewIndexManager#upsert_design_document}
65
+ class UpsertDesignDocument < Couchbase::Options::Base
66
+ # Creates an instance of options for {ViewIndexManager#upsert_design_document}
67
+ #
68
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
69
+ # @param [Symbol, nil] retry_strategy ignored by this operation
70
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
71
+ #
72
+ # @yieldparam [UpsertDesignDocument]
73
+ def initialize(timeout: nil,
74
+ retry_strategy: nil,
75
+ parent_span: nil)
76
+ super
77
+ yield self if block_given?
78
+ end
79
+
80
+ # @api private
81
+ DEFAULT = new.freeze
82
+ end
83
+
84
+ # Options for {ViewIndexManager#drop_design_document}
85
+ class DropDesignDocument < Couchbase::Options::Base
86
+ # Creates an instance of options for {ViewIndexManager#drop_design_document}
87
+ #
88
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
89
+ # @param [Symbol, nil] retry_strategy ignored by this operation
90
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
91
+ #
92
+ # @yieldparam [DropDesignDocument]
93
+ def initialize(timeout: nil,
94
+ retry_strategy: nil,
95
+ parent_span: nil)
96
+ super
97
+ yield self if block_given?
98
+ end
99
+
100
+ # @api private
101
+ DEFAULT = new.freeze
102
+ end
103
+
104
+ # Options for {ViewIndexManager#publish_design_document}
105
+ class PublishDesignDocument < Couchbase::Options::Base
106
+ # Creates an instance of options for {ViewIndexManager#publish_design_document}
107
+ #
108
+ # @param [Integer, #in_milliseconds, nil] timeout the time in milliseconds allowed for the operation to complete
109
+ # @param [Symbol, nil] retry_strategy ignored by this operation
110
+ # @param [Span, nil] parent_span if set holds the parent span, that should be used for this request
111
+ #
112
+ # @yieldparam [PublishDesignDocument]
113
+ def initialize(timeout: nil,
114
+ retry_strategy: nil,
115
+ parent_span: nil)
116
+ super
117
+ yield self if block_given?
118
+ end
119
+
120
+ # @api private
121
+ DEFAULT = new.freeze
122
+ end
123
+ end
124
+ end
125
+
126
+ # The View Index Manager interface contains the means for managing design documents used for views.
127
+ #
128
+ # A design document belongs to either the "development" or "production" namespace. A development document has a name
129
+ # that starts with "dev_". This is an implementation detail we've chosen to hide from consumers of this API.
130
+ # Document names presented to the user (returned from the "get" and "get all" methods, for example) always have the
131
+ # "dev_" prefix stripped.
132
+ #
133
+ # Whenever the user passes a design document name to any method of this API, the user may refer to the document
134
+ # using the "dev_" prefix regardless of whether the user is referring to a development document or production
135
+ # document. The "dev_" prefix is always stripped from user input, and the actual document name passed to the server
136
+ # is determined by the "namespace" argument.
137
+ #
138
+ # All methods (except publish) have a required "namespace" argument indicating whether the operation targets a
139
+ # development document or a production document. The type of this argument is [Symbol] with allowed values
140
+ # +:production+ and +:development+.
141
+ #
142
+ # @deprecated Views are deprecated in Couchbase Server 7.0+, and will be removed from a future server version.
143
+ # Views are not compatible with the Magma storage engine. Instead of views, use indexes and queries using the
144
+ # Index Service (GSI) and the Query Service (SQL++).
145
+ class ViewIndexManager
146
+ alias inspect to_s
147
+
148
+ # @return [String] name of the bucket
149
+ attr_accessor :bucket_name
150
+
151
+ # @param [Couchbase::Backend] backend
152
+ # @param [String] bucket_name
153
+ # @param [Observability::Wrapper] observability wrapper
154
+ def initialize(backend, bucket_name, observability)
155
+ @backend = backend
156
+ @bucket_name = bucket_name
157
+ @observability = observability
158
+ end
159
+
160
+ # Fetches a design document from the server
161
+ #
162
+ # @param [String] name the name of the design document
163
+ # @param [:production, :development] namespace the namespace
164
+ # @param [Options::View::GetDesignDocument] options
165
+ #
166
+ # @return [DesignDocument]
167
+ #
168
+ # @raise [Error::DesignDocumentNotFound]
169
+ def get_design_document(name, namespace, options = Options::View::GetDesignDocument::DEFAULT)
170
+ @observability.record_operation(Observability::OP_VM_GET_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
171
+ resp = @backend.view_index_get(@bucket_name, name, namespace, options.timeout, obs_handler)
172
+ extract_design_document(resp)
173
+ end
174
+ end
175
+
176
+ # Fetches all design documents from the server
177
+ #
178
+ # @param [:production, :development] namespace the namespace
179
+ # @param [Options::View::GetAllDesignDocuments] options
180
+ #
181
+ # @return [Array<DesignDocument>]
182
+ def get_all_design_documents(namespace, options = Options::View::GetAllDesignDocuments::DEFAULT)
183
+ @observability.record_operation(Observability::OP_VM_GET_ALL_DESIGN_DOCUMENTS, options.parent_span, self, :views) do |obs_handler|
184
+ resp = @backend.view_index_get_all(@bucket_name, namespace, options.timeout, obs_handler)
185
+ resp.map do |entry|
186
+ extract_design_document(entry)
187
+ end
188
+ end
189
+ end
190
+
191
+ # Updates or inserts the design document
192
+ #
193
+ # @param [DesignDocument] document
194
+ # @param [:production, :development] namespace the namespace
195
+ # @param [Options::View::UpsertDesignDocument] options
196
+ #
197
+ # @return [void]
198
+ def upsert_design_document(document, namespace, options = Options::View::UpsertDesignDocument::DEFAULT)
199
+ @observability.record_operation(Observability::OP_VM_UPSERT_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
200
+ @backend.view_index_upsert(@bucket_name, {
201
+ name: document.name,
202
+ views: document.views.map do |name, view|
203
+ {
204
+ name: name,
205
+ map: view.map_function,
206
+ reduce: view.reduce_function,
207
+ }
208
+ end,
209
+ }, namespace, options.timeout, obs_handler)
210
+ end
211
+ end
212
+
213
+ # Removes the design document
214
+ #
215
+ # @param [String] name design document name
216
+ # @param [:production, :development] namespace the namespace
217
+ # @param [Options::View::DropDesignDocument] options
218
+ #
219
+ # @return [void]
220
+ #
221
+ # @raise [Error::DesignDocumentNotFound]
222
+ def drop_design_document(name, namespace, options = Options::View::DropDesignDocument::DEFAULT)
223
+ @observability.record_operation(Observability::OP_VM_DROP_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
224
+ @backend.view_index_drop(@bucket_name, name, namespace, options.timeout, obs_handler)
225
+ end
226
+ end
227
+
228
+ # Publishes the design document.
229
+ #
230
+ # This method is equivalent to getting a document from the development namespace and upserting
231
+ # it to the production namespace.
232
+ #
233
+ # @param [String] name design document name
234
+ # @param [Options::View::PublishDesignDocument] options
235
+ #
236
+ # @return [void]
237
+ #
238
+ # @raise [ArgumentError]
239
+ # @raise [Error::DesignDocumentNotFound]
240
+ def publish_design_document(name, options = Options::View::PublishDesignDocument::DEFAULT)
241
+ @observability.record_operation(Observability::OP_VM_PUBLISH_DESIGN_DOCUMENT, options.parent_span, self, :views) do |obs_handler|
242
+ document = get_design_document(name, :development,
243
+ Options::View::GetDesignDocument.new(timeout: options.timeout, parent_span: obs_handler.op_span))
244
+ upsert_design_document(document, :production,
245
+ Options::View::UpsertDesignDocument.new(timeout: options.timeout, parent_span: obs_handler.op_span))
246
+ end
247
+ end
248
+
249
+ # @api private
250
+ # @deprecated use {Options::View::GetDesignDocument} instead
251
+ GetDesignDocumentOptions = Options::View::GetDesignDocument
252
+
253
+ # @api private
254
+ # @deprecated use {Options::View::GetAllDesignDocuments} instead
255
+ GetAllDesignDocumentsOptions = Options::View::GetAllDesignDocuments
256
+
257
+ # @api private
258
+ # @deprecated use {Options::View::UpsertDesignDocument} instead
259
+ UpsertDesignDocumentOptions = Options::View::UpsertDesignDocument
260
+
261
+ # @api private
262
+ # @deprecated use {Options::View::DropDesignDocument} instead
263
+ DropDesignDocumentOptions = Options::View::DropDesignDocument
264
+
265
+ # @api private
266
+ # @deprecated use {Options::View::PublishDesignDocument} instead
267
+ PublishDesignDocumentOptions = Options::View::PublishDesignDocument
268
+
269
+ private
270
+
271
+ def extract_design_document(resp)
272
+ DesignDocument.new do |design_document|
273
+ design_document.name = resp[:name]
274
+ design_document.namespace = resp[:namespace]
275
+ resp[:views].each do |name, view_resp|
276
+ design_document.views[name] = View.new(view_resp[:map], view_resp[:reduce])
277
+ end
278
+ end
279
+ end
280
+ end
281
+
282
+ class View
283
+ # @return [String] name of the view
284
+ attr_accessor :view
285
+
286
+ # @return [String] map function in javascript as String
287
+ attr_accessor :map_function
288
+ alias map map_function
289
+
290
+ # @return [String] reduce function in javascript as String
291
+ attr_accessor :reduce_function
292
+ alias reduce reduce_function
293
+
294
+ # @return [Boolean] true if map function is defined
295
+ def has_map?
296
+ !@map_function.nil?
297
+ end
298
+
299
+ # @return [Boolean] true if map function is defined
300
+ def has_reduce?
301
+ !@reduce_function.nil?
302
+ end
303
+
304
+ # @param [String] map
305
+ # @param [String] reduce
306
+ #
307
+ # @yieldparam [View] self
308
+ def initialize(map = nil, reduce = nil)
309
+ @map_function = map
310
+ @reduce_function = reduce
311
+ yield self if block_given?
312
+ end
313
+ end
314
+
315
+ class DesignDocument
316
+ # @return [String] name
317
+ attr_accessor :name
318
+
319
+ # @return [Hash<String => View>]
320
+ attr_accessor :views
321
+
322
+ # @return [:production, :development]
323
+ attr_accessor :namespace
324
+
325
+ # @yieldparam [DesignDocument] self
326
+ def initialize
327
+ @views = {}
328
+ yield self if block_given?
329
+ end
330
+ end
331
+ end
332
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020-2021 Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Couchbase
18
+ # This namespace includes manager classes to control cluster resources and perform maintenance operations.
19
+ module Management
20
+ end
21
+ end
22
+
23
+ require "couchbase/management/analytics_index_manager"
24
+ require "couchbase/management/bucket_manager"
25
+ require "couchbase/management/collection_manager"
26
+ require "couchbase/management/query_index_manager"
27
+ require "couchbase/management/collection_query_index_manager"
28
+ require "couchbase/management/search_index_manager"
29
+ require "couchbase/management/scope_search_index_manager"
30
+ require "couchbase/management/user_manager"
31
+ require "couchbase/management/view_index_manager"
@@ -0,0 +1,108 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative "logging_value_recorder"
18
+ require_relative "meter"
19
+ require_relative "noop_meter"
20
+ require "couchbase/utils/observability_constants"
21
+ require "couchbase/utils/stdlib_logger_adapter"
22
+ require "couchbase/logger"
23
+
24
+ require "concurrent/map"
25
+ require "concurrent/timer_task"
26
+
27
+ module Couchbase
28
+ module Metrics
29
+ class LoggingMeter < Meter
30
+ # @api private
31
+ DEFAULT_EMIT_INTERVAL = 600_000 # milliseconds
32
+
33
+ def initialize(emit_interval: nil)
34
+ super()
35
+ @emit_interval = emit_interval || DEFAULT_EMIT_INTERVAL
36
+ @value_recorders = {
37
+ Observability::ATTR_VALUE_SERVICE_KV => Concurrent::Map.new,
38
+ Observability::ATTR_VALUE_SERVICE_QUERY => Concurrent::Map.new,
39
+ Observability::ATTR_VALUE_SERVICE_VIEWS => Concurrent::Map.new,
40
+ Observability::ATTR_VALUE_SERVICE_SEARCH => Concurrent::Map.new,
41
+ Observability::ATTR_VALUE_SERVICE_ANALYTICS => Concurrent::Map.new,
42
+ Observability::ATTR_VALUE_SERVICE_MANAGEMENT => Concurrent::Map.new,
43
+ }
44
+
45
+ # TODO(DC): Find better solution for logging
46
+ @logger = Couchbase.logger || Logger.new($stdout, Utils::StdlibLoggerAdapter.map_spdlog_level(Couchbase.log_level))
47
+ @task = Concurrent::TimerTask.new(execution_interval: @emit_interval / 1_000.0) do
48
+ report = create_report
49
+ return if report.empty?
50
+
51
+ @logger.info("Metrics: #{report.to_json}")
52
+ rescue StandardError => e
53
+ @logger.debug("Failed to log metrics: #{e.message}")
54
+ end
55
+ end
56
+
57
+ def value_recorder(name, tags)
58
+ return NoopMeter::VALUE_RECORDER_INSTANCE unless name == Observability::METER_NAME_OPERATION_DURATION
59
+
60
+ operation_name = tags[Observability::ATTR_OPERATION_NAME]
61
+ service = tags[Observability::ATTR_SERVICE]
62
+
63
+ return NoopMeter::VALUE_RECORDER_INSTANCE if operation_name.nil? || service.nil?
64
+
65
+ @value_recorders[service].put_if_absent(
66
+ operation_name,
67
+ LoggingValueRecorder.new(
68
+ operation_name: operation_name,
69
+ service: service,
70
+ ),
71
+ )
72
+
73
+ @value_recorders[service][operation_name]
74
+ end
75
+
76
+ def create_report
77
+ operations = {}
78
+ @value_recorders.each do |service, recorders|
79
+ recorders.each_key do |operation_name|
80
+ recorder = recorders[operation_name]
81
+ operation_report = recorder.report_and_reset
82
+ if operation_report
83
+ operations[service] ||= {}
84
+ operations[service][operation_name] = operation_report
85
+ end
86
+ end
87
+ end
88
+ if operations.empty?
89
+ {}
90
+ else
91
+ {
92
+ meta: {
93
+ emit_interval_ms: @emit_interval,
94
+ },
95
+ operations: operations,
96
+ }
97
+ end
98
+ end
99
+
100
+ def close
101
+ @task.shutdown
102
+ @value_recorders.each_value do |operation_map|
103
+ operation_map.each_value(&:close)
104
+ end
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative "value_recorder"
18
+ require "couchbase/utils/hdr_histogram"
19
+
20
+ module Couchbase
21
+ module Metrics
22
+ class LoggingValueRecorder < ValueRecorder
23
+ attr_reader :operation_name
24
+ attr_reader :service
25
+
26
+ def initialize(operation_name:, service:)
27
+ super()
28
+ @operation_name = operation_name
29
+ @service = service
30
+ @histogram = Utils::HdrHistogram.new(
31
+ lowest_discernible_value: 1, # 1 microsecond
32
+ highest_trackable_value: 30_000_000, # 30 seconds
33
+ significant_figures: 3,
34
+ )
35
+ end
36
+
37
+ def record_value(value)
38
+ @histogram.record_value(value)
39
+ end
40
+
41
+ def report_and_reset
42
+ @histogram.report_and_reset
43
+ end
44
+
45
+ def close
46
+ @histogram.close
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Couchbase
18
+ module Metrics
19
+ class Meter
20
+ def value_recorder(name, tags)
21
+ raise NotImplementedError, "The meter does not implement #value_recorder"
22
+ end
23
+
24
+ def close; end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative 'meter'
18
+ require_relative 'noop_value_recorder'
19
+
20
+ module Couchbase
21
+ module Metrics
22
+ class NoopMeter < Meter
23
+ def value_recorder(_name, _tags)
24
+ VALUE_RECORDER_INSTANCE
25
+ end
26
+
27
+ VALUE_RECORDER_INSTANCE = NoopValueRecorder.new.freeze
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require_relative 'value_recorder'
18
+
19
+ module Couchbase
20
+ module Metrics
21
+ class NoopValueRecorder < ValueRecorder
22
+ def record_value(_value)
23
+ # Do nothing
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2025-Present Couchbase, Inc.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ module Couchbase
18
+ module Metrics
19
+ class ValueRecorder
20
+ def record_value(value)
21
+ raise NotImplementedError, "The value recorder does not implement #record_value"
22
+ end
23
+ end
24
+ end
25
+ end