Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds UserAgent and CPU Usage optimization #102

Merged
merged 24 commits into from
Mar 25, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

## 1.0.6

- Includes PR#93 - adds authentication with API Key!
- Reduces app CPU utilization to near zero while running
- Adds version to build based on git tag
- Adds user agent with kiosk version
- Switch to git workflow for builds
- Switch to Mage for building instead of make
- Update go modules
- Includes PR#

## 1.0.5

Expand Down
42 changes: 33 additions & 9 deletions Magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@ import (
"fmt"
"log"
"os"
"os/exec"
"runtime"
"strings"

"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
// mg contains helpful utility functions, like Deps
)

// Build namespace
type Build mg.Namespace

// Test namespace
type Test mg.Namespace

// Run namespace
type Run mg.Namespace

var archTargets = map[string]map[string]string{
Expand Down Expand Up @@ -79,6 +86,15 @@ var archTargets = map[string]map[string]string{
},
}

func getVersion() string {
out, err := exec.Command("git", "describe", "--tags").Output()
if err != nil {
return "unknown"
}
version := strings.TrimRight(string(out), "\r\n")
return version
}

// Default target to run when none is specified
// If not set, running mage will list available targets
var Default = Build.Local
Expand All @@ -91,7 +107,13 @@ func buildCommand(command string, arch string) error {
log.Printf("Building %s/%s\n", arch, command)
outDir := fmt.Sprintf("./bin/%s/%s", arch, command)
cmdDir := fmt.Sprintf("./pkg/cmd/%s", command)
if err := sh.RunWith(env, "go", "build", "-o", outDir, cmdDir); err != nil {
if err := sh.RunWith(
env,
"go",
"build",
"-ldflags",
fmt.Sprintf("-X main.Version=%s", getVersion()),
"-o", outDir, cmdDir); err != nil {
return err
}

Expand Down Expand Up @@ -137,23 +159,23 @@ func test() error {
return sh.RunV("go", "tool", "cover", "-html=coverage.out", "-o", "coverage.html")
}

// Formats the source files
// Format Formats the source files
func (Build) Format() error {
if err := sh.RunV("gofmt", "-w", "./pkg"); err != nil {
return err
}
return nil
}

// Minimal build
// Local Minimal build
func (Build) Local(ctx context.Context) {
mg.Deps(
Clean,
kioskCmd,
)
}

// Lint/Format/Test/Build
// CI Lint/Format/Test/Build
func (Build) CI(ctx context.Context) {
mg.Deps(
Build.OSVScanner,
Expand All @@ -165,6 +187,7 @@ func (Build) CI(ctx context.Context) {
)
}

// All build all
func (Build) All(ctx context.Context) {
mg.Deps(
Build.Lint,
Expand All @@ -174,33 +197,34 @@ func (Build) All(ctx context.Context) {
)
}

// Run linter against codebase
// Lint Run linter against codebase
func (Build) Lint() error {
os.Setenv("GO111MODULE", "on")
log.Printf("Linting...")
return sh.RunV("golangci-lint", "--timeout", "5m", "run", "./pkg/...")
}

// OSVScanner Vulnerability scanning
func (Build) OSVScanner() error {
log.Printf("Scanning...")
return sh.RunV("osv-scanner", "--lockfile", "./go.mod")
}

// Run tests in verbose mode
// Verbose Run tests in verbose mode
func (Test) Verbose() {
mg.Deps(
testVerbose,
)
}

// Run tests in normal mode
// Default Run tests in normal mode
func (Test) Default() {
mg.Deps(
test,
)
}

// Removes built files
// Clean Removes built files
func Clean() {
log.Printf("Cleaning all")
os.RemoveAll("./bin/linux_386")
Expand All @@ -214,7 +238,7 @@ func Clean() {
os.RemoveAll("./bin/windows_amd64")
}

// Build and Run
// Local Build and Run
func (Run) Local() error {
mg.Deps(Build.Local)
return sh.RunV(
Expand Down
39 changes: 0 additions & 39 deletions Makefile

This file was deleted.

44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,21 @@ Extract the zip or tar file, and copy the appropriate binary to /usr/bin/grafana
# sudo chmod 755 /usr/bin/grafana-kiosk
```

## Dependencies/Suggestion Packages

This application can run on most operating systems, but for linux some additional
binaries are suggested for full support.

Suggesting Packages:

`unclutter` (for hiding mouse/cursor)
`rng-tools` (for entropy issues)

## Usage

NOTE: Flags with parameters should use an "equals" (-autofit=true, -URL=https://play.grafana.org) when also used with any boolean flags.
NOTE: Flags with parameters should use an "equals"
`-autofit=true`
`-URL=https://play.grafana.org` when used with any boolean flags.

```TEXT
-URL string
Expand All @@ -76,10 +88,10 @@ NOTE: Flags with parameters should use an "equals" (-autofit=true, -URL=https://
idtoken json credentials (default "key.json")
-kiosk-mode string
Kiosk Display Mode [full|tv|disabled]
full = No TOPNAV and No SIDEBAR
tv = No SIDEBAR
disabled = omit option
(default "full")
full = No TOPNAV and No SIDEBAR
tv = No SIDEBAR
disabled = omit option
(default "full")
-login-method string
[anon|local|gcom|goauth|idtoken|apikey|aws] (default "anon")
-lxde
Expand Down Expand Up @@ -142,7 +154,7 @@ They can also be used instead of a configuration file.
KIOSK_WINDOW_SIZE string
Size of Kiosk in pixels (e.g. "1920,1080")
KIOSK_IGNORE_CERTIFICATE_ERRORS bool
ignore SSL/TLS certificate errors (default "false")
Ignore SSL/TLS certificate errors (default "false")
KIOSK_IS_PLAYLIST bool
URL is a playlist (default "false")
KIOSK_LOGIN_METHOD string
Expand All @@ -160,11 +172,11 @@ They can also be used instead of a configuration file.
KIOSK_GOAUTH_FIELD_PASSWORD string
Password html input name value
KIOSK_IDTOKEN_KEYFILE string
JSON Credentials for idtoken
JSON Credentials for idtoken (default "key.json")
KIOSK_IDTOKEN_AUDIENCE string
Audience for idtoken, tpyically your oauth client id
KIOSK_APIKEY_APIKEY string
Grafana API keys
APIKEY Generated in Grafana Server
```

### Hosted Grafana using grafana.com authentication
Expand Down Expand Up @@ -218,8 +230,9 @@ This will take the browser to a playlist on play.grafana.org in fullscreen kiosk
### Grafana Server with Api Key

This will take the browser to the default dashboard on play.grafana.org in fullscreen kiosk mode:

```bash
./bin/grafana-kiosk -URL=https://play.grafana.org -login-method apikey --apikey "xxxxxxxxxxxxxxx" -kiosk-mode=tv
./bin/grafana-kiosk -URL=https://play.grafana.org -login-method apikey --apikey "xxxxxxxxxxxxxxx" -kiosk-mode=tv
```

### Grafana Server with Generic Oauth
Expand Down Expand Up @@ -372,14 +385,20 @@ apt install rng-tools

## Building

A Makefile is provided for building the utility.
A Magefile is provided for building the utility, you can install mage by following the instructions at <https://magefile.org/>
briangann marked this conversation as resolved.
Show resolved Hide resolved

```bash
make
mage -v
```

This will generate executables in "bin" that can be run on a variety of platforms.

For full build and testing options use:

```BASH
mage -l
```

## TODO

- RHEL/CentOS auto-startup
Expand All @@ -398,3 +417,6 @@ This will generate executables in "bin" that can be run on a variety of platform
- [Xan Manning](https://github.com/xanmanning) for the ignore certificate option!
- [David Stäheli](https://github.com/mistadave) for the OAuth implementation!
- [Marcus Ramberg](https://github.com/marcusramberg) for the Google ID Token Auth implementation!
- [Ronan Salmon](https://github.com/ronansalmon) for API token authentication!

Any many others!
24 changes: 12 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ module github.com/grafana/grafana-kiosk
go 1.20

require (
github.com/chromedp/cdproto v0.0.0-20230220211738-2b1ec77315c9
github.com/chromedp/chromedp v0.8.7
github.com/chromedp/cdproto v0.0.0-20230319112347-6603f2c23d36
github.com/chromedp/chromedp v0.9.1
github.com/ilyakaznacheev/cleanenv v1.4.2
github.com/magefile/mage v1.14.0
github.com/smartystreets/goconvey v1.7.2
)

require (
cloud.google.com/go/compute v1.18.0 // indirect
cloud.google.com/go/compute v1.19.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
go.opencensus.io v0.24.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230301171018-9ab4bdc49ad5 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/genproto v0.0.0-20230323212658-478b75c54725 // indirect
google.golang.org/grpc v1.54.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
)

require (
Expand All @@ -38,8 +38,8 @@ require (
github.com/jtolds/gls v4.20.0+incompatible // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/smartystreets/assertions v1.13.0 // indirect
golang.org/x/sys v0.5.0 // indirect
google.golang.org/api v0.111.0
golang.org/x/sys v0.6.0 // indirect
google.golang.org/api v0.114.0
gopkg.in/yaml.v3 v3.0.1 // indirect
olympos.io/encoding/edn v0.0.0-20201019073823-d3554ca0b0a3 // indirect
)
Loading