Skip to content

Commit 74fcbbb

Browse files
Merge pull request #73 from DataDog/tim.brown/add-synthetics-tests-search
feat(synthetics): add `synthetics tests search` command
2 parents 9aa734e + 8a700a9 commit 74fcbbb

2 files changed

Lines changed: 134 additions & 1 deletion

File tree

cmd/synthetics.go

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ monitor application performance and availability from various locations.
2222
2323
CAPABILITIES:
2424
• List synthetic tests
25+
• Search synthetic tests by text query
2526
• Get test details
2627
• Get test results
2728
• List test locations
@@ -31,6 +32,10 @@ EXAMPLES:
3132
# List all synthetic tests
3233
pup synthetics tests list
3334
35+
# Search tests by creator or team
36+
pup synthetics tests search --text='creator:"Jane Doe"'
37+
pup synthetics tests search --text="team:my-team"
38+
3439
# Get test details
3540
pup synthetics tests get test-id
3641
@@ -59,6 +64,79 @@ var syntheticsTestsGetCmd = &cobra.Command{
5964
RunE: runSyntheticsTestsGet,
6065
}
6166

67+
var syntheticsTestsSearchCmd = &cobra.Command{
68+
Use: "search",
69+
Short: "Search synthetic tests",
70+
Long: `Search synthetic tests using a text query.
71+
72+
Search allows filtering tests by free text or by facet queries, returning
73+
matching tests with pagination support.
74+
75+
QUERY SYNTAX:
76+
Free text matches against test names. Facet queries use the format
77+
facet:value or facet:"multi word value".
78+
79+
Common facets:
80+
creator Test creator name (e.g., creator:"Jane Doe")
81+
team Team tag (e.g., team:synthetics)
82+
env Environment tag (e.g., env:prod, env:staging)
83+
type Test type (api, api-multi, api-ssl, api-tcp, browser)
84+
state Test state (live, paused)
85+
status Monitor status (OK, Alert, "No Data")
86+
tag Any tag (e.g., tag:terraform:true)
87+
region Test location (e.g., region:aws:us-east-2)
88+
domain Target domain
89+
http_method HTTP method (GET, POST, DELETE, PATCH)
90+
http_path Request path
91+
muted Muted state (0, 1)
92+
ci_execution_rule CI rule (blocking, non_blocking, skipped)
93+
creation_source How the test was created (e.g., terraform, templates)
94+
mobile_platform Mobile platform (android, ios)
95+
notification Notification handle
96+
endpoint Full endpoint URL
97+
step_count Number of test steps
98+
99+
Use --facets-only to discover all available facets and their values
100+
for your organization.
101+
102+
FLAGS:
103+
--text Search text or facet query
104+
--include-full-config Include full test configuration in results
105+
--facets-only Return only facets (no test results)
106+
--start Pagination offset (default: 0)
107+
--count Number of results to return (default: 50)
108+
--sort Sort order (e.g., "name,asc")
109+
110+
EXAMPLES:
111+
# Search tests by name
112+
pup synthetics tests search --text="checkout"
113+
114+
# Find tests by creator
115+
pup synthetics tests search --text='creator:"Jane Doe"'
116+
117+
# Find tests for a team
118+
pup synthetics tests search --text="team:my-team"
119+
120+
# Filter by type and environment
121+
pup synthetics tests search --text="type:browser env:prod"
122+
123+
# Search with pagination
124+
pup synthetics tests search --text="api" --start=0 --count=100
125+
126+
# Discover available facets and values for your org
127+
pup synthetics tests search --facets-only`,
128+
RunE: runSyntheticsTestsSearch,
129+
}
130+
131+
var (
132+
syntheticsSearchText string
133+
syntheticsSearchIncludeFullConfig bool
134+
syntheticsSearchFacetsOnly bool
135+
syntheticsSearchStart int64
136+
syntheticsSearchCount int64
137+
syntheticsSearchSort string
138+
)
139+
62140
var syntheticsLocationsCmd = &cobra.Command{
63141
Use: "locations",
64142
Short: "Manage test locations",
@@ -71,7 +149,14 @@ var syntheticsLocationsListCmd = &cobra.Command{
71149
}
72150

73151
func init() {
74-
syntheticsTestsCmd.AddCommand(syntheticsTestsListCmd, syntheticsTestsGetCmd)
152+
syntheticsTestsSearchCmd.Flags().StringVar(&syntheticsSearchText, "text", "", "Search text query")
153+
syntheticsTestsSearchCmd.Flags().BoolVar(&syntheticsSearchIncludeFullConfig, "include-full-config", false, "Include full test configuration in results")
154+
syntheticsTestsSearchCmd.Flags().BoolVar(&syntheticsSearchFacetsOnly, "facets-only", false, "Return only facets (no test results)")
155+
syntheticsTestsSearchCmd.Flags().Int64Var(&syntheticsSearchStart, "start", 0, "Pagination offset")
156+
syntheticsTestsSearchCmd.Flags().Int64Var(&syntheticsSearchCount, "count", 50, "Number of results to return")
157+
syntheticsTestsSearchCmd.Flags().StringVar(&syntheticsSearchSort, "sort", "", "Sort order")
158+
159+
syntheticsTestsCmd.AddCommand(syntheticsTestsListCmd, syntheticsTestsGetCmd, syntheticsTestsSearchCmd)
75160
syntheticsLocationsCmd.AddCommand(syntheticsLocationsListCmd)
76161
syntheticsCmd.AddCommand(syntheticsTestsCmd, syntheticsLocationsCmd)
77162
}
@@ -113,6 +198,42 @@ func runSyntheticsTestsGet(cmd *cobra.Command, args []string) error {
113198
return formatAndPrint(resp, nil)
114199
}
115200

201+
func runSyntheticsTestsSearch(cmd *cobra.Command, args []string) error {
202+
client, err := getClient()
203+
if err != nil {
204+
return err
205+
}
206+
207+
api := datadogV1.NewSyntheticsApi(client.V1())
208+
opts := datadogV1.SearchTestsOptionalParameters{}
209+
210+
if syntheticsSearchText != "" {
211+
opts.WithText(syntheticsSearchText)
212+
}
213+
if syntheticsSearchIncludeFullConfig {
214+
opts.WithIncludeFullConfig(syntheticsSearchIncludeFullConfig)
215+
}
216+
if syntheticsSearchFacetsOnly {
217+
opts.WithFacetsOnly(syntheticsSearchFacetsOnly)
218+
}
219+
if cmd.Flags().Changed("start") {
220+
opts.WithStart(syntheticsSearchStart)
221+
}
222+
if cmd.Flags().Changed("count") {
223+
opts.WithCount(syntheticsSearchCount)
224+
}
225+
if syntheticsSearchSort != "" {
226+
opts.WithSort(syntheticsSearchSort)
227+
}
228+
229+
resp, r, err := api.SearchTests(client.Context(), opts)
230+
if err != nil {
231+
return formatAPIError("search synthetic tests", err, r)
232+
}
233+
234+
return formatAndPrint(resp, nil)
235+
}
236+
116237
func runSyntheticsLocationsList(cmd *cobra.Command, args []string) error {
117238
client, err := getClient()
118239
if err != nil {

cmd/synthetics_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ func TestRunSyntheticsTestsGet(t *testing.T) {
5656
}
5757
}
5858

59+
func TestRunSyntheticsTestsSearch(t *testing.T) {
60+
cleanup := setupSyntheticsTestClient(t)
61+
defer cleanup()
62+
var buf bytes.Buffer
63+
outputWriter = &buf
64+
defer func() { outputWriter = os.Stdout }()
65+
err := runSyntheticsTestsSearch(syntheticsTestsSearchCmd, []string{})
66+
if err == nil {
67+
t.Error("Expected error with mock client")
68+
}
69+
}
70+
5971
func TestRunSyntheticsLocationsList(t *testing.T) {
6072
cleanup := setupSyntheticsTestClient(t)
6173
defer cleanup()

0 commit comments

Comments
 (0)