Skip to content

Commit

Permalink
Include data streams summary in search responses
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoriano committed Jan 8, 2025
1 parent 44a0b9c commit c1a9a6d
Show file tree
Hide file tree
Showing 40 changed files with 28,371 additions and 1,499 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Include summary of data streams in search responses. [#1264](https://github.com/elastic/package-registry/pull/1264)

### Deprecated

### Known Issues
Expand Down
2 changes: 1 addition & 1 deletion packages/datastream.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type DataStream struct {
DatasetIsPrefix bool `config:"dataset_is_prefix" json:"dataset_is_prefix,omitempty" yaml:"dataset_is_prefix,omitempty"`

Title string `config:"title" json:"title" validate:"required"`
Release string `config:"release" json:"release"`
Release string `config:"release" json:"release,omitempty"`

// Deprecated: Replaced by elasticsearch.ingest_pipeline.name
IngestPipeline string `config:"ingest_pipeline,omitempty" json:"ingest_pipeline,omitempty" yaml:"ingest_pipeline,omitempty"`
Expand Down
1 change: 1 addition & 0 deletions packages/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type BasePackage struct {
Categories []string `config:"categories,omitempty" json:"categories,omitempty" yaml:"categories,omitempty"`
SignaturePath string `config:"signature_path,omitempty" json:"signature_path,omitempty" yaml:"signature_path,omitempty"`
Discovery *Discovery `config:"discovery,omitempty" json:"discovery,omitempty" yaml:"discovery,omitempty"`
DataStreams []*DataStream `config:"data_streams,omitempty" json:"data_streams,omitempty" yaml:"data_streams,omitempty"`
}

// BasePolicyTemplate is used for the package policy templates in the /search endpoint
Expand Down
24 changes: 21 additions & 3 deletions search.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func searchHandlerWithProxyMode(logger *zap.Logger, indexer Indexer, proxyMode *
}
}

data, err := getPackageOutput(r.Context(), packages)
data, err := getSearchOutput(r.Context(), packages)
if err != nil {
notFoundError(w, err)
return
Expand Down Expand Up @@ -166,7 +166,7 @@ func getSpecVersion(version string) (*semver.Version, error) {
return specVersion, nil
}

func getPackageOutput(ctx context.Context, packageList packages.Packages) ([]byte, error) {
func getSearchOutput(ctx context.Context, packageList packages.Packages) ([]byte, error) {
span, _ := apm.StartSpan(ctx, "GetPackageOutput", "app")
defer span.End()

Expand All @@ -175,7 +175,7 @@ func getPackageOutput(ctx context.Context, packageList packages.Packages) ([]byt

var output []packages.BasePackage
for _, p := range packageList {
data := p.BasePackage
data := getPackageSummaryOutput(p)
output = append(output, data)
}

Expand All @@ -186,3 +186,21 @@ func getPackageOutput(ctx context.Context, packageList packages.Packages) ([]byt

return util.MarshalJSONPretty(output)
}

func getPackageSummaryOutput(index *packages.Package) packages.BasePackage {
if len(index.DataStreams) == 0 {
return index.BasePackage
}

data := index.BasePackage
data.DataStreams = make([]*packages.DataStream, len(index.DataStreams))
for i, datastream := range index.DataStreams {
data.DataStreams[i] = &packages.DataStream{
Type: datastream.Type,
Dataset: datastream.Dataset,
Title: datastream.Title,
}
}

return data
}
103 changes: 102 additions & 1 deletion testdata/generated/search-all-proxy.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
},
"categories": [
"custom"
],
"data_streams": [
{
"type": "metrics",
"dataset": "agent_privileges.agent_privileges",
"title": "Agent privileges data stream"
}
]
},
{
Expand All @@ -35,6 +42,23 @@
],
"categories": [
"custom"
],
"data_streams": [
{
"type": "logs",
"dataset": "datasources.examplelog1",
"title": "Example dataset with inputs"
},
{
"type": "logs",
"dataset": "datasources.examplelog2",
"title": "Example dataset with inputs"
},
{
"type": "metrics",
"dataset": "datasources.examplemetric",
"title": "Example data stream with inputs"
}
]
},
{
Expand All @@ -53,6 +77,13 @@
},
"categories": [
"custom"
],
"data_streams": [
{
"type": "metrics",
"dataset": "elasticsearch_privileges.elasticsearch_privileges",
"title": "Elasticsearch privileges data stream"
}
]
},
{
Expand Down Expand Up @@ -82,6 +113,13 @@
"categories": [
"crm",
"azure"
],
"data_streams": [
{
"type": "logs",
"dataset": "nodirentries.foo",
"title": "Foo"
}
]
},
{
Expand Down Expand Up @@ -114,6 +152,13 @@
"categories": [
"crm",
"azure"
],
"data_streams": [
{
"type": "logs",
"dataset": "example.foo",
"title": "Foo"
}
]
},
{
Expand Down Expand Up @@ -144,7 +189,14 @@
"crm",
"azure"
],
"signature_path": "/epr/example/example-1.0.1.zip.sig"
"signature_path": "/epr/example/example-1.0.1.zip.sig",
"data_streams": [
{
"type": "logs",
"dataset": "example.foo",
"title": "Foo"
}
]
},
{
"name": "example",
Expand Down Expand Up @@ -179,6 +231,13 @@
"categories": [
"crm",
"azure"
],
"data_streams": [
{
"type": "logs",
"dataset": "example.foo",
"title": "Foo"
}
]
},
{
Expand Down Expand Up @@ -222,6 +281,13 @@
},
"categories": [
"custom"
],
"data_streams": [
{
"type": "metrics",
"dataset": "hidden.hidden",
"title": "Hidden data stream and ilm policy overrride"
}
]
},
{
Expand All @@ -240,6 +306,13 @@
},
"categories": [
"custom"
],
"data_streams": [
{
"type": "metrics",
"dataset": "ilm_policy.ilm_policy",
"title": "ILM policy overrride data stream"
}
]
},
{
Expand Down Expand Up @@ -333,6 +406,13 @@
"categories": [
"crm",
"azure"
],
"data_streams": [
{
"type": "logs",
"dataset": "integration_input.foo",
"title": "Foo"
}
]
},
{
Expand Down Expand Up @@ -512,6 +592,13 @@
"path": "/package/no_stream_configs/1.0.0",
"categories": [
"custom"
],
"data_streams": [
{
"type": "logs",
"dataset": "no_stream_configs.log",
"title": "Log Yaml pipeline"
}
]
},
{
Expand Down Expand Up @@ -550,6 +637,13 @@
"categories": [
"custom",
"web"
],
"data_streams": [
{
"type": "logs",
"dataset": "reference.reference",
"title": "Reference Logs Title"
}
]
},
{
Expand All @@ -563,6 +657,13 @@
"path": "/package/yamlpipeline/1.0.0",
"categories": [
"custom"
],
"data_streams": [
{
"type": "logs",
"dataset": "yamlpipeline.log",
"title": "Log Yaml pipeline"
}
]
}
]
Loading

0 comments on commit c1a9a6d

Please sign in to comment.