tencent cloud

Tencent Cloud Observability Platform

Release Notes and Announcements
Release Notes
Product Introduction
Overview
Strengths
Basic Features
Basic Concepts
Use Cases
Use Limits
Purchase Guide
Tencent Cloud Product Monitoring
Application Performance Management
Mobile App Performance Monitoring
Real User Monitoring
Cloud Automated Testing
Prometheus Monitoring
Grafana
EventBridge
PTS
Quick Start
Monitoring Overview
Instance Group
Tencent Cloud Product Monitoring
Application Performance Management
Real User Monitoring
Cloud Automated Testing
Performance Testing Service
Prometheus Getting Started
Grafana
Dashboard Creation
EventBridge
Alarm Service
Cloud Product Monitoring
Tencent Cloud Service Metrics
Operation Guide
CVM Agents
Cloud Product Monitoring Integration with Grafana
Troubleshooting
Practical Tutorial
Application Performance Management
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Parameter Information
FAQs
Mobile App Performance Monitoring
Overview
Operation Guide
Access Guide
Practical Tutorial
Tencent Cloud Real User Monitoring
Product Introduction
Operation Guide
Connection Guide
FAQs
Cloud Automated Testing
Product Introduction
Operation Guide
FAQs
Performance Testing Service
Overview
Operation Guide
Practice Tutorial
JavaScript API List
FAQs
Prometheus Monitoring
Product Introduction
Access Guide
Operation Guide
Practical Tutorial
Terraform
FAQs
Grafana
Product Introduction
Operation Guide
Guide on Grafana Common Features
FAQs
Dashboard
Overview
Operation Guide
Alarm Management
Console Operation Guide
Troubleshooting
FAQs
EventBridge
Product Introduction
Operation Guide
Practical Tutorial
FAQs
Report Management
FAQs
General
Alarm Service
Concepts
Monitoring Charts
CVM Agents
Dynamic Alarm Threshold
CM Connection to Grafana
Documentation Guide
Related Agreements
Application Performance Management Service Level Agreement
APM Privacy Policy
APM Data Processing And Security Agreement
RUM Service Level Agreement
Mobile Performance Monitoring Service Level Agreement
Cloud Automated Testing Service Level Agreement
Prometheus Service Level Agreement
TCMG Service Level Agreements
PTS Service Level Agreement
PTS Use Limits
Cloud Monitor Service Level Agreement
API Documentation
History
Introduction
API Category
Making API Requests
Monitoring Data Query APIs
Alarm APIs
Legacy Alert APIs
Notification Template APIs
TMP APIs
Grafana Service APIs
Event Center APIs
TencentCloud Managed Service for Prometheus APIs
Monitoring APIs
Data Types
Error Codes
Glossary

Data Extraction Response

PDF
Mode fokus
Ukuran font
Terakhir diperbarui: 2025-03-10 22:20:39

Overview

If you want to dynamically extract data from the response of a request, PTS not only supports simple string matching (equal to or containing), but also supports Jsonpath extractor and regular expression extractor, so that you can achieve more flexible extraction logic.

Basic Usage

When you orchestrate or debug requests in the PTS stress test scenario, if you need to dynamically extract data values from the response to set checkpoints for the current request, inject parameters for subsequent requests, or debug specific response fields in debug mode, you can use the data extractor to parse and extract specific fields from the response data.
Response data extraction should be used during the orchestration or debugging scenario. For details on how to orchestrate or debug a scenario, please refer to Performance Testing in Simple Mode, Performance Testing in Script Mode, and Debugging Scenario.

Use Cases

In Simple Mode, you can select a specific extraction method from the list and then enter an expression that conforms to the extractor syntax in the text box. For example, using the JSONPath extractor:

In Script Mode, you can use Get JSON field values to implement the logic for extracting data in the script. For example, using the JSONPath extractor:


Extractor Type

JSONPath Extractor

The JSONPath extractor is suitable for extracting data from JSON-type response bodies. Common syntax of JSONPath expressions:
Operator
Description
@
The current node.
*
Wildcard, which can match any node name or index value.
.<name>
Use "." to match child nodes.
[<number> (, <number>)]
Retrieve one or more elements in an array using [].
[start:end]
Array slicing
[?(<expression>)]
Filter data with a Boolean expression.
 In script mode, the usage of Jsonpath and its result examples are as follows:
import jsonpath from 'pts/jsonpath';
export default function () {
const json = JSON.stringify({
"name": {"first": "Tom", "last": "Anderson"},
"age": 37,
"children": ["Sara", "Alex", "Jack"],
"fav.movie": "Deer Hunter",
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
]
});
console.log(jsonpath.get(json, 'name.last')); // Anderson
console.log(jsonpath.get(json, 'age')); // 37
console.log(jsonpath.get(json, 'children')); // Sara,Alex,Jack
console.log(jsonpath.get(json, 'children[*]')); // Sara,Alex,Jack
console.log(jsonpath.get(json, 'children.[0]')); // Sara
console.log(jsonpath.get(json, 'children[1:2]')); // Alex,Jack
console.log(jsonpath.get(json, 'children[1, 2]')); // Alex,Jack
console.log(jsonpath.get(json, 'friends[:].first')); // Dale,Roger,Jane
console.log(jsonpath.get(json, 'friends[1].last')); // Craig
console.log(jsonpath.get(json, 'friends[?(@.age > 45)].last')); // Craig,Murphy
console.log(jsonpath.get(json, 'friends[?(@.first =~ /D.*e/)].last')); // Murphy
};

Regular Expression Extractor

The Regular Expression Extractor is suitable for extracting data from text-based responses. PTS Regular Expressions comply with JavaScript native syntax. For details, see Regular Expression.
Taking PTS scenario debugging as an example, the usage of the Regular Expression Extractor is as follows:

Taking the script mode scenario to set a checkpoint as an example, the usage of the regular expression extractor is as follows:

import { sleep, check } from "pts";
import http from "pts/http";

export default function main() {
let response;

response = http.get("http://mockhttpbin.pts.svc.cluster.local/get?name=hello");
check("body matches /h[a-z]*o/", () => {
const expr = new RegExp("h[a-z]*o");
return expr.test(response.body);
});
}




Bantuan dan Dukungan

Apakah halaman ini membantu?

masukan