다음을 통해 공유


labels()(미리 보기의 그래프 함수)

적용 대상: ✅Microsoft FabricAzure Data Explorer

비고

이 기능은 현재 공개 미리 보기로 제공됩니다. 기능 및 구문은 일반 공급 전에 변경될 수 있습니다.

그래프 함수는 labels() 그래프의 노드 또는 가장자리와 연결된 레이블을 검색합니다. 레이블을 기반으로 요소를 필터링하고 쿼리 결과에 레이블 정보를 프로젝션하는 데 모두 사용할 수 있습니다.

레이블은 그래프 모델 내에서 정의되며 정적(노드 또는 에지 형식에 할당된 고정 레이블) 또는 동적(그래프 생성 중 데이터 속성에서 파생된 레이블)일 수 있습니다. 함수는 labels() 이러한 미리 정의된 레이블에 액세스하여 그래프 요소를 효율적으로 필터링하고 분석할 수 있도록 합니다.

비고

이 함수는 그래프 일치그래프 최단 경로 연산자와 함께 사용됩니다.

중요합니다

labels() 함수가 연산자로 만든 make-graph 그래프(즉, 영구 그래프 모델이 아닌 임시 그래프)에서 사용되는 경우 임시 그래프에는 레이블 메타데이터가 없으므로 항상 모든 노드 및 에지에 대해 빈 배열(동적 데이터 형식)을 반환합니다.

문법

labels([element])

매개 변수

이름 유형 필수 설명
요소 string 그래프 패턴의 그래프 노드 또는 에지 변수에 대한 참조입니다. inner_nodes()를 사용하여 all(), any(), map() 그래프 함수 내에서 사용할 때는 매개 변수를 전달하지 마세요. 자세한 내용은 그래프 패턴 표기법참조하세요.

반품

지정된 노드 또는 에지와 연결된 레이블을 포함하는 동적 배열을 반환합니다. 레이블이 없는 노드 및 가장자리의 경우 빈 배열을 반환합니다.

inner_nodes()와 함께 all(), any()또는 map() 내부에서 사용되는 경우 매개 변수 없이 호출 labels() 하여 모든 내부 노드 또는 에지에 대한 레이블을 각각 반환합니다.

레이블 원본

레이블은 그래프 모델에 정의되며 다음 두 소스에서 생성할 수 있습니다.

  • 정적 레이블: 그래프 모델 정의 중에 특정 노드 또는 에지 형식에 할당된 고정 레이블입니다. 이러한 레이블은 특정 형식의 모든 인스턴스에 대해 일정하게 유지됩니다.
  • 동적 레이블: 그래프를 생성할 때 데이터 속성에서 파생된 레이블입니다. 이러한 레이블은 실제 데이터 값 및 계산 식에 따라 달라질 수 있습니다.

이 함수는 labels() 그래프 모델 스키마 및 정의를 통해 그래프 요소와 연결된 정적 레이블과 동적 레이블을 모두 검색합니다.

예시

레이블별로 노드 필터링

다음 예제에서는 함수를 labels() 사용하여 할당된 레이블에 따라 노드를 필터링하는 방법을 보여 줍니다. 이 예제에는 정적 및 동적 레이블이 할당되는 방법을 명확히 하기 위한 전체 그래프 모델 정의가 포함되어 있습니다.

그래프 모델 정의

.create-or-alter graph_model AppProcessGraph ```
{
  "Schema": {
    "Nodes": {
      "Application": {"AppName": "string", "Type": "string"},
      "Process": {"ProcessName": "string"}
    },
    "Edges": {
      "CONNECTS_TO": {}
    }
  },
  "Definition": {
    "Steps": [
      {
        "Kind": "AddNodes",
        "Query": "Applications | project AppId, AppName, Type, NodeLabels",
        "NodeIdColumn": "AppId",
        "Labels": ["Application"],
        "LabelsColumn": "NodeLabels"
      },
      {
        "Kind": "AddNodes",
        "Query": "Processes | project ProcId, ProcessName",
        "NodeIdColumn": "ProcId",
        "Labels": ["Process"]
      },
      {
        "Kind": "AddEdges",
        "Query": "AppConnections | project SourceAppId, TargetProcId",
        "SourceColumn": "SourceAppId",
        "TargetColumn": "TargetProcId",
        "Labels": ["CONNECTS_TO"]
      }
    ]
  }
}
```

쿼리 예제

graph('AppProcessGraph')
| graph-match cycles=none (app)-[e*1..3]->(process)
    where process.ProcessName contains "nginx" and labels(app) has "Application"
    project app=app.AppName
| summarize c=count() by app
| top 10 by c desc

출력

앱(애플리케이션) c
WebApp1 15
WebApp2 12
APIService 8 (여덟)

결과의 프로젝트 레이블

다음 예제에서는 프로젝트 절의 함수를 labels() 사용하여 쿼리 결과에 레이블 정보를 포함하는 방법을 보여 줍니다. 이 쿼리는 다양한 유형의 네트워크 구성 요소 간의 연결을 찾고 분석을 위한 레이블을 포함합니다.

그래프 모델 정의

.create-or-alter graph_model NetworkGraph ```
{
  "Schema": {
    "Nodes": {
      "NetworkComponent": {"ComponentName": "string", "ComponentType": "string"}
    },
    "Edges": {
      "CONNECTED_TO": {"ConnectionType": "string"}
    }
  },
  "Definition": {
    "Steps": [
      {
        "Kind": "AddNodes",
        "Query": "NetworkComponentsTable | project Id, ComponentName, ComponentType, NodeLabels",
        "NodeIdColumn": "Id",
        "Labels": ["NetworkComponent"],
        "LabelsColumn": "NodeLabels"
      },
      {
        "Kind": "AddEdges",
        "Query": "ConnectionsTable | project SourceId, TargetId, ConnectionType, EdgeLabels",
        "SourceColumn": "SourceId",
        "TargetColumn": "TargetId",
        "Labels": ["CONNECTED_TO"],
        "LabelsColumn": "EdgeLabels"
      }
    ]
  }
}
```

쿼리 예제

graph('NetworkGraph')
| graph-match (source)-[conn]->(target)
    where labels(source) has "Network" and labels(target) has "Compute"
    project 
        SourceComponent = source.ComponentName,
        TargetComponent = target.ComponentName,
        SourceLabels = labels(source),
        TargetLabels = labels(target),
        ConnectionType = conn.ConnectionType

출력

SourceComponent TargetComponent SourceLabels TargetLabels 연결 유형
Switch1 Server1 ["Network", "Access"] ["Compute", "Production"] 이더넷

여러 레이블 조건으로 필터링

다음 예제에서는 여러 레이블 조건을 결합하여 네트워크 토폴로지에서 복잡한 패턴을 찾는 방법을 보여 줍니다. 이 쿼리는 프런트 엔드 구성 요소에서 미들웨어 계층을 통한 백 엔드 구성 요소로의 경로를 식별합니다.

그래프 모델 정의

.create-or-alter graph_model AppComponentGraph ```
{
  "Schema": {
    "Nodes": {
      "Frontend": {"ComponentName": "string"},
      "Middleware": {"ComponentName": "string"},
      "Backend": {"ComponentName": "string"}
    },
    "Edges": {
      "DEPENDS_ON": {"DependencyType": "string"}
    }
  },
  "Definition": {
    "Steps": [
      {
        "Kind": "AddNodes",
        "Query": "ComponentsTable | project Id, ComponentName, NodeLabels",
        "NodeIdColumn": "Id",
        "LabelsColumn": "NodeLabels"
      },
      {
        "Kind": "AddEdges",
        "Query": "DependenciesTable | project SourceId, TargetId, DependencyType, EdgeLabels",
        "SourceColumn": "SourceId",
        "TargetColumn": "TargetId",
        "Labels": ["DEPENDS_ON"],
        "LabelsColumn": "EdgeLabels"
      }
    ]
  }
}
```

쿼리 예제

graph('AppComponentGraph')
| graph-match (frontend)-[dep1]->(middleware)-[dep2]->(backend)
    where labels(frontend) has "Frontend" 
          and labels(middleware) has "Middleware" 
          and labels(backend) has "Backend"
    project 
        Path = strcat(frontend.ComponentName, " -> ", middleware.ComponentName, " -> ", backend.ComponentName),
        FrontendLabels = labels(frontend),
        MiddlewareLabels = labels(middleware),
        BackendLabels = labels(backend)

출력

경로 FrontendLabels 미들웨어라벨스 BackendLabels
WebUI -> APIGateway -> 데이터베이스 ["Frontend", "UserInterface"] ["미들웨어", "API"] ["백 엔드", "스토리지"]
WebUI -> APIGateway -> 캐시 ["Frontend", "UserInterface"] ["미들웨어", "API"] ["백 엔드", "캐시"]

all() 및 any() 함수와 함께 labels() 사용

다음 예제에서는 내부 labels() 매개 변수 없이 함수를 all() 사용하고 가변 길이 경로가 있는 함수를 사용하는 any() 방법을 보여 줍니다. 이 쿼리는 모든 중간 서비스에 "프로덕션" 레이블이 있고 하나 이상의 중간 서비스에 "중요" 레이블이 있는 서비스 메시에서 경로를 찾습니다.

그래프 모델 정의

.create-or-alter graph_model ServiceMeshGraph ```
{
  "Schema": {
    "Nodes": {
      "Service": {"ServiceName": "string", "Environment": "string"}
    },
    "Edges": {
      "CALLS": {"Protocol": "string"}
    }
  },
  "Definition": {
    "Steps": [
      {
        "Kind": "AddNodes",
        "Query": "ServicesTable | project Id, ServiceName, Environment, NodeLabels",
        "NodeIdColumn": "Id",
        "Labels": ["Service"],
        "LabelsColumn": "NodeLabels"
      },
      {
        "Kind": "AddEdges",
        "Query": "ServiceCallsTable | project SourceId, TargetId, Protocol, EdgeLabels",
        "SourceColumn": "SourceId",
        "TargetColumn": "TargetId",
        "Labels": ["CALLS"],
        "LabelsColumn": "EdgeLabels"
      }
    ]
  }
}
```

쿼리 예제

graph('ServiceMeshGraph')
| graph-match (source)-[calls*2..4]->(destination)
    where source.ServiceName == "UserService" and
          destination.ServiceName == "DatabaseService" and
          all(inner_nodes(calls), labels() has "Production") and
          any(inner_nodes(calls), labels() has "Critical")
    project 
        Path = strcat_array(map(inner_nodes(calls), ServiceName), " -> "),
        IntermediateLabels = map(inner_nodes(calls), labels()),
        CallProtocols = map(calls, Protocol)

출력

경로 IntermediateLabels CallProtocols
AuthService -> PaymentService [["Production", "Auth"], ["Production", "Critical", "Payment"]] ["HTTPS", "gRPC"]
CacheService -> PaymentService [["Production", "Cache"], ["Production", "Critical", "Payment"]] ["Redis", "gRPC"]