Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #48 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 4.3.0
  • Loading branch information
andyone authored Dec 21, 2020
2 parents 7f487fc + 9258cfe commit 2a3f85f
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 13 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
<a href="https://codebeat.co/projects/github-com-essentialkaos-pkgre-master"><img alt="codebeat badge" src="https://codebeat.co/badges/f29ed07b-af32-4d45-a342-59b20e3bfcf9" /></a>
<a href="#license"><img src="https://gh.kaos.st/apache2.svg"></a>
</p>
<p align="center">
<a href="#"><img src="https://healthchecks.io/badge/6f454deb-5215-40aa-933f-f91a8e579a07/sKjRtflJ-2/server.svg" /></a>
<a href="#"><img src="https://healthchecks.io/badge/6f454deb-5215-40aa-933f-f91a8e579a07/2FbciL3K-2/morpher.svg" /></a>
</p>

<p align="center"><a href="#routing-examples">Routing examples</a> • <a href="#contributing">Contributing</a> • <a href="#license">License</a></p>

Expand Down
5 changes: 5 additions & 0 deletions common/morpher.knf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
# URL for redirect non-system request
redirect: https://pkg.re

[healthcheck]

# URL of healthcheck service
url:

[log]

# Minimal log level (debug/info/warn/error/crit)
Expand Down
5 changes: 4 additions & 1 deletion common/pkgre.spec
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

Summary: pkg.re morpher server
Name: pkgre
Version: 4.2.1
Version: 4.3.0
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
Expand Down Expand Up @@ -153,6 +153,9 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Mon Dec 21 2020 Anton Novojilov <[email protected]> - 4.3.0-0
- Sending healthcheck requests

* Fri Dec 18 2020 Anton Novojilov <[email protected]> - 4.2.1-0
- Improved URL generation for pkg.go.dev redirect
- Dependencies updated to the latest versions
Expand Down
59 changes: 59 additions & 0 deletions server/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package healthcheck

// ////////////////////////////////////////////////////////////////////////////////// //
// //
// Copyright (c) 2020 ESSENTIAL KAOS //
// Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0> //
// //
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"time"

"pkg.re/essentialkaos/ek.v12/log"

"github.com/valyala/fasthttp"
)

// ////////////////////////////////////////////////////////////////////////////////// //

type Checker struct {
client *fasthttp.Client
url string
}

// ////////////////////////////////////////////////////////////////////////////////// //

// Start starts healthcheck pinger
func Start(url string, period time.Duration) {
checker := &Checker{
url: url,
client: &fasthttp.Client{
Name: "PKGRE Morpher/4",
MaxIdleConnDuration: 5 * time.Second,
ReadTimeout: 5 * time.Second,
WriteTimeout: 3 * time.Second,
MaxConnsPerHost: 10,
},
}

go checker.Run(period)
}

// ////////////////////////////////////////////////////////////////////////////////// //

// Run starts loop for sending pings
func (c *Checker) Run(period time.Duration) {
for range time.NewTicker(period).C {
req := fasthttp.AcquireRequest()

req.SetRequestURI(c.url)
req.Header.SetMethod("HEAD")

err := c.client.Do(req, nil)

if err != nil {
log.Error("Can't send healthcheck request: %v", err)
}
}
}
31 changes: 19 additions & 12 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"runtime"
"strings"
"time"

"pkg.re/essentialkaos/ek.v12/fmtc"
"pkg.re/essentialkaos/ek.v12/knf"
Expand All @@ -23,6 +24,7 @@ import (
knfv "pkg.re/essentialkaos/ek.v12/knf/validators"
knff "pkg.re/essentialkaos/ek.v12/knf/validators/fs"

"github.com/essentialkaos/pkgre/server/healthcheck"
"github.com/essentialkaos/pkgre/server/morpher"
)

Expand All @@ -31,7 +33,7 @@ import (
// Application info
const (
APP = "PkgRE Morpher Server"
VER = "4.2.1"
VER = "4.3.0"
DESC = "HTTP Server for morphing go get requests"
)

Expand All @@ -53,14 +55,15 @@ const (

// Configuration file properties names
const (
MAIN_PROCS = "main:procs"
HTTP_IP = "http:ip"
HTTP_PORT = "http:port"
HTTP_REDIRECT = "http:redirect"
LOG_LEVEL = "log:level"
LOG_DIR = "log:dir"
LOG_FILE = "log:file"
LOG_PERMS = "log:perms"
MAIN_PROCS = "main:procs"
HTTP_IP = "http:ip"
HTTP_PORT = "http:port"
HTTP_REDIRECT = "http:redirect"
HEALTHCHECK_URL = "healthcheck:url"
LOG_LEVEL = "log:level"
LOG_DIR = "log:dir"
LOG_FILE = "log:file"
LOG_PERMS = "log:perms"
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -128,6 +131,10 @@ func prepare() {

validateConfig()
setupLogger()

runtime.GOMAXPROCS(knf.GetI(MAIN_PROCS))

log.Debug("GOMAXPROCS set to %d", knf.GetI(MAIN_PROCS))
}

// validateConfig validate config values
Expand Down Expand Up @@ -169,9 +176,9 @@ func setupLogger() {

// start start web server
func start() {
runtime.GOMAXPROCS(knf.GetI(MAIN_PROCS))

log.Debug("GOMAXPROCS set to %d", knf.GetI(MAIN_PROCS))
if knf.HasProp(HEALTHCHECK_URL) {
healthcheck.Start(knf.GetS(HEALTHCHECK_URL), time.Minute)
}

err := morpher.Start(VER)

Expand Down

0 comments on commit 2a3f85f

Please sign in to comment.