Skip to content

Commit

Permalink
Merge pull request #389 from smacker/default_port_for_analyzer
Browse files Browse the repository at this point in the history
Default port for analyzer
  • Loading branch information
smacker authored Dec 5, 2018
2 parents a9dd4e0 + b581914 commit 5fc642f
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions cmd/dummy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/src-d/lookout/util/cli"
"github.com/src-d/lookout/util/grpchelper"
"google.golang.org/grpc"
"gopkg.in/src-d/go-log.v1"
log "gopkg.in/src-d/go-log.v1"
"gopkg.in/src-d/lookout-sdk.v0/pb"
)

Expand All @@ -20,7 +20,7 @@ var (

type ServeCommand struct {
cli.CommonOptions
Analyzer string `long:"analyzer" default:"ipv4://localhost:10302" env:"LOOKOUT_ANALYZER" description:"gRPC URL to bind the analyzer to"`
Analyzer string `long:"analyzer" default:"ipv4://0.0.0.0:9930" env:"LOOKOUT_ANALYZER" description:"gRPC URL to bind the analyzer to"`
DataServer string `long:"data-server" default:"ipv4://localhost:10301" env:"LOOKOUT_DATA_SERVER" description:"gRPC URL of the data server"`
RequestUAST bool `long:"uast" env:"LOOKOUT_REQUEST_UAST" description:"analyzer will request UAST from the data server"`
RequestFilesPush bool `long:"files" env:"LOOKOUT_REQUEST_FILES" description:"on push events the analyzer will request files from HEAD, and return comments"`
Expand Down
10 changes: 7 additions & 3 deletions cmd/lookout-sdk/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

gogit "gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-log.v1"
log "gopkg.in/src-d/go-log.v1"
"gopkg.in/src-d/lookout-sdk.v0/pb"
)

Expand All @@ -33,8 +33,8 @@ type EventCommand struct {
RevTo string `long:"to" default:"HEAD" description:"name of the head revision for event"`
ConfigJSON string `long:"config-json" description:"arbitrary JSON configuration for request to an analyzer"`
Args struct {
Analyzer string `positional-arg-name:"analyzer" description:"gRPC URL of the analyzer to use"`
} `positional-args:"yes" required:"yes"`
Analyzer string `positional-arg-name:"analyzer" description:"gRPC URL of the analyzer to use (default: ipv4://localhost:9930)"`
} `positional-args:"yes"`

repo *gogit.Repository
}
Expand Down Expand Up @@ -168,6 +168,10 @@ func (c *EventCommand) initDataServer(srv *lookout.DataServerHandler) (startFunc
}

func (c *EventCommand) analyzerClient() (lookout.AnalyzerClient, error) {
if c.Args.Analyzer == "" {
c.Args.Analyzer = "ipv4://localhost:9930"
}

var err error
log.Infof("starting looking for Analyzer at %s", c.Args.Analyzer)

Expand Down
14 changes: 7 additions & 7 deletions cmd/sdk-test/bblfsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ func (suite *BblfshIntegrationSuite) TearDownSuite() {
}

func (suite *BblfshIntegrationSuite) RunReview() io.Reader {
return suite.RunCli("review", "ipv4://localhost:10302",
return suite.RunCli("review",
"--git-dir="+suite.gitPath,
"--from="+logLineRevision.Base.Hash,
"--to="+logLineRevision.Head.Hash)
}

func (suite *BblfshIntegrationSuite) RunPush() io.Reader {
return suite.RunCli("push", "ipv4://localhost:10302",
return suite.RunCli("push",
"--git-dir="+suite.gitPath,
"--from="+logLineRevision.Base.Hash,
"--to="+logLineRevision.Head.Hash)
}

func (suite *BblfshIntegrationSuite) TestReviewNoBblfshError() {
r := suite.RunCli("review", "ipv4://localhost:10302",
r := suite.RunCli("review",
"--bblfshd=ipv4://localhost:0000",
"--git-dir="+suite.gitPath,
"--from="+logLineRevision.Base.Hash,
Expand All @@ -59,7 +59,7 @@ func (suite *BblfshIntegrationSuite) TestReviewNoUASTWarning() {
fixture := fixtures.GetByName("bblfsh-unknown-language")
rv := fixture.GetCommitRevision()

r := suite.RunCli("push", "ipv4://localhost:10302",
r := suite.RunCli("push",
"--git-dir="+suite.gitPath,
"--from="+rv.Base.Hash,
"--to="+rv.Head.Hash)
Expand All @@ -77,7 +77,7 @@ func (suite *BblfshIntegrationSuite) TestReviewLanguage() {
}

func (suite *BblfshIntegrationSuite) TestPushNoBblfshError() {
r := suite.RunCli("push", "ipv4://localhost:10302",
r := suite.RunCli("push",
"--bblfshd=ipv4://localhost:0000",
"--git-dir="+suite.gitPath,
"--from="+logLineRevision.Base.Hash,
Expand All @@ -89,7 +89,7 @@ func (suite *BblfshIntegrationSuite) TestPushNoUASTWarning() {
fixture := fixtures.GetByName("bblfsh-unknown-language")
rv := fixture.GetCommitRevision()

r := suite.RunCli("push", "ipv4://localhost:10302",
r := suite.RunCli("push",
"--git-dir="+suite.gitPath,
"--from="+rv.Base.Hash,
"--to="+rv.Head.Hash)
Expand All @@ -109,7 +109,7 @@ func (suite *BblfshIntegrationSuite) TestPushLanguage() {
func (suite *BblfshIntegrationSuite) TestConnectToDataServer() {
log.DefaultLogger = log.New(log.Fields{"app": "test"})

bblfshAnalyzerAddr := "ipv4://localhost:10303"
bblfshAnalyzerAddr := "ipv4://localhost:9931"

a := &BbblfshClientAnalyzer{}

Expand Down
6 changes: 3 additions & 3 deletions cmd/sdk-test/dummy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (suite *SDKDummyTestSuite) TearDownTest() {
func (suite *SDKDummyTestSuite) TestReview() {
suite.StartDummy("--files")

r := suite.RunCli("review", "ipv4://localhost:10302",
r := suite.RunCli("review",
"--git-dir="+suite.gitPath,
"--from="+logLineRevision.Base.Hash,
"--to="+logLineRevision.Head.Hash)
Expand All @@ -33,7 +33,7 @@ func (suite *SDKDummyTestSuite) TestReview() {
func (suite *SDKDummyTestSuite) TestPush() {
suite.StartDummy("--files")

r := suite.RunCli("push", "ipv4://localhost:10302",
r := suite.RunCli("push",
"--git-dir="+suite.gitPath,
"--from="+logLineRevision.Base.Hash,
"--to="+logLineRevision.Head.Hash)
Expand All @@ -43,7 +43,7 @@ func (suite *SDKDummyTestSuite) TestPush() {
func (suite *SDKDummyTestSuite) TestPushNoComments() {
suite.StartDummy()

r := suite.RunCli("push", "ipv4://localhost:10302",
r := suite.RunCli("push",
"--git-dir="+suite.gitPath,
"--from="+logLineRevision.Base.Hash,
"--to="+logLineRevision.Head.Hash)
Expand Down
2 changes: 1 addition & 1 deletion cmd/server-test/error_analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (suite *ErrorAnalyzerIntegrationSuite) startAnalyzer(ctx context.Context, a
server := grpchelper.NewServer()
lookout.RegisterAnalyzerServer(server, a)

lis, err := pb.Listen("ipv4://localhost:10302")
lis, err := pb.Listen("ipv4://localhost:9930")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion config.yml.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
analyzers:
- name: Dummy
addr: ipv4://localhost:10302
addr: ipv4://localhost:9930
# feedback: url to link in the comment_footer. For example, to open a new GitHub issue

providers:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
image: "srcd/lookout-dummy-analyzer:latest"
network_mode: "host"
ports:
- "10302:10302"
- "9930:9930"
bblfsh:
image: "bblfsh/bblfshd:v2.9.0-drivers"
privileged: true
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Each analyzer to be requested by **lookout** should be defined under `analyzers`
```yml
analyzers:
- name: Example name # required, unique name of the analyzer
addr: ipv4://localhost:10302 # required, gRPC address
addr: ipv4://localhost:9930 # required, gRPC address
disabled: false # optional, false by default
feedback: http://example.com/analyzer # url to link in the comment_footer
settings: # optional, this field is sent to analyzer "as is"
Expand Down
2 changes: 1 addition & 1 deletion fixtures/double_dummy_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
analyzers:
- name: Dummy1
addr: ipv4://localhost:10302
addr: ipv4://localhost:9930
- name: Dummy2
addr: ipv4://localhost:10303
2 changes: 1 addition & 1 deletion fixtures/dummy_config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
analyzers:
- name: Dummy
addr: ipv4://localhost:10302
addr: ipv4://localhost:9930
11 changes: 6 additions & 5 deletions sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,19 @@ Both `lookout-sdk push` and `lookout-sdk review` can be configured with environm
| | `--to=` | name of the head revision for event | `HEAD` |
| | `--config-json=` | arbitrary JSON configuration for request to an analyzer | |

Optional positional argument is a gRPC URL of the analyzer to use (default: `ipv4://localhost:9930`).

### NotifyReviewEvent

The main output of the Analyzer will be the `NotifyReviewEvent` response comments, triggered by Pull Requests from GitHub. For development purposes you can manually trigger a review event for a Git repository in your local filesystem, using `lookout-sdk review`.

For example, if you place the `lookout-sdk` binary in a git repository directory, you can run:

```bash
$ ./lookout-sdk review ipv4://localhost:10302
$ ./lookout-sdk review
```

In this case the `lookout-sdk` binary will send a gRPC `NotifyReviewEvent` call to your Analyzer, which should be listening on `ipv4://localhost:10302`. The analyzer will be able to request file contents and UAST to the gRPC Data Server endpoint, exposed by the `lookout-sdk` binary at `ipv4://localhost:10301`.
In this case the `lookout-sdk` binary will send a gRPC `NotifyReviewEvent` call to your Analyzer, which should be listening on `ipv4://localhost:9930`. The analyzer will be able to request file contents and UAST to the gRPC Data Server endpoint, exposed by the `lookout-sdk` binary at `ipv4://localhost:10301`.

The lookout-sdk process will wait until the Analyzer sends a response with the comments, and exit right after that. This means the Data Server endpoint will also stop being available.

Expand Down Expand Up @@ -107,14 +109,13 @@ For example, using commit sha1s:
```bash
$ ./lookout-sdk review \
--from=fa97fa19e5c9b3482e5f88e264fb62b1e7fc6d8f \
--to=355f001d719bd0368c0469acd1a46298a80bacc0 \
ipv4://localhost:10302
--to=355f001d719bd0368c0469acd1a46298a80bacc0
```

Let's say you have `branch-c` that is ahead of `master` by a few commits. Then you could run:

```bash
$ ./lookout-sdk review --from=master --to=branch-c ipv4://localhost:10302
$ ./lookout-sdk review --from=master --to=branch-c
```

### NotifyPushEvent
Expand Down

0 comments on commit 5fc642f

Please sign in to comment.