Skywalking-10:Skywalking查詢協議——GraphQL

GraphQL

GraphQL 基礎

參照Getting started with GraphQL Java and Spring Boot這篇文章學習即可

PS:可以使用 brew install --cask graphql-playground 安裝 graphql for mac 客戶端。

IDEA 怎麼調試 GraphQL 應用

安裝 JS GraphQL 插件

點擊JS GraphQL安裝插件

GraphQL 定義

schema.graphqls

type Query {
    bookById(id: ID): Book
}

type Book {
    id: ID
    name: String
    pageCount: Int
    author: Author
}

type Author {
    id: ID
    firstName: String
    lastName: String
}

GraphQL 配置文件

.graphqlconfig

{
  "name": "book-details",
  "schemaPath": "schema.graphqls",
  "extensions": {
    "endpoints": {
      "Default GraphQL Endpoint": {
        "url": "http://localhost:8080/graphql", // 請求路徑
        "headers": {
          "user-agent": "JS GraphQL"
        },
        "introspect": false
      }
    }
  }
}

創建一個查詢文件

query.graphql

# {"id": "book-1"}
query queryData($id: ID) {
    bookById(id: $id) {
        id name pageCount author {
            id firstName lastName
        }
    }
}

GraphQL 腳本目錄結構

resources
├── .graphqlconfig  # 配置文件
├── query.graphql   # 查詢文件
└── schema.graphqls # 定義文件

執行結果

file

file

GraphQL 在 Skywalking 中的應用

graphql 協議文件路徑: oap-server/server-query-plugin/query-graphql-plugin/src/main/resources/query-protocol 

GraphQL 配置文件

.graphqlconfig

{
  "name": "skywalking",
  "schemaPath": "schema.graphql",
  "extensions": {
    "endpoints": {
      "Default GraphQL Endpoint": {
        "url": "http://localhost:8080/graphql",
        "headers": {
          "user-agent": "JS GraphQL"
        },
        "introspect": true
      }
    }
  }
}

創建一個查詢文件

query.graphql

query queryData {
    readMetricsValues(
        duration: {start: "2021-07-03 1400",end: "2021-07-03 1401", step: MINUTE},
        condition: {
            name: "instance_jvm_thread_runnable_thread_count",
            entity: {
                scope: ServiceInstance,
                serviceName: "business-zone::projectA",
                serviceInstanceName: "[email protected]",
                normal: true
            }
        }
    ) { 
        label values{ values{ id value }}
    }
}

執行結果

{
  "data": {
    "readMetricsValues": {
      "values": {
        "values": [
          {
            "id": "202107031400_YnVzaW5lc3Mtem9uZTo6cHJvamVjdEE=.1_ZThjZjM0YTFkNTRhNDA1OGE4Yzk4NTA1ODc3NzcwZTJAMTkyLjE2OC41MC4xMTM=",
            "value": 22
          },
          {
            "id": "202107031401_YnVzaW5lc3Mtem9uZTo6cHJvamVjdEE=.1_ZThjZjM0YTFkNTRhNDA1OGE4Yzk4NTA1ODc3NzcwZTJAMTkyLjE2OC41MC4xMTM=",
            "value": 22
          }
        ]
      }
    }
  }
}

參考文檔

分享並記錄所學所見

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章