Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions internal/packages/assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"os"
"path/filepath"

"gopkg.in/yaml.v3"

"github.com/elastic/elastic-package/internal/multierror"
)

Expand Down Expand Up @@ -39,13 +41,13 @@ func newAssetTypeWithFolder(typeName AssetType, folderName string) assetTypeFold
var (
AssetTypeElasticsearchIndexTemplate = newAssetType("index_template")
AssetTypeElasticsearchIngestPipeline = newAssetType("ingest_pipeline")

AssetTypeKibanaSavedSearch = newAssetType("search")
AssetTypeKibanaVisualization = newAssetType("visualization")
AssetTypeKibanaDashboard = newAssetType("dashboard")
AssetTypeKibanaMap = newAssetType("map")
AssetTypeKibanaLens = newAssetType("lens")
AssetTypeSecurityRule = newAssetTypeWithFolder("security-rule", "security_rule")
AssetTypeKibanaDashboard = newAssetType("dashboard")
AssetTypeKibanaLens = newAssetType("lens")
AssetTypeKibanaMap = newAssetType("map")
AssetTypeKibanaSavedSearch = newAssetType("search")
AssetTypeKibanaTag = newAssetType("tag")
AssetTypeKibanaVisualization = newAssetType("visualization")
AssetTypeSecurityRule = newAssetTypeWithFolder("security-rule", "security_rule")
)

// Asset represents a package asset to be loaded into Kibana or Elasticsearch.
Expand All @@ -68,6 +70,12 @@ func LoadPackageAssets(pkgRootPath string) ([]Asset, error) {
return nil, fmt.Errorf("could not load kibana assets: %w", err)
}

tags, err := loadKibanaTags(pkgRootPath)
if err != nil {
return nil, fmt.Errorf("could not load kibana tags: %w", err)
}
assets = append(assets, tags...)

a, err := loadElasticsearchAssets(pkgRootPath)
if err != nil {
return a, fmt.Errorf("could not load elasticsearch assets: %w", err)
Expand All @@ -85,10 +93,11 @@ func loadKibanaAssets(pkgRootPath string) ([]Asset, error) {

assetTypes = []assetTypeFolder{
AssetTypeKibanaDashboard,
AssetTypeKibanaVisualization,
AssetTypeKibanaSavedSearch,
AssetTypeKibanaMap,
AssetTypeKibanaLens,
AssetTypeKibanaMap,
AssetTypeKibanaSavedSearch,
AssetTypeKibanaTag,
AssetTypeKibanaVisualization,
AssetTypeSecurityRule,
}

Expand All @@ -112,6 +121,34 @@ func loadKibanaAssets(pkgRootPath string) ([]Asset, error) {
return assets, nil
}

func loadKibanaTags(pkgRootPath string) ([]Asset, error) {
tagsFilePath := filepath.Join(pkgRootPath, "kibana", "tags.yml")
tagsFile, err := os.ReadFile(tagsFilePath)
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
if err != nil {
return nil, fmt.Errorf("reading tags file failed: %w", err)
}

type tag struct {
Text string `yaml:"text"`
}
var tags []tag
err = yaml.Unmarshal(tagsFile, &tags)
if err != nil {
return nil, fmt.Errorf("parsing tags file failed: %w", err)
}

assets := make([]Asset, len(tags))
for i, tag := range tags {
assets[i].ID = tag.Text
assets[i].Type = AssetTypeKibanaTag.typeName
assets[i].SourcePath = tagsFilePath
}
return assets, nil
}

func loadElasticsearchAssets(pkgRootPath string) ([]Asset, error) {
packageManifestPath := filepath.Join(pkgRootPath, PackageManifestFile)
pkgManifest, err := ReadPackageManifest(packageManifestPath)
Expand Down
5 changes: 5 additions & 0 deletions internal/testrunner/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ func GenerateBasePackageCoverageReport(pkgName, rootPath, format string) (Covera
return nil
}

// Exclude validation configuration from coverage reports.
if d.Name() == "validation.yml" && filepath.Dir(match) == filepath.Clean(rootPath) {
return nil
}

fileCoverage, err := generateBaseFileCoverageReport(repoPath, pkgName, match, format, false)
if err != nil {
return fmt.Errorf("failed to generate base coverage for \"%s\": %w", match, err)
Expand Down
2 changes: 2 additions & 0 deletions internal/testrunner/runners/system/tester.go
Original file line number Diff line number Diff line change
Expand Up @@ -2503,6 +2503,8 @@ func (r *tester) generateCoverageReport(pkgName string) (testrunner.CoverageRepo
filepath.Join(r.packageRootPath, "fields", "*.yml"),
filepath.Join(r.packageRootPath, "data_stream", dsPattern, "manifest.yml"),
filepath.Join(r.packageRootPath, "data_stream", dsPattern, "fields", "*.yml"),
filepath.Join(r.packageRootPath, "elasticsearch", "transform", "*", "*.yml"),
filepath.Join(r.packageRootPath, "elasticsearch", "transform", "*", "fields", "*.yml"),
}

return testrunner.GenerateBaseFileCoverageReportGlob(pkgName, patterns, r.coverageType, true)
Expand Down