Skip to content

Commit

Permalink
Add '_monitoring' suffix to monitoring process names (elastic#27852)
Browse files Browse the repository at this point in the history
* Add '_monitoring' suffix to monitoring process names

Add '_monitoring' suffix to monitoring process names so that they can be
distinguished from other processes. This is relevant for the status
command where the beat instances appear the same in output. Changed the
output format of the human readable option to better align text with the
longer names.
  • Loading branch information
michel-laterman authored and wiwen committed Nov 1, 2021
1 parent c685141 commit 610cff2
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 5 deletions.
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
- Change output.elasticsearch.proxy_disabled flag to output.elasticsearch.proxy_disable so fleet uses it. {issue}27670[27670] {pull}27671[27671]
- Add validation for certificate flags to ensure they are absolute paths. {pull}27779[27779]
- Migrate state on upgrade {pull}27825[27825]
- Add "_monitoring" suffix to monitoring instance names to remove ambiguity with the status command. {issue}25449[25449]

==== New features

Expand Down
9 changes: 6 additions & 3 deletions x-pack/elastic-agent/pkg/agent/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"os"
"text/tabwriter"
"time"

"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -96,14 +97,16 @@ func humanOutput(w io.Writer, status *client.AgentStatus) error {
fmt.Fprint(w, "Applications: (none)\n")
} else {
fmt.Fprint(w, "Applications:\n")
tw := tabwriter.NewWriter(w, 4, 1, 2, ' ', 0)
for _, app := range status.Applications {
fmt.Fprintf(w, " * %s\t(%s)\n", app.Name, app.Status)
fmt.Fprintf(tw, " * %s\t(%s)\n", app.Name, app.Status)
if app.Message == "" {
fmt.Fprint(w, " (no message)\n")
fmt.Fprint(tw, "\t(no message)\n")
} else {
fmt.Fprintf(w, " %s\n", app.Message)
fmt.Fprintf(tw, "\t%s\n", app.Message)
}
}
tw.Flush()
}
return nil
}
Expand Down
125 changes: 125 additions & 0 deletions x-pack/elastic-agent/pkg/agent/cmd/status_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package cmd

import (
"os"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/control/client"
)

var testStatus = &client.AgentStatus{
Status: client.Healthy,
Message: "",
Applications: []*client.ApplicationStatus{{
ID: "id_1",
Name: "filebeat",
Status: client.Healthy,
Message: "Running",
Payload: nil,
}, {
ID: "id_2",
Name: "metricbeat",
Status: client.Healthy,
Message: "Running",
Payload: nil,
}, {
ID: "id_3",
Name: "filebeat_monitoring",
Status: client.Healthy,
Message: "Running",
Payload: nil,
}, {
ID: "id_4",
Name: "metricbeat_monitoring",
Status: client.Healthy,
Message: "Running",
Payload: nil,
},
},
}

func ExamplehumanOutput() {
humanOutput(os.Stdout, testStatus)
// Output:
// Status: HEALTHY
// Message: (no message)
// Applications:
// * filebeat (HEALTHY)
// Running
// * metricbeat (HEALTHY)
// Running
// * filebeat_monitoring (HEALTHY)
// Running
// * metricbeat_monitoring (HEALTHY)
// Running
}

func ExamplejsonOutput() {
jsonOutput(os.Stdout, testStatus)
// Output:
// {
// "Status": 2,
// "Message": "",
// "Applications": [
// {
// "ID": "id_1",
// "Name": "filebeat",
// "Status": 2,
// "Message": "Running",
// "Payload": null
// },
// {
// "ID": "id_2",
// "Name": "metricbeat",
// "Status": 2,
// "Message": "Running",
// "Payload": null
// },
// {
// "ID": "id_3",
// "Name": "filebeat_monitoring",
// "Status": 2,
// "Message": "Running",
// "Payload": null
// },
// {
// "ID": "id_4",
// "Name": "metricbeat_monitoring",
// "Status": 2,
// "Message": "Running",
// "Payload": null
// }
// ]
// }
}

func ExampleyamlOutput() {
yamlOutput(os.Stdout, testStatus)
// Output:
// status: 2
// message: ""
// applications:
// - id: id_1
// name: filebeat
// status: 2
// message: Running
// payload: {}
// - id: id_2
// name: metricbeat
// status: 2
// message: Running
// payload: {}
// - id: id_3
// name: filebeat_monitoring
// status: 2
// message: Running
// payload: {}
// - id: id_4
// name: metricbeat_monitoring
// status: 2
// message: Running
// payload: {}
}
6 changes: 4 additions & 2 deletions x-pack/elastic-agent/pkg/agent/operation/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,17 +305,19 @@ func (o *Operator) getApp(p Descriptor) (Application, error) {
var err error

monitor := o.monitor
appName := p.BinaryName()
if app.IsSidecar(p) {
// make watchers unmonitorable
monitor = noop.NewMonitor()
appName += "_monitoring"
}

if p.ServicePort() == 0 {
// Applications without service ports defined are ran as through the process application type.
a, err = process.NewApplication(
o.bgContext,
p.ID(),
p.BinaryName(),
appName,
o.pipelineID,
o.config.LoggingConfig.Level.String(),
desc,
Expand All @@ -331,7 +333,7 @@ func (o *Operator) getApp(p Descriptor) (Application, error) {
a, err = service.NewApplication(
o.bgContext,
p.ID(),
p.BinaryName(),
appName,
o.pipelineID,
o.config.LoggingConfig.Level.String(),
p.ServicePort(),
Expand Down

0 comments on commit 610cff2

Please sign in to comment.