private getServiceGraphData()

in web/src/app/services/graph-converter.service.ts [129:199]


  private getServiceGraphData(
    nodes: GraphNode[],
    timeline: MappedTimelineEntry,
    t: number,
  ): ServiceGraphData[] {
    const services = Object.values(timeline).filter(
      (t) =>
        t.layer == TimelineLayer.Name &&
        t.getNameOfLayer(TimelineLayer.Kind) == 'service',
    );
    const result: ServiceGraphData[] = [];
    for (const serviceTimeline of services) {
      const manifest: k8s.K8sServiceResource = this._getManifest(
        timeline,
        serviceTimeline,
        t,
      ) as k8s.K8sServiceResource;
      if (!manifest) continue;

      const serviceName = serviceTimeline.getNameOfLayer(TimelineLayer.Name);
      const serviceNamespace = serviceTimeline.getNameOfLayer(
        TimelineLayer.Namespace,
      );

      const selector = manifest.spec?.selector ?? {};
      const connectedPods: PodConnectionGraphData[] = [];
      if (selector) {
        for (const node of nodes) {
          for (const pod of node.pods) {
            let match = Object.keys(selector).length != 0;
            for (const key in selector) {
              if (
                !(key in pod.labels) ||
                (key in pod.labels && pod.labels[key] != selector[key])
              ) {
                match = false;
              }
            }
            if (match) {
              connectedPods.push({
                node: node,
                pod: pod,
              });
            }
          }
        }
      }

      const graphServiceData: ServiceGraphData = {
        uid: manifest.metadata?.uid,
        name: serviceName,
        namespace: serviceNamespace,
        labels: {},
        clusterIp: manifest.status?.clusterIp ?? '-',
        type: manifest.spec?.type ?? 'Unknown',
        connectedPods,
      };

      if (
        this._checkDeletionThresholdAndUpdateTimestamp(
          t,
          timeline,
          serviceTimeline,
          graphServiceData,
        )
      ) {
        result.push(graphServiceData);
      }
    }
    return result;
  }