Merge pull request #1393 from Maxtonian/30trial

CORE-140 add draft trial version of molecula
This commit is contained in:
Maxton Huff 2021-02-11 16:38:53 -06:00 • committed by GitHub
commit 2e6a8e2030
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 102 additions and 7 deletions

View file

@ -11,7 +11,8 @@ BRANCH_ID := $(BRANCH)-$(GOOS)-$(GOARCH)
BUILD_TIME := $(shell date -u +%FT%T%z)
SHARD_WIDTH = 20
COMMIT := $(shell git describe --exact-match >/dev/null 2>&1 || git rev-parse --short HEAD)
LDFLAGS="-X github.com/pilosa/pilosa/v2.Version=$(VERSION) -X github.com/pilosa/pilosa/v2.BuildTime=$(BUILD_TIME) -X github.com/pilosa/pilosa/v2.Variant=$(VARIANT) -X github.com/pilosa/pilosa/v2.Commit=$(COMMIT) -X github.com/pilosa/pilosa/v2.LatticeCommit=$(LATTICE_COMMIT)"
LDFLAGS="-X github.com/pilosa/pilosa/v2.Version=$(VERSION) -X github.com/pilosa/pilosa/v2.BuildTime=$(BUILD_TIME) -X github.com/pilosa/pilosa/v2.Variant=$(VARIANT) -X github.com/pilosa/pilosa/v2.Commit=$(COMMIT) -X github.com/pilosa/pilosa/v2.LatticeCommit=$(LATTICE_COMMIT) -X github.com/pilosa/pilosa/v2.TrialDeadline=$(TRIAL_DEADLINE)"
TRIAL_STRING = $(if $(TRIAL_DEADLINE),"-trial-$(TRIAL_DEADLINE)","")
GO_VERSION=1.14.10
RELEASE ?= 0
RELEASE_ENABLED = $(subst 0,,$(RELEASE))
@ -100,10 +101,10 @@ build:
# Create a single release build under the build directory
release-build:
$(MAKE) $(if $(DOCKER_BUILD),docker-)build FLAGS="-o build/pilosa-$(VERSION_ID)/pilosa" RELEASE=1
cp NOTICE README.md LICENSE build/pilosa-$(VERSION_ID)
tar -cvz -C build -f build/pilosa-$(VERSION_ID).tar.gz pilosa-$(VERSION_ID)/
@echo Created release build: build/pilosa-$(VERSION_ID).tar.gz
$(MAKE) $(if $(DOCKER_BUILD),docker-)build FLAGS="-o build/pilosa$(TRIAL_STRING)-$(VERSION_ID)/pilosa" RELEASE=1
cp NOTICE README.md LICENSE build/pilosa$(TRIAL_STRING)-$(VERSION_ID)
tar -cvz -C build -f build/pilosa$(TRIAL_STRING)-$(VERSION_ID).tar.gz pilosa$(TRIAL_STRING)-$(VERSION_ID)/
@echo Created release build: build/pilosa$(TRIAL_STRING)-$(VERSION_ID).tar.gz
# Error out if there are untracked changes in Git
check-clean:

1
go.mod
View file

@ -5,6 +5,7 @@ replace github.com/hashicorp/memberlist => github.com/pilosa/memberlist v0.1.4-0
require (
github.com/CAFxX/gcnotifier v0.0.0-20190112062741-224a280d589d
github.com/DataDog/datadog-go v0.0.0-20180822151419-281ae9f2d895
github.com/beevik/ntp v0.3.0
github.com/benbjohnson/immutable v0.3.0
github.com/cespare/xxhash v1.1.0
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd // indirect

2
go.sum
View file

@ -31,6 +31,8 @@ github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hC
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da h1:8GUt8eRujhVEGZFFEjBj46YV4rDjvGrNxb0KMWYkL2I=
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/beevik/ntp v0.3.0 h1:xzVrPrE4ziasFXgBVBZJDP0Wg/KpMwk2KHJ4Ba8GrDw=
github.com/beevik/ntp v0.3.0/go.mod h1:hIHWr+l3+/clUnF44zdK+CWW7fO8dR5cIylAQ76NRpg=
github.com/benbjohnson/immutable v0.3.0 h1:TVRhuZx2wG9SZ0LRdqlbs9S5BZ6Y24hJEHTCgWHZEIw=
github.com/benbjohnson/immutable v0.3.0/go.mod h1:uc6OHo6PN2++n98KHLxW8ef4W42ylHiQSENghE1ezxI=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=

@ -1 +1 @@
Subproject commit fa773628a276e2590785a87fbc236c7e88ea6284
Subproject commit 28c2313ecfcd7e083d42d4e409483e968b4c421b

View file

@ -285,6 +285,8 @@ func (m *Command) SetupServer() error {
m.logger.Printf("%s", pilosa.VersionInfo())
handleTrialDeadline(m.logger)
// If the pilosa command line uses -tx to override the
// PILOSA_TXSRC env variable, then we must also correct
// the environment, so that pilosa/txfactory.go can determine the

86
server/trial.go Normal file
View file

@ -0,0 +1,86 @@
// Copyright 2021 Pilosa Corp.
//
// Licensed 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 server contains the `pilosa server` subcommand which runs Pilosa
// itself. The purpose of this package is to define an easily tested Command
// object which handles interpreting configuration and setting up all the
// objects that Pilosa needs.
package server
import (
"os"
"time"
"github.com/beevik/ntp"
"github.com/pilosa/pilosa/v2"
)
// handleTrialDeadline checks to see if this is a trial version of Molecula that expires at some point.
// If it is, we contact an NTP server to get the current time and compare that to the trial deadline.
// We launch two goroutines, one which reminds via a log message how much time is left in the trial,
// and one which causes the process to exit once the trial is over.
func handleTrialDeadline(logger loggerLogger) {
if pilosa.TrialDeadline != "" {
startTime, err := ntpServerTime(4, logger)
if err != nil {
logger.Printf("reading ntp server time %v", err)
os.Exit(1)
}
endTime, err := time.Parse("2006-01-02", pilosa.TrialDeadline)
if err != nil {
logger.Printf("parsing trial deadline: %v", err)
os.Exit(1)
}
maxDuration := endTime.Sub(startTime)
go expireAfter(maxDuration, logger)
go dailyCheck(maxDuration, logger)
}
}
const trialCheckInterval = 24 * time.Hour
// dailyCheck runs in the background while a trial version of Molecula is being run, displaying daily reminders of the remaining days
func dailyCheck(maxDuration time.Duration, logger loggerLogger) {
startTime := time.Now() // we get a new start time here to ensure that it has a monotonic clock
remaining := maxDuration - time.Since(startTime)
logger.Printf("Current time remaining in trial: %d days %v", remaining/(time.Hour*24), remaining%(time.Hour*24))
ticker := time.NewTicker(trialCheckInterval)
for range ticker.C {
remaining := maxDuration - time.Since(startTime)
logger.Printf("Current time remaining in trial: %d days %v", remaining/(time.Hour*24), remaining%(time.Hour*24))
}
}
const ntpURL = "0.beevik-ntp.pool.ntp.org"
const ntpRetryDelay = 100 * time.Millisecond
// ntpServerTime attempts to reach ntp servers with delays between each attempt, returning the time value of the first connected server
func ntpServerTime(retries int, logger loggerLogger) (time.Time, error) {
t, err := ntp.Time(ntpURL)
if err != nil && retries <= 0 {
return t, err
}
if err != nil {
time.Sleep(ntpRetryDelay)
return ntpServerTime(retries-1, logger)
}
return t, nil
}
func expireAfter(maxDuration time.Duration, logger loggerLogger) {
time.Sleep(maxDuration)
logger.Printf("Trial edition of Molecula has expired, exiting now!")
os.Exit(1)
}

View file

@ -25,6 +25,7 @@ var Variant string
var BuildTime string
var LatticeCommit string
var GoVersion string = runtime.Version()
var TrialDeadline string
func VersionInfo() string {
var prefix string
@ -53,7 +54,9 @@ func VersionInfo() string {
suffix += " (" + buildTime + ")"
}
suffix += " " + GoVersion
if TrialDeadline != "" {
suffix += " limited time trial ends on: " + TrialDeadline
}
return prefix + "Pilosa" + suffix
}