Skip to content

Commit

Permalink
cmd: replace fake-exporter by demo-exporter
Browse files Browse the repository at this point in the history
Also propagate this rename to configuration and code. It makes easier
to understand the purpose of such a command in the provided
`docker-compose` file.
  • Loading branch information
vincentbernat committed Jul 26, 2022
1 parent 30fe6bb commit 684a219
Show file tree
Hide file tree
Showing 29 changed files with 72 additions and 67 deletions.
7 changes: 5 additions & 2 deletions akvorado.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ inlet:
ClassifyExternal()
- ClassifyInternal()

.fake-exporter-flows:
# The remaining of this configuration file should be removed if you
# don't want to get demo data.

.demo-exporter-flows:
- &http-src
src-port: [80, 443]
dst-port: 0
Expand Down Expand Up @@ -157,7 +160,7 @@ inlet:
src-net: 2a01:cb00::/32
src-as: [12322, 3215, 3303, 15557, 3320, 13335, 6185, 202818, 60068, 16276, 8075, 32590]

fake-exporter:
demo-exporter:
- snmp:
name: th2-edge1.example.com
interfaces:
Expand Down
54 changes: 27 additions & 27 deletions cmd/fake-exporter.go → cmd/demo-exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,68 @@ import (
"akvorado/common/daemon"
"akvorado/common/http"
"akvorado/common/reporter"
"akvorado/fakeexporter"
"akvorado/fakeexporter/flows"
"akvorado/fakeexporter/snmp"
"akvorado/demoexporter"
"akvorado/demoexporter/flows"
"akvorado/demoexporter/snmp"
)

// FakeExporterConfiguration represents the configuration file for the fake exporter command.
type FakeExporterConfiguration struct {
// DemoExporterConfiguration represents the configuration file for the demo exporter command.
type DemoExporterConfiguration struct {
Reporting reporter.Configuration
HTTP http.Configuration
FakeExporter fakeexporter.Configuration `mapstructure:",squash" yaml:",inline"`
DemoExporter demoexporter.Configuration `mapstructure:",squash" yaml:",inline"`
SNMP snmp.Configuration
Flows flows.Configuration
}

// Reset sets the default configuration for the fake exporter command.
func (c *FakeExporterConfiguration) Reset() {
*c = FakeExporterConfiguration{
// Reset sets the default configuration for the demo exporter command.
func (c *DemoExporterConfiguration) Reset() {
*c = DemoExporterConfiguration{
HTTP: http.DefaultConfiguration(),
Reporting: reporter.DefaultConfiguration(),
FakeExporter: fakeexporter.DefaultConfiguration(),
DemoExporter: demoexporter.DefaultConfiguration(),
}
}

type fakeExporterOptions struct {
type demoExporterOptions struct {
ConfigRelatedOptions
CheckMode bool
}

// FakeExporterOptions stores the command-line option values for the
// fake exporter command.
var FakeExporterOptions fakeExporterOptions
// DemoExporterOptions stores the command-line option values for the
// demo exporter command.
var DemoExporterOptions demoExporterOptions

var fakeExporterCmd = &cobra.Command{
Use: "fake-exporter",
var demoExporterCmd = &cobra.Command{
Use: "demo-exporter",
Short: "Start a synthetic exporter",
Long: `For demo and testing purpose, this service exports synthetic flows
and answers SNMP requests.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
config := FakeExporterConfiguration{}
FakeExporterOptions.Path = args[0]
if err := FakeExporterOptions.Parse(cmd.OutOrStdout(), "fake-exporter", &config); err != nil {
config := DemoExporterConfiguration{}
DemoExporterOptions.Path = args[0]
if err := DemoExporterOptions.Parse(cmd.OutOrStdout(), "demo-exporter", &config); err != nil {
return err
}

r, err := reporter.New(config.Reporting)
if err != nil {
return fmt.Errorf("unable to initialize reporter: %w", err)
}
return fakeExporterStart(r, config, FakeExporterOptions.CheckMode)
return demoExporterStart(r, config, DemoExporterOptions.CheckMode)
},
}

func init() {
RootCmd.AddCommand(fakeExporterCmd)
fakeExporterCmd.Flags().BoolVarP(&FakeExporterOptions.ConfigRelatedOptions.Dump, "dump", "D", false,
RootCmd.AddCommand(demoExporterCmd)
demoExporterCmd.Flags().BoolVarP(&DemoExporterOptions.ConfigRelatedOptions.Dump, "dump", "D", false,
"Dump configuration before starting")
fakeExporterCmd.Flags().BoolVarP(&FakeExporterOptions.CheckMode, "check", "C", false,
demoExporterCmd.Flags().BoolVarP(&DemoExporterOptions.CheckMode, "check", "C", false,
"Check configuration, but does not start")
}

func fakeExporterStart(r *reporter.Reporter, config FakeExporterConfiguration, checkOnly bool) error {
func demoExporterStart(r *reporter.Reporter, config DemoExporterConfiguration, checkOnly bool) error {
daemonComponent, err := daemon.New(r)
if err != nil {
return fmt.Errorf("unable to initialize daemon component: %w", err)
Expand All @@ -95,7 +95,7 @@ func fakeExporterStart(r *reporter.Reporter, config FakeExporterConfiguration, c
if err != nil {
return fmt.Errorf("unable to initialize flows component: %w", err)
}
fakeExporterComponent, err := fakeexporter.New(r, config.FakeExporter, fakeexporter.Dependencies{
demoExporterComponent, err := demoexporter.New(r, config.DemoExporter, demoexporter.Dependencies{
SNMP: snmpComponent,
Flows: flowsComponent,
})
Expand All @@ -104,7 +104,7 @@ func fakeExporterStart(r *reporter.Reporter, config FakeExporterConfiguration, c
}

// Expose some informations and metrics
addCommonHTTPHandlers(r, "fake-exporter", httpComponent)
addCommonHTTPHandlers(r, "demo-exporter", httpComponent)
versionMetrics(r)

// If we only asked for a check, stop here.
Expand All @@ -117,7 +117,7 @@ func fakeExporterStart(r *reporter.Reporter, config FakeExporterConfiguration, c
httpComponent,
snmpComponent,
flowsComponent,
fakeExporterComponent,
demoExporterComponent,
}
return StartStopComponents(r, daemonComponent, components)
}
8 changes: 4 additions & 4 deletions cmd/fake-exporter_test.go → cmd/demo-exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"akvorado/common/reporter"
)

func TestFakeExporterStart(t *testing.T) {
func TestDemoExporterStart(t *testing.T) {
r := reporter.NewMock(t)
config := FakeExporterConfiguration{}
config := DemoExporterConfiguration{}
config.Reset()
if err := fakeExporterStart(r, config, true); err != nil {
t.Fatalf("fakeExporterStart() error:\n%+v", err)
if err := demoExporterStart(r, config, true); err != nil {
t.Fatalf("demoExporterStart() error:\n%+v", err)
}
}
8 changes: 4 additions & 4 deletions cmd/orchestrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type OrchestratorConfiguration struct {
// Other service configurations
Inlet []InletConfiguration
Console []ConsoleConfiguration
FakeExporter []FakeExporterConfiguration
DemoExporter []DemoExporterConfiguration
}

// Reset resets the configuration of the orchestrator command to its default value.
Expand All @@ -47,7 +47,7 @@ func (c *OrchestratorConfiguration) Reset() {
// Other service configurations
Inlet: []InletConfiguration{inletConfiguration},
Console: []ConsoleConfiguration{consoleConfiguration},
FakeExporter: []FakeExporterConfiguration{},
DemoExporter: []DemoExporterConfiguration{},
}
}

Expand Down Expand Up @@ -141,8 +141,8 @@ func orchestratorStart(r *reporter.Reporter, config OrchestratorConfiguration, c
for idx := range config.Console {
orchestratorComponent.RegisterConfiguration(orchestrator.ConsoleService, config.Console[idx])
}
for idx := range config.FakeExporter {
orchestratorComponent.RegisterConfiguration(orchestrator.FakeExporterService, config.FakeExporter[idx])
for idx := range config.DemoExporter {
orchestratorComponent.RegisterConfiguration(orchestrator.DemoExporterService, config.DemoExporter[idx])
}

// Expose some informations and metrics
Expand Down
5 changes: 3 additions & 2 deletions console/data/docs/00-intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ Once running, *Akvorado* web interface should be running on port 8080.

A few synthetic flows are generated in the background. They can be
disabled by removing the `akvorado-exporter*` services from
`docker-compose.yml` (or you can just stop them with `docker-compose
stop akvorado-exporter{1,2,3,4}`).
`docker-compose.yml`, or by stopping them with `docker-compose stop
akvorado-exporter{1,2,3,4}`, or by removing the associated
configuration in `akvorado.yaml`.

If you want to send you own flows, the inlet is accepting both NetFlow
(port 2055) and sFlow (port 6343). You should also customize some
Expand Down
4 changes: 2 additions & 2 deletions console/data/docs/02-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,9 @@ database:
dsn: /var/lib/akvorado/console.sqlite
```

## Fake exporter service
## Demo exporter service

For testing purpose, it is possible to generate flows using the fake
For testing purpose, it is possible to generate flows using the demo
exporter service. It features a NetFlow generate and a simple SNMP
agent.

Expand Down
4 changes: 2 additions & 2 deletions console/data/docs/03-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ The final SQL query sent to ClickHouse is logged inside the console
after a successful request. It should be noted than using ports or
addresses prevent the use of aggregated data and are therefore slower.

## Fake exporter service
## Demo exporter service

The fake exporter service simulates a NetFlow exporter as well as a
The demo exporter service simulates a NetFlow exporter as well as a
simple SNMP agent.

## Other commands
Expand Down
3 changes: 2 additions & 1 deletion console/data/docs/99-changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ identified with a specific icon:
- 🩹: bug fix
- 🌱: miscellaneous change

## Unreleased
## 1.5.3 - 2022-07-26

- 💥 *cmd*: replace the `fake-exporter` subcommand by `demo-exporter` to make easier to understand its purpose
- 🌱 *console*: make `<<` and `!<<` operators more efficient

## 1.5.2 - 2022-07-26
Expand Down
6 changes: 3 additions & 3 deletions fakeexporter/config.go → demoexporter/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only

package fakeexporter
package demoexporter

// Configuration describes the configuration for the fake exporter component.
// Configuration describes the configuration for the demo exporter component.
type Configuration struct {
}

// DefaultConfiguration represents the default configuration for the fake exporter component.
// DefaultConfiguration represents the default configuration for the demo exporter component.
func DefaultConfiguration() Configuration {
return Configuration{}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion fakeexporter/flows/root.go → demoexporter/flows/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func New(r *reporter.Reporter, config Configuration, dependencies Dependencies)
[]string{"error"},
)

c.d.Daemon.Track(&c.t, "fake-exporter/flows")
c.d.Daemon.Track(&c.t, "demo-exporter/flows")
return &c, nil
}

Expand Down
File renamed without changes.
14 changes: 7 additions & 7 deletions fakeexporter/root.go → demoexporter/root.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only

// Package fakeexporter simulates an exporter (NetFlow and SNMP)
package fakeexporter
// Package demoexporter simulates an exporter (NetFlow and SNMP)
package demoexporter

import (
"akvorado/common/reporter"
"akvorado/fakeexporter/flows"
"akvorado/fakeexporter/snmp"
"akvorado/demoexporter/flows"
"akvorado/demoexporter/snmp"
)

// Component represents the fake exporter service.
// Component represents the demo exporter service.
type Component struct {
r *reporter.Reporter
d *Dependencies
config Configuration
}

// Dependencies define the dependencies of the fake exporter service.
// Dependencies define the dependencies of the demo exporter service.
type Dependencies struct {
SNMP *snmp.Component
Flows *flows.Component
}

// New creates a new fake exporter service.
// New creates a new demo exporter service.
func New(r *reporter.Reporter, config Configuration, dependencies Dependencies) (*Component, error) {
c := Component{
r: r,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func TestDefaultConfiguration(t *testing.T) {
config := DefaultConfiguration()
config.Name = "fake"
config.Name = "demo"
config.Interfaces = map[int]string{
1: "Transit: Cogent",
2: "Core",
Expand Down
2 changes: 1 addition & 1 deletion fakeexporter/snmp/root.go → demoexporter/snmp/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func New(r *reporter.Reporter, config Configuration, dependencies Dependencies)
[]string{"oid"},
)

c.d.Daemon.Track(&c.t, "fake-exporter/snmp")
c.d.Daemon.Track(&c.t, "demo-exporter/snmp")
return &c, nil
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func TestSNMPServer(t *testing.T) {
config := Configuration{
Name: "fake",
Name: "demo",
Interfaces: map[int]string{
1: "transit: cogent",
2: "pni: netflix",
Expand Down Expand Up @@ -50,7 +50,7 @@ func TestSNMPServer(t *testing.T) {
expected := []gosnmp.SnmpPDU{
{
Name: ".1.3.6.1.2.1.1.5.0",
Value: []byte("fake"),
Value: []byte("demo"),
Type: gosnmp.OctetString,
}, {
Name: ".1.3.6.1.2.1.2.2.1.2.1",
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestSNMPServer(t *testing.T) {
t.Fatalf("Walk() (-got, +want):\n%s", diff)
}

gotMetrics := r.GetMetrics("akvorado_fakeexporter_")
gotMetrics := r.GetMetrics("akvorado_demoexporter_")
expectedMetrics := map[string]string{
`snmp_requests{oid="1.3.6.1.2.1.1.5.0"}`: "1",
`snmp_requests{oid="1.3.6.1.2.1.2.2.1.2.1"}`: "1",
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ services:
network_mode: host
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
# Remove the following exporters if you don't want to get fake data
# Remove the following exporters if you don't want to get demo data.
akvorado-exporter0: &exporter
<<: *akvorado-image
restart: unless-stopped
command: fake-exporter http://akvorado-orchestrator:8080#0
command: demo-exporter http://akvorado-orchestrator:8080#0
akvorado-exporter1:
<<: *exporter
command: fake-exporter http://akvorado-orchestrator:8080#1
command: demo-exporter http://akvorado-orchestrator:8080#1
akvorado-exporter2:
<<: *exporter
command: fake-exporter http://akvorado-orchestrator:8080#2
command: demo-exporter http://akvorado-orchestrator:8080#2
akvorado-exporter3:
<<: *exporter
command: fake-exporter http://akvorado-orchestrator:8080#3
command: demo-exporter http://akvorado-orchestrator:8080#3

clickhouse:
image: clickhouse/clickhouse-server:22.3
Expand Down
4 changes: 2 additions & 2 deletions orchestrator/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var (
OrchestratorService ServiceType = "orchestrator"
// ConsoleService represents the console service type
ConsoleService ServiceType = "console"
// FakeExporterService represents the fake exporter service type
FakeExporterService ServiceType = "fake-exporter"
// DemoExporterService represents the demo exporter service type
DemoExporterService ServiceType = "demo-exporter"
)

// New creates a new broker component.
Expand Down

0 comments on commit 684a219

Please sign in to comment.