Skip to content

Commit

Permalink
Merge branch 'master' of github.com:insolar/insolar into NOISSUE-fix-…
Browse files Browse the repository at this point in the history
…pulsar-distribution

# Conflicts:
#	scripts/generate_insolar_configs.go
#	scripts/insolard/launchnet.sh
  • Loading branch information
krestkrest committed Jan 22, 2019
2 parents d113660 + 96fc0c2 commit 232db3d
Show file tree
Hide file tree
Showing 66 changed files with 992 additions and 408 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ script:
# check if git repo unchanged in CI before build stage (try to catch forgotten generated files)
- make test_git_no_changes
- make build
- make functest
- make test_with_coverage
- make functest

after_success:
- "bash <(curl -s https://codecov.io/bash)"
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ INSGOCC = $(BIN_DIR)/insgocc
PULSARD = pulsard
INSGORUND = insgorund
BENCHMARK = benchmark
PULSEWATCHER = pulsewatcher
EXPORTER = exporter
APIREQUESTER = apirequester
HEALTHCHECK = healthcheck
Expand Down Expand Up @@ -63,7 +64,7 @@ ensure:

build:
mkdir -p $(BIN_DIR)
make $(INSOLARD) $(INSOLAR) $(INSGOCC) $(PULSARD) $(INSGORUND) $(HEALTHCHECK) $(BENCHMARK)
make $(INSOLARD) $(INSOLAR) $(INSGOCC) $(PULSARD) $(INSGORUND) $(HEALTHCHECK) $(BENCHMARK) $(PULSEWATCHER)

$(INSOLARD):
go build -o $(BIN_DIR)/$(INSOLARD) -ldflags "${LDFLAGS}" cmd/insolard/*.go
Expand All @@ -83,6 +84,9 @@ $(INSGORUND):
$(BENCHMARK):
go build -o $(BIN_DIR)/$(BENCHMARK) -ldflags "${LDFLAGS}" cmd/benchmark/*.go

$(PULSEWATCHER):
go build -o $(BIN_DIR)/$(PULSEWATCHER) -ldflags "${LDFLAGS}" cmd/pulsewatcher/*.go

$(APIREQUESTER):
go build -o $(BIN_DIR)/$(APIREQUESTER) -ldflags "${LDFLAGS}" cmd/apirequester/*.go

Expand Down
38 changes: 19 additions & 19 deletions api/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ import (
"net/http"
"time"

"go.opencensus.io/trace"

"github.com/insolar/insolar/instrumentation/instracer"

"github.com/insolar/insolar/api/seedmanager"
"github.com/insolar/insolar/application/extractor"
"github.com/insolar/insolar/core"
"github.com/insolar/insolar/core/reply"
"github.com/insolar/insolar/core/utils"
"github.com/insolar/insolar/instrumentation/inslogger"
"github.com/insolar/insolar/instrumentation/instracer"
"github.com/insolar/insolar/metrics"
"github.com/insolar/insolar/platformpolicy"

"github.com/insolar/insolar/api/seedmanager"
"github.com/insolar/insolar/core"
"github.com/insolar/insolar/instrumentation/inslogger"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -115,30 +113,26 @@ func (ar *Runner) checkSeed(paramsSeed []byte) error {
}

func (ar *Runner) makeCall(ctx context.Context, params Request) (interface{}, error) {
ctx, span := instracer.StartSpan(ctx, "SendRequest "+params.Method)
defer span.End()

reference, err := core.NewRefFromBase58(params.Reference)
if err != nil {
return nil, errors.Wrap(err, "[ makeCall ] failed to parse params.Reference")
}

ctx, reqspan := instracer.StartSpan(ctx, "makeCall SendRequest")
reqspan.AddAttributes(
trace.StringAttribute("method", params.Method),
)
res, err := ar.ContractRequester.SendRequest(
ctx,
reference,
"Call",
[]interface{}{*ar.CertificateManager.GetCertificate().GetRootDomainReference(), params.Method, params.Params, params.Seed, params.Signature},
)
reqspan.End()

if err != nil {
return nil, errors.Wrap(err, "[ makeCall ] Can't send request")
}

_, callspan := instracer.StartSpan(ctx, "makeCall CallResponse")
result, contractErr, err := extractor.CallResponse(res.(*reply.CallMethod).Result)
callspan.End()

if err != nil {
return nil, errors.Wrap(err, "[ makeCall ] Can't extract response")
Expand All @@ -161,12 +155,21 @@ func (ar *Runner) callHandler() func(http.ResponseWriter, *http.Request) {
traceID := utils.RandTraceID()
ctx, insLog := inslogger.WithTraceField(context.Background(), traceID)

ctx, rpcspan := instracer.StartSpan(ctx, "NetRPC Request Processing")
defer rpcspan.End()
ctx, span := instracer.StartSpan(ctx, "callHandler")
defer span.End()

params := Request{}
resp := answer{}

startTime := time.Now()
defer func() {
success := "success"
if resp.Error != "" {
success = "fail"
}
metrics.APIContractExecutionTime.WithLabelValues(params.Method, success).Observe(time.Since(startTime).Seconds())
}()

resp.TraceID = traceID

insLog.Infof("[ callHandler ] Incoming request: %s", req.RequestURI)
Expand Down Expand Up @@ -201,9 +204,6 @@ func (ar *Runner) callHandler() func(http.ResponseWriter, *http.Request) {
return
}

ctx, callspan := instracer.StartSpan(ctx, "callHandler makeCall")
defer callspan.End()

var result interface{}
ch := make(chan interface{}, 1)
go func() {
Expand Down
1 change: 0 additions & 1 deletion api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ func (ar *Runner) IsAPIRunner() bool {
// Start runs api server
func (ar *Runner) Start(ctx context.Context) error {
ar.SeedManager = seedmanager.New()

http.HandleFunc(ar.cfg.Call, ar.callHandler())
http.Handle(ar.cfg.RPC, ar.rpcServer)
inslog := inslogger.FromContext(ctx)
Expand Down
6 changes: 3 additions & 3 deletions cmd/insolard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func main() {
bootstrapComponents.KeyProcessor,
)

fmt.Print("Starts with configuration:\n", configuration.ToString(cfgHolder.Configuration))
fmt.Println("Starts with configuration:\n", configuration.ToString(cfgHolder.Configuration))

jaegerflush := func() {}
if params.traceEnabled {
Expand All @@ -123,7 +123,8 @@ func main() {
certManager.GetCertificate().GetRole().String(),
certManager.GetCertificate().GetNodeRef().String(),
jconf.AgentEndpoint,
jconf.CollectorEndpoint)
jconf.CollectorEndpoint,
jconf.ProbabilityRate)
ctx = instracer.SetBaggage(ctx, instracer.Entry{Key: "traceid", Value: traceID})
}
defer jaegerflush()
Expand Down Expand Up @@ -162,7 +163,6 @@ func main() {

inslog.Warn("GRACEFULL STOP APP")
err = cm.Stop(ctx)
jaegerflush()
checkError(ctx, err, "failed to graceful stop components")
close(waitChannel)
}()
Expand Down
29 changes: 25 additions & 4 deletions cmd/pulsard/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/insolar/insolar/core/utils"
"github.com/insolar/insolar/cryptography"
"github.com/insolar/insolar/instrumentation/inslogger"
"github.com/insolar/insolar/instrumentation/instracer"
"github.com/insolar/insolar/keystore"
"github.com/insolar/insolar/log"
"github.com/insolar/insolar/network/pulsenetwork"
Expand All @@ -39,20 +40,22 @@ import (
"github.com/insolar/insolar/platformpolicy"
"github.com/insolar/insolar/pulsar"
"github.com/insolar/insolar/pulsar/entropygenerator"
"github.com/insolar/insolar/pulsar/storage"
pulsarstorage "github.com/insolar/insolar/pulsar/storage"
"github.com/insolar/insolar/version"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
)

type inputParams struct {
configPath string
configPath string
traceEnabled bool
}

func parseInputParams() inputParams {
var rootCmd = &cobra.Command{Use: "insolard"}
var result inputParams
rootCmd.Flags().StringVarP(&result.configPath, "config", "c", "", "path to config file")
rootCmd.Flags().BoolVarP(&result.traceEnabled, "trace", "t", false, "enable tracing")
err := rootCmd.Execute()
if err != nil {
fmt.Println("Wrong input params:", err.Error())
Expand Down Expand Up @@ -86,6 +89,21 @@ func main() {
ctx, inslog := initLogger(context.Background(), cfgHolder.Configuration.Log, traceID)
log.SetGlobalLogger(inslog)

jaegerflush := func() {}
if params.traceEnabled {
jconf := cfgHolder.Configuration.Tracer.Jaeger
log.Infof("Tracing enabled. Agent endpoint: '%s', collector endpoint: '%s'", jconf.AgentEndpoint, jconf.CollectorEndpoint)
jaegerflush = instracer.ShouldRegisterJaeger(
ctx,
"pulsar",
core.RecordRef{}.String(),
jconf.AgentEndpoint,
jconf.CollectorEndpoint,
jconf.ProbabilityRate)
ctx = instracer.SetBaggage(ctx, instracer.Entry{Key: "traceid", Value: traceID})
}
defer jaegerflush()

cm, server, storage := initPulsar(ctx, cfgHolder.Configuration)
server.ID = traceID

Expand All @@ -100,7 +118,10 @@ func main() {
inslog.Error(err)
}
server.StopServer(ctx)
cm.Stop(ctx)
err = cm.Stop(ctx)
if err != nil {
inslog.Error(err)
}
}()

var gracefulStop = make(chan os.Signal, 1)
Expand All @@ -111,7 +132,7 @@ func main() {
}

func initPulsar(ctx context.Context, cfg configuration.Configuration) (*component.Manager, *pulsar.Pulsar, pulsarstorage.PulsarStorage) {
fmt.Print("Starts with configuration:\n", configuration.ToString(cfg))
fmt.Println("Starts with configuration:\n", configuration.ToString(cfg))
fmt.Println("Version: ", version.GetFullVersion())

keyStore, err := keystore.NewKeyStore(cfg.KeysPath)
Expand Down
21 changes: 21 additions & 0 deletions cmd/pulsewatcher/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Pulse Watcher
===============

Usage
----------
#### Build

make pulsewatcher

#### Start blockchain

./scripts/insolard/launchnet.sh -g

#### Start pulsewatcher

./bin/pulsewatcher -c scripts/insolard/configs/generated_configs/utils/pulsewatcher.yaml

### Options

-c config file
Path to configuration file.
57 changes: 57 additions & 0 deletions cmd/pulsewatcher/config/pulsewatcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2019 Insolar
*
* 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 pulsewatcher

import (
"io/ioutil"
"os"
"path/filepath"
"time"

"gopkg.in/yaml.v2"
)

type Config struct {
Nodes []string
Interval time.Duration
Timeout time.Duration
}

func WriteConfig(dir string, file string, conf Config) error {
err := os.MkdirAll(dir, 0775)
if err != nil {
return err
}
data, err := yaml.Marshal(conf)
if err != nil {
return err
}
return ioutil.WriteFile(filepath.Join(dir, file), data, 0644)
}

func ReadConfig(file string) (*Config, error) {
var conf Config
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
err = yaml.Unmarshal(data, &conf)
if err != nil {
return nil, err
}
return &conf, nil
}
Loading

0 comments on commit 232db3d

Please sign in to comment.