Skip to content

Commit

Permalink
INFINITY-3565 Fix build/instructions for collector-emitter example (#145
Browse files Browse the repository at this point in the history
)

* INFINITY-3565 Fix build/instructions for collector-emitter example

* Fix lint: Use alias for schema package

* Clean up schema generation, fix 'clean' call
  • Loading branch information
nickbp authored and philipnrmn committed Apr 30, 2018
1 parent 05326e7 commit 511d10e
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 29 deletions.
5 changes: 3 additions & 2 deletions Makefile
Expand Up @@ -7,6 +7,7 @@ all: clean build test
build: docker
$(call buildIt,collector)
$(call buildIt,statsd-emitter)
$(call buildIt,collector-emitter)

.PHONY: plugins
plugins: docker clean
Expand All @@ -18,8 +19,8 @@ test: docker clean build

.PHONY: clean
clean:
rm -rf ./build
rm -rf ./schema/metrics_schema
# Clean from within the docker container to avoid issues with file permissions:
$(call buildIt,clean)

.PHONY: docker
docker:
Expand Down
3 changes: 3 additions & 0 deletions dcos-metrics.go
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// 'go generate' must be run for the 'metrics_schema' package to be present:
//go:generate go generate github.com/dcos/dcos-metrics/schema/

package main

import (
Expand Down
2 changes: 1 addition & 1 deletion examples/collector-emitter/.gitignore
@@ -1 +1 @@
collector-emitter
collector-emitter*
5 changes: 3 additions & 2 deletions examples/collector-emitter/README.md
Expand Up @@ -15,9 +15,10 @@ apt-get install golang-go

```bash
go get -u github.com/dcos/dcos-metrics
cd $GOPATH/src/github.com/dcos/dcos-metrics
cd $GOPATH/src/github.com/dcos/dcos-metrics/examples/collector-emitter/
go generate # creates 'metrics_schema' package
go build
go build # local native build
CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -ldflags="-s -w" -o collector-emitter-linux # linux build (for clusters)
```

If you see errors about `cannot find package "github.com/.../metrics_schema"`, you forgot to perform `go generate`.
Expand Down
20 changes: 10 additions & 10 deletions examples/collector-emitter/main.go
@@ -1,7 +1,7 @@
package main

// 'go generate' must be run for the 'metricsSchema' package to be present:
//go:generate go run ../../schema/generator.go -infile ../../schema/metrics.avsc -outfile metrics_schema/schema.go
// 'go generate' must be run for the 'metrics_schema' package to be present:
//go:generate go generate github.com/dcos/dcos-metrics/schema/

import (
"flag"
Expand All @@ -14,7 +14,7 @@ import (

log "github.com/Sirupsen/logrus"

"github.com/dcos/dcos-metrics/schema/metrics_schema"
schema "github.com/dcos/dcos-metrics/schema/metrics_schema"
"github.com/linkedin/goavro"
)

Expand All @@ -31,14 +31,14 @@ var (
blockTickMsFlag = flag.Int("block-tick-ms", 500,
"Number of milliseconds to wait before flushing the current avro block (0 = disabled)")

datapointNamespace = goavro.RecordEnclosingNamespace(metricsSchema.DatapointNamespace)
datapointSchema = goavro.RecordSchema(metricsSchema.DatapointSchema)
datapointNamespace = goavro.RecordEnclosingNamespace(schema.DatapointNamespace)
datapointSchema = goavro.RecordSchema(schema.DatapointSchema)

metricListNamespace = goavro.RecordEnclosingNamespace(metricsSchema.MetricListNamespace)
metricListSchema = goavro.RecordSchema(metricsSchema.MetricListSchema)
metricListNamespace = goavro.RecordEnclosingNamespace(schema.MetricListNamespace)
metricListSchema = goavro.RecordSchema(schema.MetricListSchema)

tagNamespace = goavro.RecordEnclosingNamespace(metricsSchema.TagNamespace)
tagSchema = goavro.RecordSchema(metricsSchema.TagSchema)
tagNamespace = goavro.RecordEnclosingNamespace(schema.TagNamespace)
tagSchema = goavro.RecordSchema(schema.TagSchema)

startTime = time.Now()
)
Expand Down Expand Up @@ -144,7 +144,7 @@ func buildDatapoint(name string, timeMs int64, value float64) interface{} {
// ---

func runTCPSerializerSender(recordsChan <-chan []interface{}) {
codec, err := goavro.NewCodec(metricsSchema.MetricListSchema)
codec, err := goavro.NewCodec(schema.MetricListSchema)
if err != nil {
log.Fatal("Failed to initialize avro codec: ", err)
}
Expand Down
3 changes: 3 additions & 0 deletions schema/generator.go
Expand Up @@ -12,6 +12,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// 'go generate' must be run for the 'metrics_schema' package to be present:
//go:generate go run generator.go -infile metrics.avsc -outfile metrics_schema/schema.go

// Generate Go code from an Avro schema.
package main

Expand Down
15 changes: 6 additions & 9 deletions scripts/build.ps1
Expand Up @@ -19,13 +19,13 @@ function license_check
Get-ChildItem -File -Filter *.go -Recurse | ?{ $_.FullName -notmatch "\\vendor\\" } | ?{ $_.FullName -notmatch "\\schema\\" } | ?{ $_.FullName -notmatch "\\examples\\" } |
ForEach-Object {
$fullName = $_.FullName
$output = Select-String -Pattern "Copyright [0-9]{4} Mesosphere, Inc." $fullName
$output = Select-String -Pattern "Copyright [0-9]{4} Mesosphere, Inc." $fullName
if (-not $output)
{
Write-Output("$fullName does not have proper Mesosphere copyright")
$retval=$retval+1
}
$output = Select-String -SimpleMatch "Licensed under the Apache License, Version 2.0 (the `"License`");" $fullName
$output = Select-String -SimpleMatch "Licensed under the Apache License, Version 2.0 (the `"License`");" $fullName
if (-not $output)
{
Write-Output("$fullName does not have proper Apache license")
Expand All @@ -36,11 +36,8 @@ function license_check

function build_collector()
{
$curLocation = Get-Location
Set-Location "$SOURCE_DIR/schema"
& go run generator.go -infile metrics.avsc -outfile ./metrics_schema/schema.go
& go generate github.com/dcos/dcos-metrics/
fastfail("Failed to generate schema.go.")
Set-Location $curLocation

$filenames = ""
Get-ChildItem -file -Filter *.go |
Expand Down Expand Up @@ -109,7 +106,7 @@ foreach ($arg in $args)
{
$SOURCE_DIR = & git rev-parse --show-toplevel
fastfail("Failed to find top-level source directory. Cannot find git.exe?")

$GIT_REF = & git describe --tags --always
fastfail("Failed to get git ref")

Expand All @@ -119,15 +116,15 @@ foreach ($arg in $args)
fastfail("Failed to get revision")

$PLATFORM = "Windows"

try
{
main $arg
}
catch
{
Write-Output ("Failed build for component $arg")
exit -1
exit -1
}
}
& tree /F build
Expand Down
22 changes: 17 additions & 5 deletions scripts/build.sh
Expand Up @@ -29,27 +29,39 @@ function license_check {
fi
}

function build_clean {
rm -rf ./build
rm -rf ./schema/metrics_schema
}

function build_collector {
license_check
# build metrics_schema package
pushd "${SOURCE_DIR}/schema"
go run generator.go -infile metrics.avsc -outfile ./metrics_schema/schema.go
popd
# generate metrics_schema package used by collector
go generate github.com/dcos/dcos-metrics/

# build binary
go build -a -o ${BUILD_DIR}/dcos-metrics-${COMPONENT}-${GIT_REF} \
-ldflags "-X main.VERSION=${VERSION} -X main.REVISION=${REVISION} -X github.com/dcos/dcos-metrics/util/http/client.USERAGENT=dcos-metrics/${VERSION}" \
*.go
}

function build_collector-emitter {
# generate metrics_schema package used by example
go generate github.com/dcos/dcos-metrics/examples/collector-emitter/

# build binary
go build -a -o ${BUILD_DIR}/dcos-metrics-${COMPONENT}-${GIT_REF} \
examples/collector-emitter/main.go
}

function build_statsd-emitter {
go build -a -o ${BUILD_DIR}/dcos-metrics-${COMPONENT}-${GIT_REF} \
examples/statsd-emitter/main.go
}

function build_plugins {
license_check

for PLUGIN in $(cd plugins/ && ls -d */ | sed 's,/,,'); do
pluginPath=${BUILD_DIR}/dcos-metrics-${PLUGIN}-plugin@${GIT_REF}
echo "Building plugin: $PLUGIN"
Expand Down

0 comments on commit 511d10e

Please sign in to comment.