You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/10/10 02:30:55 UTC

[GitHub] [skywalking] kezhenxu94 commented on a diff in pull request #9747: Lazy load the Kubernetes metadata and switch from event-driven to polling

kezhenxu94 commented on code in PR #9747:
URL: https://github.com/apache/skywalking/pull/9747#discussion_r990882189


##########
oap-server/server-library/library-kubernetes-support/src/main/java/org/apache/skywalking/library/kubernetes/KubernetesServices.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.skywalking.library.kubernetes;
+
+import java.time.Duration;
+import java.util.Collections;
+import java.util.List;
+import org.slf4j.LoggerFactory;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import io.kubernetes.client.openapi.ApiException;
+import io.kubernetes.client.openapi.apis.CoreV1Api;
+import io.kubernetes.client.openapi.models.V1Service;
+import lombok.SneakyThrows;
+
+public enum KubernetesServices {
+    INSTANCE;
+
+    private final LoadingCache<KubernetesServices, List<V1Service>> services;
+
+    @SneakyThrows
+    private KubernetesServices() {

Review Comment:
   > As a constructor of an enum, how do we control this initialization? I think this should not run if we are not in a k8s env.
   
   We don't because we don't need.
   
   > The initialization should only run when it is used in the first time.
   
   The enum being instantiated doesn't mean it will fetch the metadata immediately, it fetches the metadata ONLY when the `list` method is called, and the `list` method is only called in `k8s-mesh` analyzer, or Kubernetes metrics comes to MAL.
   
   In short, SkyWalking only tries to fetch the metadata when requested, if it throws error, it means someone tries to fetch the metadata in the wrong place (i.e. open `k8s-mesh` analyzer in non-Kubernetes cluster)



-- 
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: notifications-unsubscribe@skywalking.apache.org

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