-
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.
Merge branch 'main' into am-support-external-labels
- Loading branch information
Showing
55 changed files
with
326 additions
and
107 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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
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
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
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,60 @@ | ||
// package useragent provides a consistent way to get a user agent for outbound http requests from Grafana Agent. | ||
// The default User-Agent is `GrafanaAgent/$VERSION($MODE)` | ||
// Where version is the build version of the agent and MODE is one of "static" or "flow". | ||
package useragent | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"runtime" | ||
"strings" | ||
|
||
"github.com/grafana/agent/pkg/build" | ||
) | ||
|
||
const ( | ||
deployModeEnv = "AGENT_DEPLOY_MODE" | ||
modeEnv = "AGENT_MODE" | ||
) | ||
|
||
// settable by tests | ||
var goos = runtime.GOOS | ||
|
||
func Get() string { | ||
parenthesis := "" | ||
metadata := []string{} | ||
if mode := getRunMode(); mode != "" { | ||
metadata = append(metadata, mode) | ||
} | ||
metadata = append(metadata, goos) | ||
if op := getDeployMode(); op != "" { | ||
metadata = append(metadata, op) | ||
} | ||
if len(metadata) > 0 { | ||
parenthesis = fmt.Sprintf(" (%s)", strings.Join(metadata, "; ")) | ||
} | ||
return fmt.Sprintf("GrafanaAgent/%s%s", build.Version, parenthesis) | ||
} | ||
|
||
// getRunMode attempts to get agent mode, using `unknown` for invalid values. | ||
func getRunMode() string { | ||
key := os.Getenv(modeEnv) | ||
switch key { | ||
case "flow": | ||
return "flow" | ||
case "static", "": | ||
return "static" | ||
default: | ||
return "unknown" | ||
} | ||
} | ||
|
||
func getDeployMode() string { | ||
op := os.Getenv(deployModeEnv) | ||
// only return known modes. Use "binary" as a default catch-all. | ||
switch op { | ||
case "operator", "helm", "docker", "deb", "rpm", "brew": | ||
return op | ||
} | ||
return "binary" | ||
} |
Oops, something went wrong.