github.com/hernad/nomad@v1.6.112/nomad/structs/search.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package structs 5 6 // Context defines the scope in which a search for Nomad object operates, and 7 // is also used to query the matching index value for this context. 8 type Context string 9 10 const ( 11 // Individual context types. 12 Allocs Context = "allocs" 13 Deployments Context = "deployment" 14 Evals Context = "evals" 15 Jobs Context = "jobs" 16 Nodes Context = "nodes" 17 NodePools Context = "node_pools" 18 Namespaces Context = "namespaces" 19 Quotas Context = "quotas" 20 Recommendations Context = "recommendations" 21 ScalingPolicies Context = "scaling_policy" 22 Plugins Context = "plugins" 23 Variables Context = "vars" 24 Volumes Context = "volumes" 25 26 // Subtypes used in fuzzy matching. 27 Groups Context = "groups" 28 Services Context = "services" 29 Tasks Context = "tasks" 30 Images Context = "images" 31 Commands Context = "commands" 32 Classes Context = "classes" 33 34 // Union context types. 35 All Context = "all" 36 ) 37 38 // SearchConfig is used in servers to configure search API options. 39 type SearchConfig struct { 40 // FuzzyEnabled toggles whether the FuzzySearch API is enabled. If not 41 // enabled, requests to /v1/search/fuzzy will reply with a 404 response code. 42 FuzzyEnabled bool `hcl:"fuzzy_enabled"` 43 44 // LimitQuery limits the number of objects searched in the FuzzySearch API. 45 // The results are indicated as truncated if the limit is reached. 46 // 47 // Lowering this value can reduce resource consumption of Nomad server when 48 // the FuzzySearch API is enabled. 49 LimitQuery int `hcl:"limit_query"` 50 51 // LimitResults limits the number of results provided by the FuzzySearch API. 52 // The results are indicated as truncate if the limit is reached. 53 // 54 // Lowering this value can reduce resource consumption of Nomad server per 55 // fuzzy search request when the FuzzySearch API is enabled. 56 LimitResults int `hcl:"limit_results"` 57 58 // MinTermLength is the minimum length of Text required before the FuzzySearch 59 // API will return results. 60 // 61 // Increasing this value can avoid resource consumption on Nomad server by 62 // reducing searches with less meaningful results. 63 MinTermLength int `hcl:"min_term_length"` 64 } 65 66 func (s *SearchConfig) Copy() *SearchConfig { 67 if s == nil { 68 return nil 69 } 70 71 ns := *s 72 return &ns 73 } 74 75 // SearchResponse is used to return matches and information about whether 76 // the match list is truncated specific to each type of Context. 77 type SearchResponse struct { 78 // Map of Context types to ids which match a specified prefix 79 Matches map[Context][]string 80 81 // Truncations indicates whether the matches for a particular Context have 82 // been truncated 83 Truncations map[Context]bool 84 85 QueryMeta 86 } 87 88 // SearchRequest is used to parameterize a request, and returns a 89 // list of matches made up of jobs, allocations, evaluations, and/or nodes, 90 // along with whether or not the information returned is truncated. 91 type SearchRequest struct { 92 // Prefix is what ids are matched to. I.e, if the given prefix were 93 // "a", potential matches might be "abcd" or "aabb" 94 Prefix string 95 96 // Context is the type that can be matched against. A context can be a job, 97 // node, evaluation, allocation, or empty (indicated every context should be 98 // matched) 99 Context Context 100 101 QueryOptions 102 } 103 104 // FuzzyMatch is used to describe the ID of an object which may be a machine 105 // readable UUID or a human readable Name. If the object is a component of a Job, 106 // the Scope is a list of IDs starting from Namespace down to the parent object of 107 // ID. 108 // 109 // e.g. A Task-level service would have scope like, 110 // 111 // ["<namespace>", "<job>", "<group>", "<task>"] 112 type FuzzyMatch struct { 113 ID string // ID is UUID or Name of object 114 Scope []string `json:",omitempty"` // IDs of parent objects 115 } 116 117 // FuzzySearchResponse is used to return fuzzy matches and information about 118 // whether the match list is truncated specific to each type of searchable Context. 119 type FuzzySearchResponse struct { 120 // Matches is a map of Context types to IDs which fuzzy match a specified query. 121 Matches map[Context][]FuzzyMatch 122 123 // Truncations indicates whether the matches for a particular Context have 124 // been truncated. 125 Truncations map[Context]bool 126 127 QueryMeta 128 } 129 130 // FuzzySearchRequest is used to parameterize a fuzzy search request, and returns 131 // a list of matches made up of jobs, allocations, evaluations, and/or nodes, 132 // along with whether or not the information returned is truncated. 133 type FuzzySearchRequest struct { 134 // Text is what names are fuzzy-matched to. E.g. if the given text were 135 // "py", potential matches might be "python", "mypy", etc. of jobs, nodes, 136 // allocs, groups, services, commands, images, classes. 137 Text string 138 139 // Context is the type that can be matched against. A Context of "all" indicates 140 // all Contexts types are queried for matching. 141 Context Context 142 143 QueryOptions 144 }