Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pipeline name refs #4489

Merged
merged 3 commits into from
Dec 4, 2020
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"description": "Default enrichment for APM events",
"processors": [
{
"pipeline": {
"name": "metrics-apm.internal-0.1.0-apm_user_agent"
}
},
{
"pipeline": {
"name": "metrics-apm.internal-0.1.0-apm_user_geo"
}
},
{
"pipeline": {
"name": "metrics-apm.internal-0.1.0-apm_ingest_timestamp"
}
},
{
"pipeline": {
"name": "metrics-apm.internal-0.1.0-apm_remove_span_metadata"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
title: APM internal metrics
type: metrics
dataset: apm.internal
ingest_pipeline: apm
axw marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"processors": [
{
"pipeline": {
"name": "apm_user_agent"
"name": "logs-apm.error-0.1.0-apm_user_agent"
}
},
{
"pipeline": {
"name": "apm_user_geo"
"name": "logs-apm.error-0.1.0-apm_user_geo"
}
},
{
"pipeline": {
"name": "apm_ingest_timestamp"
"name": "logs-apm.error-0.1.0-apm_ingest_timestamp"
}
},
{
"pipeline": {
"name": "apm_remove_span_metadata"
"name": "logs-apm.error-0.1.0-apm_remove_span_metadata"
}
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"processors": [
{
"pipeline": {
"name": "apm_user_agent"
"name": "metrics-apm-0.1.0-apm_user_agent"
}
},
{
"pipeline": {
"name": "apm_user_geo"
"name": "metrics-apm-0.1.0-apm_user_geo"
}
},
{
"pipeline": {
"name": "apm_ingest_timestamp"
"name": "metrics-apm-0.1.0-apm_ingest_timestamp"
}
},
{
"pipeline": {
"name": "apm_remove_span_metadata"
"name": "metrics-apm-0.1.0-apm_remove_span_metadata"
}
}
]
Expand Down
1 change: 0 additions & 1 deletion apmpackage/apm/0.1.0/data_stream/metrics/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
title: APM application metrics
type: metrics
dataset: apm
ingest_pipeline: apm
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"processors": [
{
"pipeline": {
"name": "apm_user_agent"
"name": "profiles-apm-0.1.0-apm_user_agent"
}
},
{
"pipeline": {
"name": "apm_user_geo"
"name": "profiles-apm-0.1.0-apm_user_geo"
}
},
{
"pipeline": {
"name": "apm_ingest_timestamp"
"name": "profiles-apm-0.1.0-apm_ingest_timestamp"
}
},
{
"pipeline": {
"name": "apm_remove_span_metadata"
"name": "profiles-apm-0.1.0-apm_remove_span_metadata"
}
}
]
Expand Down
1 change: 0 additions & 1 deletion apmpackage/apm/0.1.0/data_stream/profiles/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
title: APM profiles
type: metrics
dataset: apm.profiling
ingest_pipeline: apm

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
"processors": [
{
"pipeline": {
"name": "apm_user_agent"
"name": "traces-apm-0.1.0-apm_user_agent"
}
},
{
"pipeline": {
"name": "apm_user_geo"
"name": "traces-apm-0.1.0-apm_user_geo"
}
},
{
"pipeline": {
"name": "apm_ingest_timestamp"
"name": "traces-apm-0.1.0-apm_ingest_timestamp"
}
},
{
"pipeline": {
"name": "apm_remove_span_metadata"
"name": "traces-apm-0.1.0-apm_remove_span_metadata"
}
}
]
Expand Down
1 change: 0 additions & 1 deletion apmpackage/apm/0.1.0/data_stream/traces/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
title: APM traces
type: traces
dataset: apm
ingest_pipeline: apm
87 changes: 78 additions & 9 deletions apmpackage/cmd/gen-package/genpipelines.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,68 @@ package main

import (
"encoding/json"
"errors"
"io/ioutil"
"os"
"path/filepath"
)

var streamMappings = map[string]string{
"logs": "logs-apm.error",
"traces": "traces-apm",
"metrics": "metrics-apm",
"internal_metrics": "metrics-apm.internal",
"profiles": "profiles-apm",
}

type PipelineDef struct {
ID string `json:"id"`
Body PipelineBody `json:"body"`
}

type PipelineBody struct {
Description string `json:"description"`
Processors []Processor `json:"processors"`
}

type Processor struct {
Pipeline *Pipeline `json:"pipeline,omitempty"`
m map[string]interface{}
}

type Pipeline struct {
Name string `json:"name"`
}

type _Processor Processor

func (p *Processor) UnmarshalJSON(bytes []byte) error {
aux := _Processor{}
err := json.Unmarshal(bytes, &aux)
if err != nil {
return err
}

*p = Processor(aux)
m := make(map[string]interface{})

err = json.Unmarshal(bytes, &m)
if err != nil {
return err
}
delete(m, "pipeline")
p.m = m
return nil
}

func (p *Processor) MarshalJSON() ([]byte, error) {
aux := _Processor(*p)
if p.Pipeline != nil {
return json.Marshal(aux)
}
return json.Marshal(p.m)
}

func generatePipelines(version, dataStream string) {
pipelines, err := os.Open("ingest/pipeline/definition.json")
if err != nil {
Expand All @@ -36,29 +93,41 @@ func generatePipelines(version, dataStream string) {
panic(err)
}

var definitions = make([]map[string]interface{}, 0)
var definitions = make([]PipelineDef, 0)
err = json.Unmarshal(bytes, &definitions)
if err != nil {
panic(err)
}

os.MkdirAll(pipelinesPath(version, dataStream), 0755)

var apmPipeline PipelineBody
for _, definition := range definitions {
pipeline, ok := definition["body"]
if !ok {
continue
}
id, ok := definition["id"]
if !ok {
pipeline := definition.Body
if definition.ID == "apm" {
apmPipeline = pipeline
continue
}

out, err := json.MarshalIndent(pipeline, "", " ")
if err != nil {
panic(err)
}
fName := filepath.Join(pipelinesPath(version, dataStream), id.(string)+".json")
fName := filepath.Join(pipelinesPath(version, dataStream), definition.ID+".json")
ioutil.WriteFile(fName, out, 0644)
}

for _, p := range apmPipeline.Processors {
if p.Pipeline == nil {
// should not happen, lets panic loudly
panic(errors.New("expected pipeline processor"))
}
// name is updated to match the one generated by Fleet when installs the pipelines
p.Pipeline.Name = streamMappings[dataStream] + "-" + version + "-" + p.Pipeline.Name
jalvz marked this conversation as resolved.
Show resolved Hide resolved
}
out, err := json.MarshalIndent(apmPipeline, "", " ")
if err != nil {
panic(err)
}
fName := filepath.Join(pipelinesPath(version, dataStream), "default.json")
ioutil.WriteFile(fName, out, 0644)
}
7 changes: 1 addition & 6 deletions apmpackage/cmd/gen-package/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/elastic/apm-server/cmd"
"github.com/elastic/beats/v7/libbeat/common"
Expand All @@ -46,11 +45,6 @@ func main() {
for dataStream := range inputFields {
generatePipelines(packageVersion, dataStream)
}
// hack, remove when bugfix comes to Kibana
bad := filepath.Join(pipelinesPath(packageVersion, "logs"), "apm.json")
good := filepath.Join(pipelinesPath(packageVersion, "logs"), "default.json")
os.Rename(bad, good)

generateDocs(inputFields, packageVersion)
log.Printf("Package fields and docs generated for version %s (stack %s)", packageVersion, stackVersion.String())
}
Expand All @@ -66,6 +60,7 @@ func clear(version string) {
if f.IsDir() {
os.Remove(ecsFilePath(version, f.Name()))
os.Remove(fieldsFilePath(version, f.Name()))
os.RemoveAll(pipelinesPath(version, f.Name()))
}
}
ioutil.WriteFile(docsFilePath(version), nil, 0644)
Expand Down