עדכון אשכול Connect

אפשר לערוך אשכול Connect כדי לעדכן מאפיינים כמו מספר המעבדים הווירטואליים, הזיכרון, הרשת והתוויות.

כדי לערוך אשכול Connect, אתם יכולים להשתמש במסוף Google Cloud , ב-CLI של gcloud, בספריית הלקוח או ב-Managed Kafka API. אי אפשר להשתמש ב-API של Apache Kafka בקוד פתוח כדי לעדכן אשכול Connect.

לפני שמתחילים

אי אפשר לערוך את כל המאפיינים של אשכול Connect. בודקים את המאפיינים של אשכול Connect לפני שמעדכנים.

תפקידים והרשאות נדרשים

כדי לקבל את ההרשאות שנדרשות לעריכת אשכול Connect, בקשו מהאדמין להקצות לכם את התפקיד עריכת אשכולות מנוהלים של Kafka Connect (roles/managedkafka.connectClusterEditor) ב-IAM בפרויקט. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

זהו תפקיד שמוגדר מראש וכולל את ההרשאות שנדרשות לעריכת אשכול Connect. כדי לראות בדיוק אילו הרשאות נדרשות, אפשר להרחיב את הקטע ההרשאות הנדרשות:

ההרשאות הנדרשות

כדי לערוך אשכול Connect, צריך את ההרשאות הבאות:

  • עדכון אשכול Connect: managedkafka.connectClusters.update
  • צפייה במחברים כשמשתמשים במסוף Google Cloud כדי לעדכן אשכול Connect: managedkafka.connectors.list

יכול להיות שתקבלו את ההרשאות האלה באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

הרשאות של רשתות משנה באשכולות

אם מעדכנים את רשת המשנה של ה-worker באשכול Connect, סוכן השירות המנוהל של Kafka מצרף את רשת המשנה במהלך פעולת העדכון.

ההרשאה managedkafka.connectClusters.update מאפשרת לישות מורשית לצרף באופן עקיף כל תת-רשת שלסוכן השירות יש הרשאה להשתמש בה, גם אם לישות המורשית אין הרשאה ישירה להשתמש בתת-הרשת.

עריכת אשכול Connect

כדי לעדכן מאפיינים מסוימים, כמו מעבד (CPU) וזיכרון, צריך להפעיל מחדש את האשכול.

הפעלה מחדש של אשכולות שומרת על הנתונים, אבל עלולה להגדיל את זמן האחזור. משך ההפעלה מחדש נקבע לפי מספר ה-workers הראשוני באשכול.

אפשר לעדכן את המאפיינים הבאים של אשכול Connect:

מאפיין (property) ניתן לעריכה
מעבדים וירטואלים כן
זיכרון כן
רשת כן
תת-רשת של Worker כן
דומיינים של DNS שניתנים לפענוח כן (הוספה/מחיקה)
שם האשכול ב-Connect לא
אשכול Kafka לא
מיקום לא
תוויות כן (הוספה/עריכה/מחיקה)
סודות כן (הוספה/מחיקה)

המסוף

  1. נכנסים לדף Connect Clusters במסוף Google Cloud .

    מעבר אל Connect Clusters

  2. לוחצים על אשכול Connect שרוצים לעדכן.

    הדף Connect cluster details מוצג.

  3. לוחצים על Edit.

    מופיע הדף Edit Kafka Connect cluster.

  4. מבצעים את השינויים הנדרשים במאפיינים שאפשר לערוך.

  5. לוחצים על Save.

gcloud

  1. מפעילים את Cloud Shell במסוף Google Cloud .

    הפעלת Cloud Shell

    בחלק התחתון של מסוף Google Cloud יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.

  2. מריצים את הפקודה gcloud managed-kafka connect-clusters update:

    gcloud managed-kafka connect-clusters update CONNECT_CLUSTER_ID \
        --location=LOCATION \
        [--cpu=CPU --memory=MEMORY
         | --clear-dns-names \
         | --dns-name=DNS_NAME --clear-labels \
         | --labels=LABELS --clear-secrets \
         | --secret=SECRET [--primary-subnet=WORKER_SUBNET \
        [--async]
    

    מחליפים את מה שכתוב בשדות הבאים:

    • ‫CONNECT_CLUSTER_ID: המזהה או השם של אשכול Connect. אי אפשר לשנות את השם של אשכול Connect.
    • ‫LOCATION: המיקום של אשכול Connect. אי אפשר לשנות את המיקום של אשכול Connect.
    • ‫CPU: מספר ה-vCPU של אשכול Connect. הערך המינימלי הוא 3 מעבדי vCPU.
    • ‫MEMORY: כמות הזיכרון של אשכול Connect. צריך להשתמש ביחידות "MB",‏ "MiB",‏ "GB",‏ "GiB",‏ "TB" או "TiB". לדוגמה, "10GiB". צריך להקצות בין ‎1GiB ל-‎8GiB לכל vCPU.

    • ‫DNS_NAME: שם דומיין DNS מרשת המשנה שיהיה גלוי ל-Connect Cluster.
    • ‫LABELS: (אופציונלי) תוויות לשיוך לאשכול. מידע נוסף על הפורמט של תוויות רשימה של צמדי KEY=VALUE של תוויות להוספה. המפתחות צריכים להתחיל באות קטנה, ויכולים להכיל רק מקפים (-), קווים תחתונים (_), אותיות קטנות ומספרים. הערכים יכולים להכיל רק מקפים (-), קווים תחתונים (_), אותיות קטנות ומספרים.
    • ‫SECRET: (אופציונלי) סודות לטעינה ב-workers. צריך לספק גרסאות סודיות מדויקות מ-Secret Manager, אין תמיכה בשמות סודיים. אפשר לטעון עד 32 סודות באשכול אחד. פורמט: projects/PROJECT_ID/secrets/SECRET_NAME/versions/VERSION_ID
    • ‫WORKER_SUBNET: רשת המשנה של ה-worker של אשכול Connect. רשת המשנה של ה-worker צריכה להיות באותו אזור כמו אשכול Connect.

      הפורמט של רשת המשנה הוא projects/PROJECT_ID/regions/REGION/subnetworks/SUBNET_ID.

המשך

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי ההוראות להגדרת Go בקטע התקנת ספריות הלקוח. מידע נוסף מופיע במאמרי העזרה של ה-API של Go עבור שירות מנוהל ל-Apache Kafka.

כדי לבצע אימות בשירות המנוהל ל-Apache Kafka, צריך להגדיר את Application Default Credentials ‏(ADC). מידע נוסף זמין במאמר הגדרת ADC לסביבת פיתוח מקומית.

import (
	"context"
	"fmt"
	"io"

	"cloud.google.com/go/managedkafka/apiv1/managedkafkapb"
	"google.golang.org/api/option"
	"google.golang.org/protobuf/types/known/fieldmaskpb"

	managedkafka "cloud.google.com/go/managedkafka/apiv1"
)

func updateConnectCluster(w io.Writer, projectID, region, clusterID string, memoryBytes int64, labels map[string]string, opts ...option.ClientOption) error {
	// projectID := "my-project-id"
	// region := "us-central1"
	// clusterID := "my-connect-cluster"
	// memoryBytes := 25769803776 // 24 GiB in bytes
	// labels := map[string]string{"environment": "production"}
	ctx := context.Background()
	client, err := managedkafka.NewManagedKafkaConnectClient(ctx, opts...)
	if err != nil {
		return fmt.Errorf("managedkafka.NewManagedKafkaConnectClient got err: %w", err)
	}
	defer client.Close()

	clusterPath := fmt.Sprintf("projects/%s/locations/%s/connectClusters/%s", projectID, region, clusterID)

	// Capacity configuration update
	capacityConfig := &managedkafkapb.CapacityConfig{
		MemoryBytes: memoryBytes,
	}

	connectCluster := &managedkafkapb.ConnectCluster{
		Name:           clusterPath,
		CapacityConfig: capacityConfig,
		Labels:         labels,
	}
	paths := []string{"capacity_config.memory_bytes", "labels"}
	updateMask := &fieldmaskpb.FieldMask{
		Paths: paths,
	}

	req := &managedkafkapb.UpdateConnectClusterRequest{
		UpdateMask:     updateMask,
		ConnectCluster: connectCluster,
	}
	op, err := client.UpdateConnectCluster(ctx, req)
	if err != nil {
		return fmt.Errorf("client.UpdateConnectCluster got err: %w", err)
	}
	resp, err := op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("op.Wait got err: %w", err)
	}
	fmt.Fprintf(w, "Updated connect cluster: %#v\n", resp)
	return nil
}

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההתקנה של Java בקטע התקנת ספריות הלקוח. מידע נוסף מופיע במאמרי העזרה של Managed Service for Apache Kafka Java API.

כדי לבצע אימות בשירות המנוהל ל-Apache Kafka, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת ADC לסביבת פיתוח מקומית.


import com.google.api.gax.longrunning.OperationFuture;
import com.google.api.gax.longrunning.OperationSnapshot;
import com.google.api.gax.longrunning.OperationTimedPollAlgorithm;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.retrying.TimedRetryAlgorithm;
import com.google.cloud.managedkafka.v1.CapacityConfig;
import com.google.cloud.managedkafka.v1.ConnectCluster;
import com.google.cloud.managedkafka.v1.ConnectClusterName;
import com.google.cloud.managedkafka.v1.ManagedKafkaConnectClient;
import com.google.cloud.managedkafka.v1.ManagedKafkaConnectSettings;
import com.google.cloud.managedkafka.v1.OperationMetadata;
import com.google.cloud.managedkafka.v1.UpdateConnectClusterRequest;
import com.google.protobuf.FieldMask;
import java.time.Duration;
import java.util.concurrent.ExecutionException;

public class UpdateConnectCluster {

  public static void main(String[] args) throws Exception {
    // TODO(developer): Replace these variables before running the example.
    String projectId = "my-project-id";
    String region = "my-region"; // e.g. us-east1
    String clusterId = "my-connect-cluster";
    long memoryBytes = 25769803776L; // 24 GiB
    updateConnectCluster(projectId, region, clusterId, memoryBytes);
  }

  public static void updateConnectCluster(
      String projectId, String region, String clusterId, long memoryBytes) throws Exception {
    CapacityConfig capacityConfig = CapacityConfig.newBuilder().setMemoryBytes(memoryBytes).build();
    ConnectCluster connectCluster = ConnectCluster.newBuilder()
        .setName(ConnectClusterName.of(projectId, region, clusterId).toString())
        .setCapacityConfig(capacityConfig)
        .build();
    FieldMask updateMask = FieldMask.newBuilder().addPaths("capacity_config.memory_bytes").build();

    // Create the settings to configure the timeout for polling operations
    ManagedKafkaConnectSettings.Builder settingsBuilder = ManagedKafkaConnectSettings.newBuilder();
    TimedRetryAlgorithm timedRetryAlgorithm = OperationTimedPollAlgorithm.create(
        RetrySettings.newBuilder()
            .setTotalTimeoutDuration(Duration.ofHours(1L))
            .build());
    settingsBuilder.updateConnectClusterOperationSettings()
        .setPollingAlgorithm(timedRetryAlgorithm);

    try (ManagedKafkaConnectClient managedKafkaConnectClient = ManagedKafkaConnectClient.create(
        settingsBuilder.build())) {
      UpdateConnectClusterRequest request = UpdateConnectClusterRequest.newBuilder()
          .setUpdateMask(updateMask)
          .setConnectCluster(connectCluster).build();
      OperationFuture<ConnectCluster, OperationMetadata> future = managedKafkaConnectClient
          .updateConnectClusterOperationCallable().futureCall(request);

      // Get the initial LRO and print details. CreateConnectCluster contains sample
      // code for polling logs.
      OperationSnapshot operation = future.getInitialFuture().get();
      System.out.printf(
          "Connect cluster update started. Operation name: %s\nDone: %s\nMetadata: %s\n",
          operation.getName(),
          operation.isDone(),
          future.getMetadata().get().toString());

      ConnectCluster response = future.get();
      System.out.printf("Updated connect cluster: %s\n", response.getName());
    } catch (ExecutionException e) {
      System.err.printf("managedKafkaConnectClient.updateConnectCluster got err: %s\n", 
          e.getMessage());
    }
  }
}

Python

לפני שתנסו את הדוגמה הזו, פעלו לפי הוראות ההגדרה של Python בקטע התקנת ספריות הלקוח. מידע נוסף מופיע במאמרי העזרה של ה-API בשפת Python של שירות מנוהל ל-Apache Kafka.

כדי לבצע אימות בשירות המנוהל ל-Apache Kafka, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת ADC לסביבת פיתוח מקומית.

from google.api_core.exceptions import GoogleAPICallError
from google.cloud import managedkafka_v1
from google.cloud.managedkafka_v1.services.managed_kafka_connect import (
    ManagedKafkaConnectClient,
)
from google.cloud.managedkafka_v1.types import ConnectCluster
from google.protobuf import field_mask_pb2

# TODO(developer)
# project_id = "my-project-id"
# region = "us-central1"
# connect_cluster_id = "my-connect-cluster"
# memory_bytes = 4295000000

connect_client = ManagedKafkaConnectClient()

connect_cluster = ConnectCluster()
connect_cluster.name = connect_client.connect_cluster_path(
    project_id, region, connect_cluster_id
)
connect_cluster.capacity_config.memory_bytes = memory_bytes
update_mask = field_mask_pb2.FieldMask()
update_mask.paths.append("capacity_config.memory_bytes")

# For a list of editable fields, one can check https://cloud.google.com/managed-service-for-apache-kafka/docs/connect-cluster/create-connect-cluster#properties.
request = managedkafka_v1.UpdateConnectClusterRequest(
    update_mask=update_mask,
    connect_cluster=connect_cluster,
)

try:
    operation = connect_client.update_connect_cluster(request=request)
    print(f"Waiting for operation {operation.operation.name} to complete...")
    operation.result()
    response = operation.result()
    print("Updated Connect cluster:", response)
except GoogleAPICallError as e:
    print(f"The operation failed with error: {e}")

מה השלב הבא?

‫Apache Kafka®‎ הוא סימן מסחרי רשום של The Apache Software Foundation או של השותפים העצמאיים שלה בארצות הברית או במדינות אחרות.