001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.trace;
019
020import io.opentelemetry.api.common.AttributeKey;
021import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
022import java.nio.ByteBuffer;
023import java.util.List;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/**
027 * The constants in this class correspond with the guidance outlined by the OpenTelemetry <a href=
028 * "https://github.com/open-telemetry/opentelemetry-specification/tree/main/specification/trace/semantic_conventions">Semantic
029 * Conventions</a>.
030 */
031@InterfaceAudience.Private
032public final class HBaseSemanticAttributes {
033  public static final AttributeKey<String> DB_SYSTEM = SemanticAttributes.DB_SYSTEM;
034  public static final String DB_SYSTEM_VALUE = SemanticAttributes.DbSystemValues.HBASE;
035  public static final AttributeKey<String> DB_CONNECTION_STRING =
036    SemanticAttributes.DB_CONNECTION_STRING;
037  public static final AttributeKey<String> DB_USER = SemanticAttributes.DB_USER;
038  public static final AttributeKey<String> DB_NAME = SemanticAttributes.DB_NAME;
039  public static final AttributeKey<String> DB_OPERATION = SemanticAttributes.DB_OPERATION;
040  public static final AttributeKey<String> TABLE_KEY = AttributeKey.stringKey("db.hbase.table");
041  /**
042   * For operations that themselves ship one or more operations, such as {@link Operation#BATCH} and
043   * {@link Operation#CHECK_AND_MUTATE}.
044   */
045  public static final AttributeKey<List<String>> CONTAINER_DB_OPERATIONS_KEY =
046    AttributeKey.stringArrayKey("db.hbase.container_operations");
047  public static final AttributeKey<List<String>> REGION_NAMES_KEY =
048    AttributeKey.stringArrayKey("db.hbase.regions");
049  public static final AttributeKey<String> RPC_SYSTEM = SemanticAttributes.RPC_SYSTEM;
050  public static final AttributeKey<String> RPC_SERVICE = SemanticAttributes.RPC_SERVICE;
051  public static final AttributeKey<String> RPC_METHOD = SemanticAttributes.RPC_METHOD;
052  public static final AttributeKey<String> SERVER_NAME_KEY =
053    AttributeKey.stringKey("db.hbase.server.name");
054  public static final AttributeKey<String> NET_PEER_NAME = SemanticAttributes.NET_PEER_NAME;
055  public static final AttributeKey<Long> NET_PEER_PORT = SemanticAttributes.NET_PEER_PORT;
056  public static final AttributeKey<Boolean> ROW_LOCK_READ_LOCK_KEY =
057    AttributeKey.booleanKey("db.hbase.rowlock.readlock");
058  public static final AttributeKey<String> WAL_IMPL = AttributeKey.stringKey("db.hbase.wal.impl");
059
060  /**
061   * Indicates the amount of data was read into a {@link ByteBuffer} of type
062   * {@link ByteBuffer#isDirect() direct}.
063   */
064  public static final AttributeKey<Long> DIRECT_BYTES_READ_KEY =
065    AttributeKey.longKey("db.hbase.io.direct_bytes_read");
066  /**
067   * Indicates the amount of data was read into a {@link ByteBuffer} not of type
068   * {@link ByteBuffer#isDirect() direct}.
069   */
070  public static final AttributeKey<Long> HEAP_BYTES_READ_KEY =
071    AttributeKey.longKey("db.hbase.io.heap_bytes_read");
072  /**
073   * Indicates the {@link org.apache.hadoop.hbase.io.compress.Compression.Algorithm} used to encode
074   * an HFile.
075   */
076  public static final AttributeKey<String> COMPRESSION_ALGORITHM_KEY =
077    AttributeKey.stringKey("db.hbase.io.hfile.data_block_encoding");
078  /**
079   * Indicates the {@link org.apache.hadoop.hbase.io.encoding.DataBlockEncoding} algorithm used to
080   * encode this HFile.
081   */
082  public static final AttributeKey<String> DATA_BLOCK_ENCODING_KEY =
083    AttributeKey.stringKey("db.hbase.io.hfile.data_block_encoding");
084  /**
085   * Indicates the {@link org.apache.hadoop.hbase.io.crypto.Cipher} used to encrypt this HFile.
086   */
087  public static final AttributeKey<String> ENCRYPTION_CIPHER_KEY =
088    AttributeKey.stringKey("db.hbase.io.hfile.encryption_cipher");
089  /**
090   * Indicates the {@link org.apache.hadoop.hbase.util.ChecksumType} used to encode this HFile.
091   */
092  public static final AttributeKey<String> CHECKSUM_KEY =
093    AttributeKey.stringKey("db.hbase.io.hfile.checksum_type");
094  /**
095   * Indicates the name of the HFile accessed.
096   */
097  public static final AttributeKey<String> HFILE_NAME_KEY =
098    AttributeKey.stringKey("db.hbase.io.hfile.file_name");
099  /**
100   * Indicated the type of read.
101   */
102  public static final AttributeKey<String> READ_TYPE_KEY =
103    AttributeKey.stringKey("db.hbase.io.hfile.read_type");
104  /**
105   * Identifies an entry in the Block Cache.
106   */
107  public static final AttributeKey<String> BLOCK_CACHE_KEY_KEY =
108    AttributeKey.stringKey("db.hbase.io.hfile.block_cache_key");
109
110  /**
111   * These values represent the different IO read strategies HBase may employ for accessing
112   * filesystem data.
113   */
114  public enum ReadType {
115    // TODO: promote this to the FSReader#readBlockData API. Or somehow instead use Scan.ReadType.
116    POSITIONAL_READ,
117    SEEK_PLUS_READ,
118  }
119
120  /**
121   * These are values used with {@link #DB_OPERATION}. They correspond with the implementations of
122   * {@code org.apache.hadoop.hbase.client.Operation}, as well as
123   * {@code org.apache.hadoop.hbase.client.CheckAndMutate}, and "MULTI", meaning a batch of multiple
124   * operations.
125   */
126  public enum Operation {
127    APPEND,
128    BATCH,
129    CHECK_AND_MUTATE,
130    COPROC_EXEC,
131    DELETE,
132    GET,
133    INCREMENT,
134    PUT,
135    SCAN,
136  }
137
138  /**
139   * These are values used with {@link #RPC_SYSTEM}. Only a single value for now; more to come as we
140   * add tracing over our gateway components.
141   */
142  public enum RpcSystem {
143    HBASE_RPC,
144  }
145
146  private HBaseSemanticAttributes() {
147  }
148}