ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

Skywalking-10:Skywalking查询协议——GraphQL

2021-10-02 12:58:56  阅读:238  来源: 互联网

标签:10 name graphql JS GraphQL query Skywalking id


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: "e8cf34a1d54a4058a8c98505877770e2@192.168.50.113",
                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
          }
        ]
      }
    }
  }
}

参考文档

标签:10,name,graphql,JS,GraphQL,query,Skywalking,id
来源: https://blog.csdn.net/q547550831/article/details/120584991

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有