Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Create initial Skeleton of the shipper and gRPC service #18

Merged
merged 8 commits into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Directories
/.vagrant
/.idea
/.vscode
/build
/*/*.template*.json
**/html_docs
data


# Files
.DS_Store
/beats.iml
*.dev.yml
*.generated.yml
coverage.out
.python-version
beat.db
*.keystore
go_env.properties
mage_output_file.go

fleet.yml

# Editor swap files
*.swp
*.swo
*.swn

# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
*.exe
*.test
*.prof
*.pyc

# Terraform
*.terraform
*.tfstate*

# Files generated with the bump version automations
*.bck


# agent
build/
elastic-agent-shipper


# VSCode
/.vscode
63 changes: 63 additions & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package cmd

import (
// import logp flags
// Elastic-agent currently imports into beats like this, I assume for license reasons?
"flag"
"fmt"
"os"

//import logp flags
"github.com/spf13/cobra"

_ "github.com/elastic/elastic-agent-libs/logp/configure"
"github.com/elastic/elastic-agent-shipper/server"
)

// NewCommand returns a new command structure
func NewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "elastic-agent-shipper [subcommand]",
}
cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("path.config"))
// logging flags
cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("v"))
cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("e"))
cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("d"))
cmd.PersistentFlags().AddGoFlag(flag.CommandLine.Lookup("environment"))

run := runCmd()
cmd.Run = run.Run

return cmd
}

func runCmd() *cobra.Command {
return &cobra.Command{
Use: "run",
Short: "Start the elastic-agent-shipper.",
Run: func(_ *cobra.Command, _ []string) {
if err := server.LoadAndRun(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n\n", err)
os.Exit(1)
}
},
}
}
84 changes: 84 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package config

import (
"flag"
"fmt"
"io/ioutil"
"path/filepath"

"github.com/elastic/elastic-agent-libs/config"
"github.com/elastic/elastic-agent-libs/logp"
)

const (
defaultConfigName = "elastic-agent-shipper.yml"
defaultPort = 50051
)

var (
configPath string
configFilePath string
)

// A lot of the code here is the same as what's in elastic-agent, but it lives in an internal/ library
func init() {
fs := flag.CommandLine
fs.StringVar(&configFilePath, "c", defaultConfigName, "Configuration file, relative to path.config")
fs.StringVar(&configPath, "path.config", configPath, "Config path is the directory Agent looks for its config file")
}

//ShipperConfig defines the options present in the config file
type ShipperConfig struct {
Log logp.Config `config:"logging"`
TLS bool `config:"tls"`
Cert string `config:"cert"` //TLS cert file, if TLS is enabled
Key string `config:"key"` //TLS Keyfile, if specified
Port int `config:"port"` //Port to listen on
}

// ReadConfig returns the populated config from the specified path
func ReadConfig() (ShipperConfig, error) {
path := configFile()

contents, err := ioutil.ReadFile(path)
if err != nil {
return ShipperConfig{}, fmt.Errorf("Error reading input file %s: %v", path, err)
}

raw, err := config.NewConfigWithYAML(contents, "")
// TODO: This logging init will need to be a tad more sophisticated, I assume there's something in the libs already
config := ShipperConfig{Port: defaultPort, Log: logp.DefaultConfig(logp.DefaultEnvironment)}
err = raw.Unpack(&config)
if err != nil {
return config, fmt.Errorf("error unpacking config: %w", err)
}

return config, nil
}

func configFile() string {
if configFilePath == "" || configFilePath == defaultConfigName {
return filepath.Join(configPath, defaultConfigName)
}
if filepath.IsAbs(configFilePath) {
return configFilePath
}
return filepath.Join(configPath, configFilePath)
}
10 changes: 10 additions & 0 deletions elastic-agent-shipper.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# The gRPC port that the shipper will listen on
port: 50052
tls: false
#cert: # path to TLS cert
#key: # path to TLS keyfile

#log level
logging.level: debug
logging.selectors: ["*"]
logging.to_stderr: true
71 changes: 71 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module github.com/elastic/elastic-agent-shipper

go 1.17

require (
github.com/elastic/elastic-agent-libs v0.1.1
github.com/spf13/cobra v1.3.0
google.golang.org/genproto v0.0.0-20220329172620-7be39ac1afc7
google.golang.org/grpc v1.45.0
google.golang.org/protobuf v1.28.0
)

require (
github.com/elastic/elastic-agent v0.0.0-20220330154707-da786a47a0c5
github.com/magefile/mage v1.13.0
)

require (
github.com/akavel/rsrc v0.8.0 // indirect
github.com/armon/go-radix v1.0.0 // indirect
github.com/dlclark/regexp2 v1.1.7-0.20171009020623-7632a260cbaf // indirect
github.com/dop251/goja v0.0.0-20200831102558-9af81ddcf0e1 // indirect
github.com/dop251/goja_nodejs v0.0.0-20171011081505-adff31b136e6 // indirect
github.com/elastic/beats/v7 v7.0.0-alpha2.0.20220303073437-a28c413604b8 // indirect
github.com/elastic/elastic-agent-client/v7 v7.0.0-20210727140539-f0905d9377f6 // indirect
github.com/elastic/go-licenser v0.4.0 // indirect
github.com/elastic/go-sysinfo v1.7.1 // indirect
github.com/elastic/go-ucfg v0.8.4 // indirect
github.com/elastic/go-windows v1.0.1 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/go-sourcemap/sourcemap v2.1.2+incompatible // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jcchavezs/porto v0.1.0 // indirect
github.com/joeshaw/multierror v0.0.0-20140124173710-69b34d4ec901 // indirect
github.com/josephspurrier/goversioninfo v0.0.0-20190209210621-63e6d1acd3dd // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/hashstructure v0.0.0-20170116052023-ab25296c0f51 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/santhosh-tekuri/jsonschema v1.2.4 // indirect
github.com/spf13/pflag v1.0.5 // indirect
go.elastic.co/apm v1.15.0 // indirect
go.elastic.co/ecszap v1.0.0 // indirect
go.elastic.co/fastjson v1.1.0 // indirect
go.uber.org/atomic v1.8.0 // indirect
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20211209124913-491a49abca63 // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.8 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v0.0.0-20201203080718-1454fab16a06 // indirect
)

replace (
github.com/dop251/goja => github.com/andrewkroh/goja v0.0.0-20190128172624-dd2ac4456e20
github.com/dop251/goja_nodejs => github.com/dop251/goja_nodejs v0.0.0-20171011081505-adff31b136e6
)
Loading