Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
Move protos to their own packages.
Browse files Browse the repository at this point in the history
This will simplify the internal <-> github conversion maintenance. Also:
 = It will reduces the chances of surprising name collisions that we have deal with now, after migrations to Github.
 = Autogenned protobuf Go files won't pollute the package documentation.

I plan to do it in multiple CLs.

ORIGINAL_AUTHOR=Manu Garg <manugarg@gmail.com>
PiperOrigin-RevId: 192519069
  • Loading branch information
manugarg committed Apr 12, 2018
1 parent 2b0af06 commit 0d5794a
Show file tree
Hide file tree
Showing 22 changed files with 379 additions and 350 deletions.
54 changes: 27 additions & 27 deletions config/config.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion config/config.proto
@@ -1,6 +1,6 @@
syntax = "proto2";

import "github.com/google/cloudprober/probes/config.proto";
import "github.com/google/cloudprober/probes/proto/config.proto";
import "github.com/google/cloudprober/servers/config.proto";
import "github.com/google/cloudprober/targets/targets.proto";
import "github.com/google/cloudprober/surfacers/config.proto";
Expand Down
17 changes: 9 additions & 8 deletions message/message.go
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc.
// Copyright 2017-2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,7 @@ import (
"time"

"github.com/golang/protobuf/proto"
msgpb "github.com/google/cloudprober/message/proto"
)

// FlowState maintains the state of flow on both the src and dst sides.
Expand Down Expand Up @@ -71,7 +72,7 @@ const (
lostThreshold = 3600 * 24
)

var constants Constants
var constants msgpb.Constants

// Uint64ToNetworkBytes converts a 64bit unsigned integer to an 8-byte slice.
// in network byte order.
Expand Down Expand Up @@ -106,13 +107,13 @@ func NetworkBytesToUint64(bytes []byte) uint64 {
// Message is a wrapper struct for the message protobuf that provides
// functions to access the most commonly accessed fields.
type Message struct {
m *Msg
m *msgpb.Msg
}

// NewMessage parses a byte array into a message.
func NewMessage(msgBytes []byte) (*Message, error) {
m := &Message{
m: &Msg{},
m: &msgpb.Msg{},
}

msg := m.m
Expand Down Expand Up @@ -199,15 +200,15 @@ func (fs *FlowState) CreateMessage(src string, dst string, ts time.Time, maxLen
fs.mu.Lock()
defer fs.mu.Unlock()

dstType := DataNode_SERVER
msg := &Msg{
dstType := msgpb.DataNode_SERVER
msg := &msgpb.Msg{
Magic: proto.Uint64(constants.GetMagic()),
Seq: Uint64ToNetworkBytes(fs.seq + 1),
Src: &DataNode{
Src: &msgpb.DataNode{
Name: proto.String(src),
TimestampUsec: Uint64ToNetworkBytes(uint64(ts.UnixNano()) / 1000),
},
Dst: &DataNode{
Dst: &msgpb.DataNode{
Name: proto.String(dst),
TimestampUsec: Uint64ToNetworkBytes(uint64(0)),
Type: &dstType,
Expand Down
21 changes: 18 additions & 3 deletions message/message_test.go
@@ -1,10 +1,25 @@
// Copyright 2017-2018 Google Inc.
//
// 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 message

import (
"testing"
"time"

"github.com/golang/protobuf/proto"
msgpb "github.com/google/cloudprober/message/proto"
)

// createMessage is a helper function for creating a message and fatally failing
Expand Down Expand Up @@ -91,13 +106,13 @@ func TestInvalidMessage(t *testing.T) {
}

// Invalid magic.
msg := &Msg{
msg := &msgpb.Msg{
Magic: proto.Uint64(constants.GetMagic() + 1),
Seq: Uint64ToNetworkBytes(seq),
Src: &DataNode{
Src: &msgpb.DataNode{
Name: proto.String(src),
},
Dst: &DataNode{
Dst: &msgpb.DataNode{
Name: proto.String(dst),
},
}
Expand Down
78 changes: 39 additions & 39 deletions message/message.pb.go → message/proto/message.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
5 changes: 3 additions & 2 deletions probes/http/cmd/http.go
@@ -1,4 +1,4 @@
// Copyright 2017 Google Inc.
// Copyright 2017-2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@ import (
"github.com/golang/protobuf/proto"
"github.com/google/cloudprober/metrics"
"github.com/google/cloudprober/probes/http"
configpb "github.com/google/cloudprober/probes/http/proto"
"github.com/google/cloudprober/probes/options"
"github.com/google/cloudprober/targets"
)
Expand All @@ -42,7 +43,7 @@ var (
func main() {
flag.Parse()

c := &http.ProbeConf{}
c := &configpb.ProbeConf{}

// If we are given a config file, read it. If not, use defaults.
if *config != "" {
Expand Down
9 changes: 5 additions & 4 deletions probes/http/http.go
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/google/cloudprober/logger"
"github.com/google/cloudprober/metrics"
configpb "github.com/google/cloudprober/probes/http/proto"
"github.com/google/cloudprober/probes/options"
"github.com/google/cloudprober/probes/probeutils"
)
Expand All @@ -39,7 +40,7 @@ const (
type Probe struct {
name string
opts *options.Options
c *ProbeConf
c *configpb.ProbeConf
l *logger.Logger
client *http.Client

Expand Down Expand Up @@ -99,7 +100,7 @@ func (prr probeRunResult) Target() string {

// Init initializes the probe with the given params.
func (p *Probe) Init(name string, opts *options.Options) error {
c, ok := opts.ProbeConf.(*ProbeConf)
c, ok := opts.ProbeConf.(*configpb.ProbeConf)
if !ok {
return fmt.Errorf("no http config")
}
Expand All @@ -113,9 +114,9 @@ func (p *Probe) Init(name string, opts *options.Options) error {
p.targets = p.opts.Targets.List()

switch p.c.GetProtocol() {
case ProbeConf_HTTP:
case configpb.ProbeConf_HTTP:
p.protocol = "http"
case ProbeConf_HTTPS:
case configpb.ProbeConf_HTTPS:
p.protocol = "https"
default:
p.l.Errorf("Invalid Protocol: %s", p.c.GetProtocol())
Expand Down
3 changes: 2 additions & 1 deletion probes/http/http_test.go
Expand Up @@ -21,6 +21,7 @@ import (
"time"

"github.com/golang/protobuf/proto"
configpb "github.com/google/cloudprober/probes/http/proto"
"github.com/google/cloudprober/probes/options"
"github.com/google/cloudprober/probes/probeutils"
"github.com/google/cloudprober/targets"
Expand Down Expand Up @@ -55,7 +56,7 @@ func TestRun(t *testing.T) {
Targets: targets.StaticTargets("test.com"),
Interval: 2 * time.Second,
Timeout: time.Second,
ProbeConf: &ProbeConf{
ProbeConf: &configpb.ProbeConf{
RequestsPerProbe: proto.Int32(1),
StatsExportIntervalMsec: proto.Int32(1000),
},
Expand Down

0 comments on commit 0d5794a

Please sign in to comment.