Bigtable Cluster Tables Should Have Timestamp Granularity
More Info:
Ensure that Bigtable cluster tables timestamp granularity is set to 1ms.
Risk Level
Low
Address
Operational Maturity
Compliance Standards
- Cloudanix Best Practice
Triage and Remediation
- Remediation
Remediation
Using Console
To remediate the misconfiguration of Bigtable Cluster Tables should have timestamp granularity set to 1ms in GCP using GCP console, follow these steps:
-
Open the GCP console and navigate to the Cloud Bigtable section.
-
Select the Bigtable instance that you want to remediate.
-
In the left navigation pane, click on the "Tables" option.
-
Select the table that you want to remediate and click on the "Edit" button.
-
Scroll down to the "Column families" section and click on the column family that contains the timestamp column.
-
In the "Column family" settings, set the "Timestamp granularity" to "Milliseconds".
-
Click on the "Save" button to apply the changes.
-
Repeat steps 4-7 for all the tables in the Bigtable instance that have timestamp columns.
By following these steps, you will remediate the misconfiguration of Bigtable Cluster Tables should have timestamp granularity set to 1ms in GCP using GCP console.
Using CLI
To remediate the misconfiguration of Bigtable Cluster Tables having timestamp granularity set to 1ms in GCP using GCP CLI, follow these steps:
-
Open the terminal and ensure that you have the latest version of the Google Cloud SDK installed.
-
Authenticate yourself with the GCP CLI by running the following command:
gcloud auth login
- Set the default project for the CLI by running the following command:
gcloud config set project PROJECT_ID
Replace PROJECT_ID with the ID of the project where your Bigtable Cluster is located.
- Run the following command to update the timestamp granularity of your Bigtable Cluster:
gcloud bigtable clusters update CLUSTER_NAME --cluster-id=CLUSTER_ID --instance=INSTANCE_NAME --timestamp-granularity=ms
Replace CLUSTER_NAME, CLUSTER_ID, and INSTANCE_NAME with the respective names of your Bigtable Cluster, Cluster ID, and Instance.
- Verify that the timestamp granularity has been set to 1ms by running the following command:
gcloud bigtable clusters describe CLUSTER_NAME --cluster-id=CLUSTER_ID --instance=INSTANCE_NAME
This command will display the details of your Bigtable Cluster, including the timestamp granularity.
By following these steps, you can remediate the misconfiguration of Bigtable Cluster Tables having timestamp granularity set to 1ms in GCP using GCP CLI.
Using Python
To remediate the Bigtable Cluster Tables Timestamp Granularity issue in GCP using Python, you can follow these steps:
- Install the
google-cloud-bigtablelibrary using pip:
pip install google-cloud-bigtable
- Import the required libraries:
from google.cloud import bigtable
from google.cloud.bigtable import column_family
- Create a
bigtable.Clientobject and abigtable.Tableobject:
client = bigtable.Client(project=<project_id>, admin=True)
table = client.table('<instance_id>', '<table_id>')
- Get the column family and update the timestamp granularity:
column_family_id = '<column_family_id>'
column_family = column_family.ColumnFamily(column_granularity_millis=1)
table.column_family(column_family_id).modify_column_family(column_family)
- Confirm that the column family has been updated:
column_families = table.list_column_families()
for column_family_id, column_family in column_families.items():
print('Column Family:', column_family_id)
print('Timestamp Granularity:', column_family.column_granularity_millis)
This should remediate the Bigtable Cluster Tables Timestamp Granularity issue in GCP using Python.
Using Terraform
resource "google_bigtable_instance" "THIS_INSTANCE" {
name = "BT_INSTANCE_NAME" # replace with your instance ID
display_name = "BT_INSTANCE_DISPLAY_NAME" # replace with your display name
cluster {
cluster_id = "BT_CLUSTER_ID" # replace with your cluster ID
zone = "BT_CLUSTER_ZONE" # replace with your zone, e.g. us-central1-b
num_nodes = 1
storage_type = "SSD"
}
}
resource "google_bigtable_table" "THIS_TABLE" {
name = "BT_TABLE_NAME" # replace with your table ID
instance_name = google_bigtable_instance.THIS_INSTANCE.name
# This is the setting the check requires: 1ms timestamp granularity
granularity = "MILLIS"
}
Changing granularity on an existing google_bigtable_table forces replacement of the table (the underlying API treats this as immutable), which will delete and recreate the table and its data; plan and migrate data accordingly before applying.
To verify, terraform plan should show a ~ or +/- change on the google_bigtable_table resource where granularity is set to "MILLIS" (or a new table created with that value if it was previously unmanaged).