You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "smiklosovic (via GitHub)" <gi...@apache.org> on 2023/07/03 07:38:28 UTC

[GitHub] [cassandra] smiklosovic opened a new pull request, #2462: CASSANDRA-18646

smiklosovic opened a new pull request, #2462:
URL: https://github.com/apache/cassandra/pull/2462

   Thanks for sending a pull request! Here are some tips if you're new here:
    
    * Ensure you have added or run the [appropriate tests](https://cassandra.apache.org/_/development/testing.html) for your PR.
    * Be sure to keep the PR description updated to reflect all changes.
    * Write your PR title to summarize what this PR proposes.
    * If possible, provide a concise example to reproduce the issue for a faster review.
    * Read our [contributor guidelines](https://cassandra.apache.org/_/development/index.html)
    * If you're making a documentation change, see our [guide to documentation contribution](https://cassandra.apache.org/_/development/documentation.html)
    
   Commit messages should follow the following format:
   
   ```
   <One sentence description, usually Jira title or CHANGES.txt summary>
   
   <Optional lengthier description (context on patch)>
   
   patch by <Authors>; reviewed by <Reviewers> for CASSANDRA-#####
   
   Co-authored-by: Name1 <email1>
   Co-authored-by: Name2 <email2>
   
   ```
   
   The [Cassandra Jira](https://issues.apache.org/jira/projects/CASSANDRA/issues/)
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] xgerman commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "xgerman (via GitHub)" <gi...@apache.org>.
xgerman commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1263857083


##########
conf/cassandra.yaml:
##########
@@ -1302,6 +1302,10 @@ slow_query_log_timeout: 500ms
 #    Snitch for getting dc and rack of a node from metadata service of Alibaba cloud.
 #    This snitch that assumes an ECS region is a DC and an ECS availability_zone is a rack.
 #
+# AzureSnitch:
+#    Gets datacenter from 'location' and rack from 'zone' fields of 'compute' object
+#    from instance metadata service.

Review Comment:
   If availability zone is not enabled it will use fault domains and get the respective value from 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1260886689


##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.utils.JsonUtils;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+public class AzureSnitch extends AbstractCloudMetadataServiceSnitch
+{
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties), properties);
+    }
+
+    public AzureSnitch(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        super(connector, properties, resolveDcAndRack(connector));
+    }
+
+    private static Pair<String, String> resolveDcAndRack(AzureCloudConnector connector) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+
+        String datacenter;
+        String rack;
+
+        if (location == null || location.isNull() || location.asText().isEmpty())
+            datacenter = DEFAULT_DC;
+        else
+            datacenter = location.asText();

Review Comment:
   @xgerman I am not sure what you mean by this. Can you elaborate? 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] smiklosovic closed pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic closed pull request #2462: CASSANDRA-18646 Azure snitch
URL: https://github.com/apache/cassandra/pull/2462


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] xgerman commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "xgerman (via GitHub)" <gi...@apache.org>.
xgerman commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1261357233


##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.utils.JsonUtils;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+public class AzureSnitch extends AbstractCloudMetadataServiceSnitch
+{
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties), properties);
+    }
+
+    public AzureSnitch(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        super(connector, properties, resolveDcAndRack(connector));
+    }
+
+    private static Pair<String, String> resolveDcAndRack(AzureCloudConnector connector) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+
+        String datacenter;
+        String rack;
+
+        if (location == null || location.isNull() || location.asText().isEmpty())
+            datacenter = DEFAULT_DC;
+        else
+            datacenter = location.asText();

Review Comment:
   Assume you have two data centers DC1 and DC2 both in the same region, say useast2. Then `datacenter` would be for both useast2... 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1262533577


##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.utils.JsonUtils;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+public class AzureSnitch extends AbstractCloudMetadataServiceSnitch
+{
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties), properties);
+    }
+
+    public AzureSnitch(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        super(connector, properties, resolveDcAndRack(connector));
+    }
+
+    private static Pair<String, String> resolveDcAndRack(AzureCloudConnector connector) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+
+        String datacenter;
+        String rack;
+
+        if (location == null || location.isNull() || location.asText().isEmpty())
+            datacenter = DEFAULT_DC;
+        else
+            datacenter = location.asText();

Review Comment:
   resolved privately, in practice one is supposed to use dc_suffix for this kind of scenario



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1265235739


##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.utils.JsonUtils;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+/**
+ * AzureSnitch will resolve datacenter and rack by calling {@code /metadata/instance/compute} endpoint returning
+ * the response in JSON format for API version {@code 2021-12-13}. The version of API is configurable via property
+ * {@code azure_api_version} in cassandra-rackdc.properties.
+ *
+ * A datacenter is resolved from {@code location} field and a rack is resolved by looking into {@code zone} field first.
+ * When zone is not set, or it is empty string, it will look into {@code platformFaultDomain} field. Such resolved
+ * value is prepended by {@code rack-} string.
+ */
+public class AzureSnitch extends AbstractCloudMetadataServiceSnitch
+{
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties), properties);
+    }
+
+    public AzureSnitch(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        super(connector, properties, resolveDcAndRack(connector, properties));
+    }
+
+    private static Pair<String, String> resolveDcAndRack(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+        JsonNode platformFaultDomain = jsonNode.get("platformFaultDomain");
+
+        String datacenter;
+        String rack;
+
+        if (location == null || location.isNull() || location.asText().isEmpty())
+            datacenter = DEFAULT_DC;
+        else
+        {

Review Comment:
   nit: braces seems redundant



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1253983448


##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.regex.Pattern;
+
+import com.google.common.collect.ImmutableMap;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.db.SystemKeyspace;
+import org.apache.cassandra.gms.ApplicationState;
+import org.apache.cassandra.gms.EndpointState;
+import org.apache.cassandra.gms.Gossiper;
+import org.apache.cassandra.utils.FBUtilities;
+import org.apache.cassandra.utils.JsonUtils;
+
+import static java.lang.String.format;
+
+public class AzureSnitch extends AbstractNetworkTopologySnitch
+{
+    private static final Logger logger = LoggerFactory.getLogger(AzureSnitch.class);
+
+    private static final String DEFAULT_DC = "UNKNOWN-DC";
+    private static final String DEFAULT_RACK = "UNKNOWN-RACK";
+
+    private Map<InetAddressAndPort, Map<String, String>> savedEndpoints;
+
+    String rack;
+    String datacenter;
+
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties));
+    }
+
+    public AzureSnitch(AzureCloudConnector connector) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+
+        if (location == null || location.isNull() || location.asText().isEmpty())
+            datacenter = DEFAULT_DC;
+        else
+            datacenter = location.asText();
+
+        if (zone == null || zone.isNull() || zone.asText().isEmpty())
+            rack = DEFAULT_RACK;
+        else
+            rack = "zone-" + zone.asText();
+
+        logger.info(format("%s using region: %s, zone: %s, properties: %s", AzureSnitch.class.getName(), datacenter, rack, connector));
+    }
+
+    static class AzureCloudConnector extends AbstractCloudMetadataServiceConnector
+    {
+        private static final Logger logger = LoggerFactory.getLogger(AzureSnitch.class);
+        private static final Pattern API_VERSION_PATTERN = Pattern.compile("\\d\\d\\d\\d-\\d\\d-\\d\\d");
+
+        static final String METADATA_SERVICE_PROPERTY_KEY = "metadata_url";
+        static final String DEFAULT_METADATA_SERVICE_URL = "http://169.254.169.254";
+        static final String METADATA_QUERY = "/metadata/instance/compute?api-version=%s&format=json";
+        static final String VERSIONS_ENDPOINT = "/metadata/versions";
+        static final String METADATA_HEADER = "Metadata";
+        static final String API_VERSION_PROPERTY_KEY = "azure_api_version";
+
+        private final String apiVersion;
+
+        protected AzureCloudConnector(SnitchProperties properties) throws IOException
+        {
+            super(properties.get(METADATA_SERVICE_PROPERTY_KEY, DEFAULT_METADATA_SERVICE_URL));
+            apiVersion = getApiVersion(properties);
+            logger.debug("Resolved API version " + apiVersion);
+        }
+
+        String getResponse() throws IOException
+        {
+            return apiCall(metadataServiceUrl,
+                           String.format(METADATA_QUERY, apiVersion),
+                           "GET",
+                           ImmutableMap.of(METADATA_HEADER, "true"),
+                           200);
+        }
+
+        String getApiVersion(SnitchProperties properties) throws IOException
+        {
+            String version = properties.get(API_VERSION_PROPERTY_KEY, null);
+
+            if (version != null && API_VERSION_PATTERN.matcher(version).matches())
+                return version;
+
+            logger.debug(format("API version of '%s' does not follow pattern %s or is null. Going to " +
+                                "parse the latest version from the service ...",
+                                version, API_VERSION_PATTERN));
+
+            String response = apiCall(metadataServiceUrl,
+                                      VERSIONS_ENDPOINT,
+                                      "GET",
+                                      ImmutableMap.of("Metadata", "true"),
+                                      200);
+
+            JsonNode versions = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+            JsonNode apiVersions = versions.get("apiVersions");
+
+            if (apiVersions == null)
+                throw new IllegalStateException("Unable to get field 'apiVersions' from the response!");
+
+            if (!(apiVersions.isArray()))
+                throw new IOException(format(
+                "Expected a list, but got a %s:%s", apiVersions.getClass().getSimpleName(), apiVersions));
+
+            String[] versionsArray = JsonUtils.JSON_OBJECT_MAPPER.convertValue(apiVersions, String[].class);
+
+            if (versionsArray != null && versionsArray.length > 0)
+                return versionsArray[versionsArray.length - 1];
+            else
+                throw new IllegalStateException("returned apiVersions array is empty!");
+        }
+
+        @Override
+        public String toString()
+        {
+            return format("%s{%s=%s,%s=%s}",
+                          AzureCloudConnector.class.getName(),
+                          METADATA_SERVICE_PROPERTY_KEY,
+                          metadataServiceUrl,
+                          API_VERSION_PROPERTY_KEY,
+                          apiVersion);
+        }
+    }
+
+    public String getRack(InetAddressAndPort endpoint)

Review Comment:
   This method, and `getDatacenter` method, are identical in all snitch implementations. The only difference is that it returns a value of a field `rack` and, say in EC2, it returns value of a field `ec2zone`. Could you extract simple method like `getRackInternal() { return rack }`, define it abstract in `AbstractNetworkTopologySnitch` and move the implementation of `getRack(endpoint)` to `AbstractNetworkTopologySnitch`? You can do the same for `getDatacenter(endpoint)` method, and do that for all the snitch implementations.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] jacek-lewandowski commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "jacek-lewandowski (via GitHub)" <gi...@apache.org>.
jacek-lewandowski commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1269119209


##########
conf/cassandra.yaml:
##########
@@ -1302,6 +1302,11 @@ slow_query_log_timeout: 500ms
 #    Snitch for getting dc and rack of a node from metadata service of Alibaba cloud.
 #    This snitch that assumes an ECS region is a DC and an ECS availability_zone is a rack.
 #
+# AzureSnitch:

Review Comment:
   nit: 
   ```
   # AzureSnitch:
   #    Gets datacenter from 'location' and rack from 'zone' fields of 'compute' object
   #    from instance metadata service. If the availability zone is not enabled, it will use the fault
   #    domain and get its respective value.
   #
   ```
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] smiklosovic commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "smiklosovic (via GitHub)" <gi...@apache.org>.
smiklosovic commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1265243792


##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.utils.JsonUtils;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+/**
+ * AzureSnitch will resolve datacenter and rack by calling {@code /metadata/instance/compute} endpoint returning
+ * the response in JSON format for API version {@code 2021-12-13}. The version of API is configurable via property
+ * {@code azure_api_version} in cassandra-rackdc.properties.
+ *
+ * A datacenter is resolved from {@code location} field and a rack is resolved by looking into {@code zone} field first.
+ * When zone is not set, or it is empty string, it will look into {@code platformFaultDomain} field. Such resolved
+ * value is prepended by {@code rack-} string.
+ */
+public class AzureSnitch extends AbstractCloudMetadataServiceSnitch
+{
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties), properties);
+    }
+
+    public AzureSnitch(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        super(connector, properties, resolveDcAndRack(connector, properties));
+    }
+
+    private static Pair<String, String> resolveDcAndRack(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+        JsonNode platformFaultDomain = jsonNode.get("platformFaultDomain");
+
+        String datacenter;
+        String rack;
+
+        if (location == null || location.isNull() || location.asText().isEmpty())
+            datacenter = DEFAULT_DC;
+        else
+        {

Review Comment:
   done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


[GitHub] [cassandra] xgerman commented on a diff in pull request #2462: CASSANDRA-18646 Azure snitch

Posted by "xgerman (via GitHub)" <gi...@apache.org>.
xgerman commented on code in PR #2462:
URL: https://github.com/apache/cassandra/pull/2462#discussion_r1260301186


##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.utils.JsonUtils;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+public class AzureSnitch extends AbstractCloudMetadataServiceSnitch
+{
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties), properties);
+    }
+
+    public AzureSnitch(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        super(connector, properties, resolveDcAndRack(connector));
+    }
+
+    private static Pair<String, String> resolveDcAndRack(AzureCloudConnector connector) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");

Review Comment:
   Azure being azure there is another way to distribute nodes called fault domains (see https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-manage-fault-domains) so if zone is empty you need to check `platformFaultDomain` https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service?tabs=linux



##########
src/java/org/apache/cassandra/locator/AzureSnitch.java:
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.locator;
+
+import java.io.IOException;
+
+import com.google.common.collect.ImmutableMap;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.cassandra.utils.JsonUtils;
+import org.apache.cassandra.utils.Pair;
+
+import static java.lang.String.format;
+
+public class AzureSnitch extends AbstractCloudMetadataServiceSnitch
+{
+    public AzureSnitch() throws IOException
+    {
+        this(new SnitchProperties());
+    }
+
+    public AzureSnitch(SnitchProperties properties) throws IOException
+    {
+        this(new AzureCloudConnector(properties), properties);
+    }
+
+    public AzureSnitch(AzureCloudConnector connector, SnitchProperties properties) throws IOException
+    {
+        super(connector, properties, resolveDcAndRack(connector));
+    }
+
+    private static Pair<String, String> resolveDcAndRack(AzureCloudConnector connector) throws IOException
+    {
+        String response = connector.getResponse();
+        JsonNode jsonNode = JsonUtils.JSON_OBJECT_MAPPER.readTree(response);
+
+        JsonNode location = jsonNode.get("location");
+        JsonNode zone = jsonNode.get("zone");
+
+        String datacenter;
+        String rack;
+
+        if (location == null || location.isNull() || location.asText().isEmpty())
+            datacenter = DEFAULT_DC;
+        else
+            datacenter = location.asText();

Review Comment:
   not sure if having multiple data centers in the same location is a goal. If so, this would not work for that scenario.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org