-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cmd/agentctl: initial commit * pkg/client: add client for agent http/1 API * implement agentctl and hook up to CI for builds * fix test fail * address review feedback * agentctl: exit with failure when config-sync fails * Update docs/scraping-service.md Co-authored-by: gotjosh <josue.abreu@gmail.com> * Update pkg/agentctl/sync.go Co-authored-by: gotjosh <josue.abreu@gmail.com> * address review feedback * return error at the end of syncing if anything failed Co-authored-by: gotjosh <josue.abreu@gmail.com>
- Loading branch information
Showing
41 changed files
with
4,608 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
cover.out | ||
|
||
cmd/agent/agent | ||
cmd/agentctl/agentctl | ||
dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM golang:1.14 as build | ||
COPY . /src/agent | ||
WORKDIR /src/agent | ||
ARG RELEASE_BUILD=false | ||
ARG IMAGE_TAG | ||
RUN make clean && make IMAGE_TAG=${IMAGE_TAG} RELEASE_BUILD=${RELEASE_BUILD} BUILD_IN_CONTAINER=false agentctl | ||
|
||
FROM alpine:3.9 | ||
RUN apk add --update --no-cache ca-certificates | ||
COPY --from=build /src/agent/cmd/agentctl/agentctl /bin/agentctl | ||
|
||
ENTRYPOINT ["/bin/agentctl"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Command agentctl provides utilities for interacting with Grafana Cloud Agent | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
// Adds version information | ||
_ "github.com/grafana/agent/pkg/build" | ||
"github.com/prometheus/common/version" | ||
|
||
"github.com/go-kit/kit/log" | ||
"github.com/go-kit/kit/log/level" | ||
"github.com/grafana/agent/pkg/agentctl" | ||
"github.com/grafana/agent/pkg/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func main() { | ||
var cmd = &cobra.Command{ | ||
Use: "agentctl", | ||
Short: "Tools for interacting with the Grafana Cloud Agent", | ||
Version: version.Print("agentctl"), | ||
} | ||
cmd.SetVersionTemplate("{{ .Version }}\n") | ||
|
||
cmd.AddCommand( | ||
configSyncCmd(), | ||
) | ||
|
||
_ = cmd.Execute() | ||
} | ||
|
||
func configSyncCmd() *cobra.Command { | ||
var ( | ||
agentAddr string | ||
) | ||
|
||
cmd := &cobra.Command{ | ||
Use: "config-sync [directory]", | ||
Short: "Sync config files from a directory to an Agent's config management API", | ||
Long: `config-sync loads all files ending with .yml or .yaml from the specified | ||
directory and uploads them the the config management API. The name of the config | ||
uploaded will be the base name of the file (e.g., the name of the file without | ||
its extension). | ||
The directory is used as the source-of-truth for the entire set of configs that | ||
should be present in the API. config-sync will delete all existing configs from the API | ||
that do not match any of the names of the configs that were uploaded from the | ||
source-of-truth directory.`, | ||
Args: cobra.ExactArgs(1), | ||
|
||
Run: func(_ *cobra.Command, args []string) { | ||
directory := args[0] | ||
cli := client.New(agentAddr) | ||
|
||
logger := log.NewLogfmtLogger(log.NewSyncWriter(os.Stdout)) | ||
|
||
err := agentctl.ConfigSync(logger, cli.PrometheusClient, directory) | ||
if err != nil { | ||
level.Error(logger).Log("msg", "failed to sync config", "err", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&agentAddr, "addr", "a", "http://localhost:12345", "address of the agent to connect to") | ||
must(cmd.MarkFlagRequired("addr")) | ||
return cmd | ||
} | ||
|
||
func must(err error) { | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.