scraper.go 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package aerospikereceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/aerospikereceiver"
  4. import (
  5. "context"
  6. "crypto/tls"
  7. "fmt"
  8. "net"
  9. "strconv"
  10. "time"
  11. as "github.com/aerospike/aerospike-client-go/v6"
  12. "go.opentelemetry.io/collector/component"
  13. "go.opentelemetry.io/collector/consumer"
  14. "go.opentelemetry.io/collector/pdata/pcommon"
  15. "go.opentelemetry.io/collector/pdata/pmetric"
  16. "go.opentelemetry.io/collector/receiver"
  17. "go.opentelemetry.io/collector/receiver/scrapererror"
  18. "go.uber.org/zap"
  19. "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/aerospikereceiver/internal/metadata"
  20. )
  21. // aerospikeReceiver is a metrics receiver using the Aerospike interface to collect
  22. type aerospikeReceiver struct {
  23. config *Config
  24. consumer consumer.Metrics
  25. clientFactory clientFactoryFunc
  26. client Aerospike
  27. mb *metadata.MetricsBuilder
  28. logger *zap.SugaredLogger
  29. }
  30. // clientFactoryFunc creates an Aerospike connection to the given host and port
  31. type clientFactoryFunc func() (Aerospike, error)
  32. // newAerospikeReceiver creates a new aerospikeReceiver connected to the endpoint provided in cfg
  33. //
  34. // If the host or port can't be parsed from endpoint, an error is returned.
  35. func newAerospikeReceiver(params receiver.CreateSettings, cfg *Config, consumer consumer.Metrics) (*aerospikeReceiver, error) {
  36. var err error
  37. var tlsCfg *tls.Config
  38. if cfg.TLS != nil {
  39. tlsCfg, err = cfg.TLS.LoadTLSConfig()
  40. if err != nil {
  41. return nil, fmt.Errorf("%w: %s", errFailedTLSLoad, err.Error())
  42. }
  43. }
  44. host, portStr, err := net.SplitHostPort(cfg.Endpoint)
  45. if err != nil {
  46. return nil, fmt.Errorf("%w: %s", errBadEndpoint, err.Error())
  47. }
  48. port, err := strconv.ParseInt(portStr, 10, 32)
  49. if err != nil {
  50. return nil, fmt.Errorf("%w: %s", errBadPort, err.Error())
  51. }
  52. ashost := as.NewHost(host, int(port))
  53. ashost.TLSName = cfg.TLSName
  54. sugaredLogger := params.Logger.Sugar()
  55. return &aerospikeReceiver{
  56. logger: sugaredLogger,
  57. config: cfg,
  58. consumer: consumer,
  59. clientFactory: func() (Aerospike, error) {
  60. conf := &clientConfig{
  61. host: ashost,
  62. username: cfg.Username,
  63. password: string(cfg.Password),
  64. timeout: cfg.Timeout,
  65. logger: sugaredLogger,
  66. collectClusterMetrics: cfg.CollectClusterMetrics,
  67. tls: tlsCfg,
  68. }
  69. return newASClient(
  70. conf,
  71. nodeGetterFactory,
  72. )
  73. },
  74. mb: metadata.NewMetricsBuilder(cfg.MetricsBuilderConfig, params),
  75. }, nil
  76. }
  77. func (r *aerospikeReceiver) start(_ context.Context, _ component.Host) error {
  78. r.logger.Debug("executing start")
  79. client, err := r.clientFactory()
  80. if err != nil {
  81. client = nil
  82. r.logger.Warn("initial client creation failed: %w", err) // .Sugar().Warnf("initial client creation failed: %w", err)
  83. }
  84. r.client = client
  85. return nil
  86. }
  87. func (r *aerospikeReceiver) shutdown(_ context.Context) error {
  88. r.logger.Debug("executing close")
  89. if r.client != nil {
  90. r.client.Close()
  91. }
  92. return nil
  93. }
  94. // scrape scrapes both Node and Namespace metrics from the provided Aerospike node.
  95. // If CollectClusterMetrics is true, it then scrapes every discovered node
  96. func (r *aerospikeReceiver) scrape(_ context.Context) (pmetric.Metrics, error) {
  97. r.logger.Debug("beginning scrape")
  98. errs := &scrapererror.ScrapeErrors{}
  99. if r.client == nil {
  100. var err error
  101. r.logger.Debug("client is nil, attempting to create a new client")
  102. r.client, err = r.clientFactory()
  103. if err != nil {
  104. r.client = nil
  105. addPartialIfError(errs, fmt.Errorf("client creation failed: %w", err))
  106. return r.mb.Emit(), errs.Combine()
  107. }
  108. }
  109. now := pcommon.NewTimestampFromTime(time.Now().UTC())
  110. client := r.client
  111. info := client.Info()
  112. for _, nodeInfo := range info {
  113. r.emitNode(nodeInfo, now, errs)
  114. }
  115. r.scrapeNamespaces(client, now, errs)
  116. return r.mb.Emit(), errs.Combine()
  117. }
  118. // emitNode records node metrics and emits the resource. If statistics are missing in INFO, nothing is recorded
  119. func (r *aerospikeReceiver) emitNode(info map[string]string, now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) {
  120. r.logger.Debugf("emitNode len(info): %v", len(info))
  121. for k, v := range info {
  122. switch k {
  123. case "client_connections":
  124. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionOpenDataPoint(now, v, metadata.AttributeConnectionTypeClient))
  125. case "fabric_connections":
  126. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionOpenDataPoint(now, v, metadata.AttributeConnectionTypeFabric))
  127. case "heartbeat_connections":
  128. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionOpenDataPoint(now, v, metadata.AttributeConnectionTypeHeartbeat))
  129. case "client_connections_closed":
  130. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionCountDataPoint(now, v, metadata.AttributeConnectionTypeClient, metadata.AttributeConnectionOpClose))
  131. case "client_connections_opened":
  132. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionCountDataPoint(now, v, metadata.AttributeConnectionTypeClient, metadata.AttributeConnectionOpOpen))
  133. case "fabric_connections_closed":
  134. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionCountDataPoint(now, v, metadata.AttributeConnectionTypeFabric, metadata.AttributeConnectionOpClose))
  135. case "fabric_connections_opened":
  136. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionCountDataPoint(now, v, metadata.AttributeConnectionTypeFabric, metadata.AttributeConnectionOpOpen))
  137. case "heartbeat_connections_closed":
  138. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionCountDataPoint(now, v, metadata.AttributeConnectionTypeHeartbeat, metadata.AttributeConnectionOpClose))
  139. case "heartbeat_connections_opened":
  140. addPartialIfError(errs, r.mb.RecordAerospikeNodeConnectionCountDataPoint(now, v, metadata.AttributeConnectionTypeHeartbeat, metadata.AttributeConnectionOpOpen))
  141. case "system_free_mem_pct":
  142. addPartialIfError(errs, r.mb.RecordAerospikeNodeMemoryFreeDataPoint(now, v))
  143. case "query_tracked":
  144. addPartialIfError(errs, r.mb.RecordAerospikeNodeQueryTrackedDataPoint(now, v))
  145. }
  146. }
  147. rb := r.mb.NewResourceBuilder()
  148. rb.SetAerospikeNodeName(info["node"])
  149. r.mb.EmitForResource(metadata.WithResource(rb.Emit()))
  150. r.logger.Debug("finished emitNode")
  151. }
  152. // scrapeNamespaces records metrics for all namespaces on a node
  153. // The given client is used to collect namespace metrics, which is connected to a single node
  154. func (r *aerospikeReceiver) scrapeNamespaces(client Aerospike, now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) {
  155. r.logger.Debug("scraping namespaces")
  156. nInfo := client.NamespaceInfo()
  157. r.logger.Debugf("scrapeNamespaces len(nInfo): %v", len(nInfo))
  158. for node, nsMap := range nInfo {
  159. for nsName, nsStats := range nsMap {
  160. nsStats["node"] = node
  161. nsStats["name"] = nsName
  162. r.emitNamespace(nsStats, now, errs)
  163. }
  164. }
  165. }
  166. // emitNamespace emits a namespace resource with its name as resource attribute
  167. func (r *aerospikeReceiver) emitNamespace(info map[string]string, now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) {
  168. r.logger.Debugf("emitNamespace len(info): %v", len(info))
  169. for k, v := range info {
  170. switch k {
  171. // Capacity
  172. case "device_available_pct":
  173. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceDiskAvailableDataPoint(now, v))
  174. case "memory_free_pct":
  175. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceMemoryFreeDataPoint(now, v))
  176. // Memory usage
  177. case "memory_used_data_bytes":
  178. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceMemoryUsageDataPoint(now, v, metadata.AttributeNamespaceComponentData))
  179. case "memory_used_index_bytes":
  180. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceMemoryUsageDataPoint(now, v, metadata.AttributeNamespaceComponentIndex))
  181. case "memory_used_sindex_bytes":
  182. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceMemoryUsageDataPoint(now, v, metadata.AttributeNamespaceComponentSecondaryIndex))
  183. case "memory_used_set_index_bytes":
  184. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceMemoryUsageDataPoint(now, v, metadata.AttributeNamespaceComponentSetIndex))
  185. // Scans
  186. case "scan_aggr_abort":
  187. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeAggregation, metadata.AttributeScanResultAbort))
  188. case "scan_aggr_complete":
  189. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeAggregation, metadata.AttributeScanResultComplete))
  190. case "scan_aggr_error":
  191. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeAggregation, metadata.AttributeScanResultError))
  192. case "scan_basic_abort":
  193. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeBasic, metadata.AttributeScanResultAbort))
  194. case "scan_basic_complete":
  195. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeBasic, metadata.AttributeScanResultComplete))
  196. case "scan_basic_error":
  197. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeBasic, metadata.AttributeScanResultError))
  198. case "scan_ops_bg_abort":
  199. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeOpsBackground, metadata.AttributeScanResultAbort))
  200. case "scan_ops_bg_complete":
  201. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeOpsBackground, metadata.AttributeScanResultComplete))
  202. case "scan_ops_bg_error":
  203. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeOpsBackground, metadata.AttributeScanResultError))
  204. case "scan_udf_bg_abort":
  205. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeUdfBackground, metadata.AttributeScanResultAbort))
  206. case "scan_udf_bg_complete":
  207. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeUdfBackground, metadata.AttributeScanResultComplete))
  208. case "scan_udf_bg_error":
  209. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceScanCountDataPoint(now, v, metadata.AttributeScanTypeUdfBackground, metadata.AttributeScanResultError))
  210. // Pre Aerospike 6.0 query metrics. These were always done on secondary indexes, otherwise they were counted as a scan.
  211. case "query_aggr_abort":
  212. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  213. case "query_aggr_complete":
  214. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  215. case "query_aggr_error":
  216. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  217. case "query_basic_abort":
  218. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  219. case "query_basic_complete":
  220. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  221. case "query_basic_error":
  222. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  223. case "query_ops_bg_abort":
  224. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  225. case "query_ops_bg_complete":
  226. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  227. case "query_ops_bg_error":
  228. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  229. case "query_udf_bg_abort":
  230. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  231. case "query_udf_bg_complete":
  232. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  233. case "query_udf_bg_error":
  234. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  235. // PI queries
  236. case "pi_query_aggr_abort":
  237. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultAbort))
  238. case "pi_query_aggr_complete":
  239. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultComplete))
  240. case "pi_query_aggr_error":
  241. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultError))
  242. case "pi_query_long_basic_abort":
  243. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeLongBasic, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultAbort))
  244. case "pi_query_long_basic_complete":
  245. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeLongBasic, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultComplete))
  246. case "pi_query_long_basic_error":
  247. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeLongBasic, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultError))
  248. case "pi_query_ops_bg_abort":
  249. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultAbort))
  250. case "pi_query_ops_bg_basic_complete":
  251. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultComplete))
  252. case "pi_query_ops_bg_basic_error":
  253. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultError))
  254. case "pi_query_short_basic_timeout":
  255. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeShortBasic, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultTimeout))
  256. case "pi_query_short_basic_complete":
  257. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeShortBasic, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultComplete))
  258. case "pi_query_short_basic_error":
  259. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeShortBasic, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultError))
  260. case "pi_query_udf_bg_abort":
  261. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultAbort))
  262. case "pi_query_udf_bg_complete":
  263. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultComplete))
  264. case "pi_query_udf_bg_error":
  265. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypePrimary, metadata.AttributeQueryResultError))
  266. // SI queries
  267. case "si_query_aggr_abort":
  268. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  269. case "si_query_aggr_complete":
  270. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  271. case "si_query_aggr_error":
  272. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeAggregation, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  273. case "si_query_long_basic_abort":
  274. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeLongBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  275. case "si_query_long_basic_complete":
  276. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeLongBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  277. case "si_query_long_basic_error":
  278. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeLongBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  279. case "si_query_ops_bg_abort":
  280. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  281. case "si_query_ops_bg_basic_complete":
  282. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  283. case "si_query_ops_bg_basic_error":
  284. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeOpsBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  285. case "si_query_short_basic_timeout":
  286. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeShortBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultTimeout))
  287. case "si_query_short_basic_complete":
  288. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeShortBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  289. case "si_query_short_basic_error":
  290. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeShortBasic, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  291. case "si_query_udf_bg_abort":
  292. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultAbort))
  293. case "si_query_udf_bg_complete":
  294. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultComplete))
  295. case "si_query_udf_bg_error":
  296. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceQueryCountDataPoint(now, v, metadata.AttributeQueryTypeUdfBackground, metadata.AttributeIndexTypeSecondary, metadata.AttributeQueryResultError))
  297. // GeoJSON region queries
  298. case "geo_region_query_cells":
  299. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceGeojsonRegionQueryCellsDataPoint(now, v))
  300. case "geo_region_query_falsepos":
  301. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceGeojsonRegionQueryFalsePositiveDataPoint(now, v))
  302. case "geo_region_query_points":
  303. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceGeojsonRegionQueryPointsDataPoint(now, v))
  304. case "geo_region_query_reqs":
  305. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceGeojsonRegionQueryRequestsDataPoint(now, v))
  306. // Compression
  307. // 'Delete' transactions
  308. case "client_delete_error":
  309. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeDelete, metadata.AttributeTransactionResultError))
  310. case "client_delete_filtered_out":
  311. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeDelete, metadata.AttributeTransactionResultFilteredOut))
  312. case "client_delete_not_found":
  313. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeDelete, metadata.AttributeTransactionResultNotFound))
  314. case "client_delete_success":
  315. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeDelete, metadata.AttributeTransactionResultSuccess))
  316. case "client_delete_timeout":
  317. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeDelete, metadata.AttributeTransactionResultTimeout))
  318. // 'Read' transactions
  319. case "client_read_error":
  320. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeRead, metadata.AttributeTransactionResultError))
  321. case "client_read_filtered_out":
  322. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeRead, metadata.AttributeTransactionResultFilteredOut))
  323. case "client_read_not_found":
  324. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeRead, metadata.AttributeTransactionResultNotFound))
  325. case "client_read_success":
  326. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeRead, metadata.AttributeTransactionResultSuccess))
  327. case "client_read_timeout":
  328. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeRead, metadata.AttributeTransactionResultTimeout))
  329. // UDF transactions
  330. case "client_udf_error":
  331. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeUdf, metadata.AttributeTransactionResultError))
  332. case "client_udf_filtered_out":
  333. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeUdf, metadata.AttributeTransactionResultFilteredOut))
  334. case "client_udf_not_found":
  335. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeUdf, metadata.AttributeTransactionResultNotFound))
  336. case "client_udf_success":
  337. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeUdf, metadata.AttributeTransactionResultSuccess))
  338. case "client_udf_timeout":
  339. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeUdf, metadata.AttributeTransactionResultTimeout))
  340. // 'Write' transactions
  341. case "client_write_error":
  342. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeWrite, metadata.AttributeTransactionResultError))
  343. case "client_write_filtered_out":
  344. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeWrite, metadata.AttributeTransactionResultFilteredOut))
  345. case "client_write_not_found":
  346. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeWrite, metadata.AttributeTransactionResultNotFound))
  347. case "client_write_success":
  348. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeWrite, metadata.AttributeTransactionResultSuccess))
  349. case "client_write_timeout":
  350. addPartialIfError(errs, r.mb.RecordAerospikeNamespaceTransactionCountDataPoint(now, v, metadata.AttributeTransactionTypeWrite, metadata.AttributeTransactionResultTimeout))
  351. }
  352. }
  353. rb := r.mb.NewResourceBuilder()
  354. rb.SetAerospikeNamespace(info["name"])
  355. rb.SetAerospikeNodeName(info["node"])
  356. r.mb.EmitForResource(metadata.WithResource(rb.Emit()))
  357. r.logger.Debug("finished emitNamespace")
  358. }
  359. // addPartialIfError adds a partial error if the given error isn't nil
  360. func addPartialIfError(errs *scrapererror.ScrapeErrors, err error) {
  361. if err != nil {
  362. errs.AddPartial(1, err)
  363. }
  364. }