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

[config] [dsl] fixes #32 - RXT scraper definition language #38

Open
wants to merge 87 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
c98a68e
[core] refs #32 - Core interfaces for datasets, and sources for scrap…
olemis Nov 20, 2018
9d9dc52
[config] [dsl] refs #32 - RextScrapingRule => RextMetricDef. RextMetr…
olemis Nov 20, 2018
1d18f14
Merge remote-tracking branch 'simelo/develop' into olemis_t32_rxt_dsl
olemis Nov 20, 2018
a0ed99e
[config] [dsl] refs #32 - Lexer for RXT language
olemis Nov 21, 2018
57c39c1
[config] [dsl] refs #32 - Lexer tokens BLK, EOL, EOB, BIE, PCT
olemis Nov 22, 2018
48d6c02
[config] [dsl] refs #32 - Remove whitespace while emitting punctuatio…
olemis Nov 22, 2018
8dd72bb
[config] [dsl] refs #32 - Correct lexer golden file for sample RXT spec.
olemis Nov 23, 2018
1164bbb
[config] [dsl] refs #32 - Fix matching of RXT indentation tokens.
olemis Nov 23, 2018
d9f1df4
[config] [dsl] refs #32 Boundary conditions related to EOB token
olemis Nov 23, 2018
dc6283e
[config] [dsl] refs #32 - RXT AST data types
olemis Nov 24, 2018
3bc397c
[rxt] refs #32 - Move src/config/rxt => src/rxt
olemis Nov 24, 2018
82bf2bb
[cmd] [rxt] refs #32 - Lexer command based on (reusable) LexTheRxt fu…
olemis Nov 24, 2018
9b04cfb
[core] refs #32 - Core interfaces with methods needed for parsing REX…
olemis Nov 26, 2018
0a5628e
[core] refs #32 - Some methods in core interfaces may return error
olemis Nov 27, 2018
f2feb01
[rxt] refs #32 - CTX token. TokenHandler interface
olemis Nov 28, 2018
d60f9bd
[rxt] refs #32 - make test-grammar outputs tokens to file and diff -u…
olemis Nov 28, 2018
ad2ace0
ref #32 Merge branch 'denisacostaq_t54_automatically_generated_labels…
Dec 10, 2018
ed7f01b
ref #32 skip autogenerated file lexer.nn.go from linter
Dec 10, 2018
bfb0a19
ref #32 fix some build errors
Dec 10, 2018
003121a
[rxt] refs #32 - TokenHandler lexer interface
olemis Dec 10, 2018
a7a7112
ref #32 Merge remote-tracking branch 'olemis/olemis_t32_rxt_dsl' into…
Dec 10, 2018
1f4a05b
[config] [rxt] [util] refs #32 - Parser grammar ... WiP
olemis Dec 11, 2018
08dbd9f
ref #32 Merge branch 'denisacostaq_t54_automatically_generated_labels…
Dec 11, 2018
c034e0a
ref #32 Merge remote-tracking branch 'olemis/olemis_t32_rxt_dsl' into…
Dec 11, 2018
fd62034
ref #32 Merge branch 'denisacostaq_t54_automatically_generated_labels…
Dec 11, 2018
4636b6f
ref #32 implemment core.RextMetricDef and unit tests
Dec 14, 2018
ac3a4ac
ref #32 implements core.RextAuth and unit tests
Dec 14, 2018
7ae08d4
ref #32 implements core.RextMetricsExtractor and unit tests
Dec 14, 2018
ae33237
ref #32 implements core.RextDataSource and unit tests
Dec 14, 2018
f3827aa
ref #32 implements core.RextServiceScraper and unit tests
Dec 14, 2018
0686090
ref #32 implements core.RextEnv and unit tests
Dec 14, 2018
a3d9d43
ref #32 implements core.RextKeyValStore (copied from config module, o…
Dec 14, 2018
d307ef4
ref #32 run memconfig unit tests from makefile
Dec 14, 2018
4e17cf4
ref #32 core interfaces redefinitions for config only
Dec 16, 2018
f2c8bd1
ref #32 config interfaces redefinition and comments
Dec 18, 2018
96b518a
ref #32 config core interface redefinition, remove DataPath
Dec 18, 2018
8328dea
ref #32 renamed: src/core/sources.go -> src/core/config.go
Dec 18, 2018
86b9532
ref #32 define a toml structure for the configuration
Dec 18, 2018
b20c062
ref #32 tracking some toml config examples
Dec 19, 2018
54fbe10
ref #32 a toml config reader
Dec 19, 2018
e3108b5
ref #32 reading toml config from cmd/rextporter
Dec 19, 2018
511c63b
ref #32 auth implementation use an KeyValueStore implementation as pa…
Dec 19, 2018
7dc0220
ref #32 add test for set type on auth
Dec 19, 2018
47612f6
ref #32 metric def:
Dec 19, 2018
eb56b3d
ref #32 change service core.RextKeyValueStore implace implementation …
Dec 19, 2018
d1f4d30
ref #32 add support for general objects(interface{})
Dec 19, 2018
1cf1df8
ref #32 change root config to impplement core.RextRoot interface
Dec 19, 2018
941524f
ref #32 remove metrics extractor and scrapper from memconfig
Dec 19, 2018
0dfd2c9
ref #32 add decoder implementation of core.RextDecoderDef interface
Dec 19, 2018
039e016
ref #32 add label implementation of core.RextLabelDef interface
Dec 19, 2018
c31af82
ref #32 add label implementation of core.RextNodeSolver interface
Dec 19, 2018
e9e5a4f
ref #32 add a resource implementation of core.RextResourceDef interface
Dec 19, 2018
2fa62eb
ref #32 replace a specific config usage in client by the core interface
Dec 19, 2018
30707ee
ref #32 replace a specific config usage in exporter by the core inter…
Dec 19, 2018
e206309
ref #32 replace a specific config usage in scrapper by the core inter…
Dec 19, 2018
2f32bc8
ref #32 find config folder
Dec 19, 2018
d65c237
ref #32 make config structure copyable(deep copy, clone)
Dec 21, 2018
f72881c
ref #32 validations and tests for RextAuth
Dec 21, 2018
7b86c03
ref #32 validations and tests for RextResourceDef
Dec 21, 2018
c6a861c
ref #32 igore mocks folder
Dec 21, 2018
18b5d5f
ref #32 validations and tests for RextService
Dec 21, 2018
b892977
ref #32 refactor source to resource
Dec 21, 2018
f03ad3d
ref #32 validations and tests for RextNodeSolver
Dec 21, 2018
0d82784
ref #32 refactor resource in RextService
Dec 21, 2018
262f030
ref #32 validations and tests for RextLabel
Dec 21, 2018
8af8886
ref #32 validations and tests for RextDecoder
Dec 21, 2018
8676163
ref #32 validations and tests for RextMetric
Dec 21, 2018
281f213
ref #32 validations and tests for RextRoot
Dec 22, 2018
2e37771
ref #32 fixes, refactor, source code comments
Dec 22, 2018
bc0f5fe
ref #32 install github.com/vektra/mockery from travis script
Dec 22, 2018
75b90dc
ref #32 add rule to makefile, generate mocks.
Dec 22, 2018
3b7d6cf
ref #32 delete file from config
Dec 22, 2018
c404d0b
ref #32 crate a core.RextRoot config from a toml config and fix some …
Dec 22, 2018
7960875
ref #32 fix bug on metrics validations
Dec 23, 2018
3cc99ef
ref #32 refactor and little fixes
Dec 24, 2018
dd09434
ref #32 a complete rework over integration tests
Dec 24, 2018
c17eb19
ref #32 track toml config reader
Dec 24, 2018
6c59e31
ref #32 url validation
Dec 24, 2018
719f67d
ref #32 fix bug on url validation, ignored result
Dec 24, 2018
243ae18
ref #32 refactor based on linter and delete key_val_4test
Dec 24, 2018
13326e5
ref #32 update vendor
Dec 24, 2018
c712c06
ref #32 skip autogenerated mocks folder
Dec 24, 2018
6e4723b
ref #32 keep the mocks folders even without content
Dec 24, 2018
9d5d595
ref #32 Merge remote-tracking branch 'upstream/develop' into stdevAlD…
Dec 24, 2018
7ab550e
Merge remote-tracking branch 'simelo/develop' into olemis_t32_rxt_dsl
olemis Dec 25, 2018
d0481a1
ref #32 Merge remote-tracking branch 'olemis/olemis_t32_rxt_dsl' into…
Dec 25, 2018
83db570
Merge pull request #1 from denisacostaq/stdevAlDen_t32_rxt_dsl
olemis Dec 29, 2018
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,13 @@

# screen logs
screenlog.*

# Temp files
*.swo
*.swp
*.orig


**/mocks/*
!**/mocks/.gitkeep

3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ run:
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- src/core/mocks

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:

- src/rxt/grammar/lexer.nn.go

# output configuration options
output:
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ install:
- if [[ ! -d $GOPATH/src/github.com/simelo/rextporter ]]; then mkdir -p $GOPATH/src/github.com/simelo; ln -s $TRAVIS_BUILD_DIR $GOPATH/src/github.com/simelo/rextporter; fi
- cd $GOPATH/src/github.com/simelo/rextporter
- go get -t ./...
- go get github.com/vektra/mockery/.../
- make install-linters


Expand Down
4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,3 @@
[[constraint]]
branch = "master"
name = "github.com/cznic/goyacc"

[[constraint]]
branch = "master"
name = "github.com/cznic/goyacc"
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
.DEFAULT_GOAL := help
.PHONY: test install-linters test-386 test-amd64 lint

build-grammar: ## Generate source code for REXT grammar
nex -s src/rxt/grammar/lexer.nex

test: ## Run test with GOARCH=Default
mocks: ## Create all mock files for unit tests
echo "Generating mock files"
cd src/core/ ; mockery -all ; cd ../../

test-grammar: build-grammar ## Test cases for REXT lexer and parser
go run cmd/rxtc/lexer.go < src/rxt/testdata/skyexample.rxt 2> src/rxt/testdata/skyexample.golden.orig
diff -u src/rxt/testdata/skyexample.golden src/rxt/testdata/skyexample.golden.orig

test: mocks ## Run test with GOARCH=Default
go test -count=1 github.com/simelo/rextporter/src/config
go test -count=1 github.com/simelo/rextporter/src/scrapper
go test -count=1 github.com/simelo/rextporter/src/memconfig
if ! screen -list | grep -q "fakeSkycoinForIntegrationTest"; then echo "creating screen fakeSkycoinForIntegrationTest"; screen -L -dm -S fakeSkycoinForIntegrationTest go run test/integration/fake_skycoin_node.go; else echo "fakeSkycoinForIntegrationTest screen already exist. quiting it to create a new one"; screen -S fakeSkycoinForIntegrationTest -X quit; screen -dm -S fakeSkycoinForIntegrationTest go run test/integration/fake_skycoin_node.go; fi
sleep 3
go test -count=1 -cpu=1 -parallel=1 github.com/simelo/rextporter/test/integration -args -test.v
Expand All @@ -13,9 +25,10 @@ test: ## Run test with GOARCH=Default
cat screenlog.0


test-386: ## Run tests with GOARCH=386
test-386: mocks ## Run tests with GOARCH=386
GOARCH=386 go test -count=1 github.com/simelo/rextporter/src/config
GOARCH=386 go test -count=1 github.com/simelo/rextporter/src/scrapper
GOARCH=386 go test -count=1 github.com/simelo/rextporter/src/memconfig
if ! screen -list | grep -q "fakeSkycoinForIntegrationTest"; then echo "creating screen fakeSkycoinForIntegrationTest"; screen -L -dm -S fakeSkycoinForIntegrationTest go run test/integration/fake_skycoin_node.go; else echo "fakeSkycoinForIntegrationTest screen already exist. quiting it to create a new one"; screen -S fakeSkycoinForIntegrationTest -X quit; screen -dm -S fakeSkycoinForIntegrationTest go run test/integration/fake_skycoin_node.go; fi
sleep 3
GOARCH=386 go test -cpu=1 -parallel=1 -count=1 github.com/simelo/rextporter/test/integration -args -test.v
Expand All @@ -24,9 +37,10 @@ test-386: ## Run tests with GOARCH=386
screen -S fakeSkycoinForIntegrationTest -X quit
cat screenlog.0

test-amd64: ## Run tests with GOARCH=amd64
test-amd64: mocks ## Run tests with GOARCH=amd64
GOARCH=amd64 go test -count=1 github.com/simelo/rextporter/src/config
GOARCH=amd64 go test -count=1 github.com/simelo/rextporter/src/scrapper
GOARCH=amd64 go test -count=1 github.com/simelo/rextporter/src/memconfig
if ! screen -list | grep -q "fakeSkycoinForIntegrationTest"; then echo "creating screen fakeSkycoinForIntegrationTest"; screen -L -dm -S fakeSkycoinForIntegrationTest go run test/integration/fake_skycoin_node.go; else echo "fakeSkycoinForIntegrationTest screen already exist. quiting it to create a new one"; screen -S fakeSkycoinForIntegrationTest -X quit; screen -dm -S fakeSkycoinForIntegrationTest go run test/integration/fake_skycoin_node.go; fi
sleep 3
GOARCH=amd64 go test -cpu=1 -parallel=1 -count=1 github.com/simelo/rextporter/test/integration -args -test.v
Expand Down
23 changes: 19 additions & 4 deletions cmd/rextporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,35 @@ package main

import (
"flag"
"os"

"github.com/simelo/rextporter/src/config"
"github.com/simelo/rextporter/src/core"
"github.com/simelo/rextporter/src/exporter"
"github.com/simelo/rextporter/src/toml2config"
"github.com/simelo/rextporter/src/tomlconfig"
log "github.com/sirupsen/logrus"
)

func main() {
mainConfigFile := flag.String("config", "", "Metrics main config file path.")
// log.SetFlags(log.LstdFlags | log.Lshortfile)
mainConfigFile := flag.String("config", "/home/adacosta/.config/simelo/rextporter/main.toml", "Metrics main config file path.")
defaultListenPort := 8080
listenPort := flag.Uint("port", uint(defaultListenPort), "Listen port.")
defaultHandlerEndpoint := "/metrics"
handlerEndpoint := flag.String("handler", defaultHandlerEndpoint, "Handler endpoint.")
flag.Parse()
conf := config.MustConfigFromFileSystem(*mainConfigFile)
exporter.MustExportMetrics(*handlerEndpoint, uint16(*listenPort), conf)
conf, err := tomlconfig.ReadConfigFromFileSystem(*mainConfigFile)
if err != nil {
log.WithError(err).Errorln("error reading config from file system")
os.Exit(1)
}
var rootConf core.RextRoot
rootConf, err = toml2config.Fill(conf)
if err != nil {
log.WithError(err).Errorln("error filling config info")
os.Exit(1)
}
exporter.MustExportMetrics(*handlerEndpoint, uint16(*listenPort), rootConf)
waitForEver := make(chan bool)
<-waitForEver
}
10 changes: 10 additions & 0 deletions cmd/rxtc/lexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

import (
"github.com/simelo/rextporter/src/rxt"
"github.com/simelo/rextporter/src/rxt/grammar"
)

func main() {
grammar.LexTheRxt(&rxt.TokenWriter{}, "LEX")
}
60 changes: 50 additions & 10 deletions src/client/api_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/oliveagle/jsonpath"
"github.com/prometheus/client_golang/prometheus"
"github.com/simelo/rextporter/src/config"
"github.com/simelo/rextporter/src/core"
"github.com/simelo/rextporter/src/util"
log "github.com/sirupsen/logrus"
)
Expand All @@ -26,19 +26,59 @@ type APIRestCreator struct {
}

// CreateAPIRestCreator create an APIRestCreator
func CreateAPIRestCreator(metric config.Metric, service config.Service, dataSourceResponseDurationDesc *prometheus.Desc) (cf CacheableFactory, err error) {
func CreateAPIRestCreator(resConf core.RextResourceDef, srvConf core.RextServiceDef, dataSourceResponseDurationDesc *prometheus.Desc) (cf CacheableFactory, err error) {
resOptions := resConf.GetOptions()
httpMethod, err := resOptions.GetString(core.OptKeyRextResourceDefHTTPMethod)
if err != nil {
log.WithError(err).Errorln("Can not find httpMethod")
return cf, err
}
resURI := strings.TrimPrefix(resConf.GetResourcePATH(srvConf.GetBasePath()), srvConf.GetBasePath())
auth := resConf.GetAuth(srvConf.GetAuthForBaseURL())
var tkHeaderKey, tkKeyFromEndpoint, tkKeyGenEndpoint string
if auth != nil {
authOpts := auth.GetOptions()
tkHeaderKey, err = authOpts.GetString(core.OptKeyRextAuthDefTokenHeaderKey)
if err != nil {
log.WithError(err).Errorln("Can not find tokenHeaderKey")
return cf, err
}
tkKeyFromEndpoint, err = authOpts.GetString(core.OptKeyRextAuthDefTokenKeyFromEndpoint)
if err != nil {
log.WithError(err).Errorln("Can not find tokenKeyFromEndpoint")
return cf, err
}
tkKeyGenEndpoint, err = authOpts.GetString(core.OptKeyRextAuthDefTokenGenEndpoint)
if err != nil {
log.WithError(err).Errorln("Can not find tkKeyGenEndpoint")
return cf, err
}
} else {
log.Warnln("you have an empty auth")
}
srvOpts := srvConf.GetOptions()
jobName, err := srvOpts.GetString(core.OptKeyRextServiceDefJobName)
if err != nil {
log.WithError(err).Errorln("Can not find jobName")
return cf, err
}
instanceName, err := srvOpts.GetString(core.OptKeyRextServiceDefInstanceName)
if err != nil {
log.WithError(err).Errorln("Can not find instanceName")
return cf, err
}
cf = APIRestCreator{
baseFactory: baseFactory{
jobName: service.JobName(),
instanceName: service.InstanceName(),
dataSource: metric.URL,
jobName: jobName,
instanceName: instanceName,
dataSource: resURI,
dataSourceResponseDurationDesc: dataSourceResponseDurationDesc,
},
httpMethod: metric.HTTPMethod,
dataPath: service.URIToGetMetric(metric),
tokenPath: service.URIToGetToken(),
tokenHeaderKey: service.TokenHeaderKey,
tokenKeyFromEndpoint: service.TokenKeyFromEndpoint,
httpMethod: httpMethod,
dataPath: resConf.GetResourcePATH(srvConf.GetBasePath()),
tokenPath: tkKeyGenEndpoint,
tokenHeaderKey: tkHeaderKey,
tokenKeyFromEndpoint: tkKeyFromEndpoint,
}
return cf, err
}
Expand Down
25 changes: 17 additions & 8 deletions src/client/metrics_forwader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package client

import (
"compress/gzip"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"time"

"github.com/simelo/rextporter/src/config"
"github.com/simelo/rextporter/src/core"
"github.com/simelo/rextporter/src/util"
"github.com/simelo/rextporter/src/util/metrics"
log "github.com/sirupsen/logrus"
)

// ProxyMetricClientCreator create a metrics fordwader client
Expand All @@ -23,15 +23,24 @@ type ProxyMetricClientCreator struct {
}

// CreateProxyMetricClientCreator create a ProxyMetricClientCreator with required info to create a metrics fordwader client
func CreateProxyMetricClientCreator(service config.Service, fDefMetrics *metrics.DefaultFordwaderMetrics) (cf ProxyMetricClientCreator, err error) {
if !util.StrSliceContains(service.Modes, config.ServiceTypeProxy) {
return ProxyMetricClientCreator{}, errors.New("can not create a forward_metrics metric client from a service whitout type " + config.ServiceTypeProxy)
func CreateProxyMetricClientCreator(resConf core.RextResourceDef, srvConf core.RextServiceDef, fDefMetrics *metrics.DefaultFordwaderMetrics) (cf ProxyMetricClientCreator, err error) {
srvOpts := srvConf.GetOptions()
jobName, err := srvOpts.GetString(core.OptKeyRextServiceDefJobName)
if err != nil {
log.WithError(err).Errorln("Can not find jobName")
return cf, err
}
instanceName, err := srvOpts.GetString(core.OptKeyRextServiceDefInstanceName)
if err != nil {
log.WithError(err).Errorln("Can not find instanceName")
return cf, err
}
resPath := resConf.GetResourcePATH(srvConf.GetBasePath())
cf = ProxyMetricClientCreator{
defFordwaderMetrics: fDefMetrics,
dataPath: service.URIToGetExposedMetric(),
JobName: service.JobName(),
InstanceName: service.InstanceName(),
dataPath: resPath,
JobName: jobName,
InstanceName: instanceName,
}
return cf, err
}
Expand Down
Loading