From 9e02c2393a4db958b19e4261860880e3f7e40e9b Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Wed, 24 Apr 2013 16:59:40 +0200 Subject: [PATCH 1/2] Include generated Protocol Buffer descriptor. The Protocol Buffer compiler supports generating a machine-readable descriptor file encoded as a provided Protocol Buffer message type, which can be used to decode messages that have been encoded with it after-the-fact. The generated descriptor also bundles in dependent message types. We can use this to perform forensics on old Prometheus clients, if necessary. --- Makefile | 2 +- model/Makefile | 8 ++++++-- model/data.proto | 4 +++- model/generated/.gitignore | 6 ++---- web/blob/Makefile | 13 +++++++++++-- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 367e4aed6e..ee895f8f8b 100644 --- a/Makefile +++ b/Makefile @@ -76,7 +76,7 @@ test: build go test ./utility/... $(GO_TEST_FLAGS) go test ./web/... $(GO_TEST_FLAGS) -web: preparation +web: preparation model $(MAKE) -C web .PHONY: advice binary build clean documentation format model package preparation run search_index source_path test diff --git a/model/Makefile b/model/Makefile index 2382a6a2bb..328b33f5ef 100644 --- a/model/Makefile +++ b/model/Makefile @@ -11,14 +11,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +all: generated + +SUFFIXES: + MAKE_ARTIFACTS = generated-stamp -all: generated +include ../Makefile.INCLUDE generated: generated-stamp generated-stamp: data.proto - protoc --go_out=generated/ data.proto + protoc --proto_path=$(PREFIX)/include:. --go_out=generated/ --descriptor_set_out=generated/descriptor.blob data.proto touch $@ clean: diff --git a/model/data.proto b/model/data.proto index ce6cff9209..1678da4737 100644 --- a/model/data.proto +++ b/model/data.proto @@ -11,7 +11,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package dto; +package io.prometheus; + +import "google/protobuf/descriptor.proto"; message LabelPair { optional string name = 1; diff --git a/model/generated/.gitignore b/model/generated/.gitignore index cd6d21b5f9..01d8818eb2 100644 --- a/model/generated/.gitignore +++ b/model/generated/.gitignore @@ -1,4 +1,2 @@ -*.cc -*.go -*.h -*.o +data.pb.go +descriptor.blob diff --git a/web/blob/Makefile b/web/blob/Makefile index 891010d56a..171d1affbd 100644 --- a/web/blob/Makefile +++ b/web/blob/Makefile @@ -13,10 +13,19 @@ all: files.go -files.go: $(shell find ../templates/ ../static/ -type f) - ../../utility/embed-static.sh ../static ../templates | gofmt > $@ +SUFFIXES: + +generated: + mkdir -vp generated + +generated/protocol_buffer.descriptor: generated ../../model/generated/descriptor.blob + cp ../../model/generated/descriptor.blob -f $@ + +files.go: $(shell find ../templates/ ../static/ -type f) generated/protocol_buffer.descriptor + ../../utility/embed-static.sh ../static ../templates ./generated | gofmt > $@ clean: -rm files.go + -rm -rf generated .PHONY: clean From 1f96d4c822eed62dd1561908c3650101846cbcc2 Mon Sep 17 00:00:00 2001 From: Johannes 'fish' Ziemke Date: Wed, 24 Apr 2013 18:51:07 +0200 Subject: [PATCH 2/2] Move protobuf descriptor and add content-type. - move to static/generated - set content-type based on extension '.description' --- web/Makefile | 8 +++++++- web/blob/Makefile | 10 ++-------- web/blob/blob.go | 5 +++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/web/Makefile b/web/Makefile index 4f3cf0980d..ba0e5a7d8f 100644 --- a/web/Makefile +++ b/web/Makefile @@ -13,10 +13,16 @@ all: blob -blob: +blob: static/generated/protocol_buffer.descriptor $(MAKE) -C blob clean: $(MAKE) -C blob clean +static/generated: + mkdir -vp static/generated + +static/generated/protocol_buffer.descriptor: static/generated ../model/generated/descriptor.blob + cp ../model/generated/descriptor.blob -f $@ + .PHONY: blob clean diff --git a/web/blob/Makefile b/web/blob/Makefile index 171d1affbd..5c64fa1925 100644 --- a/web/blob/Makefile +++ b/web/blob/Makefile @@ -15,14 +15,8 @@ all: files.go SUFFIXES: -generated: - mkdir -vp generated - -generated/protocol_buffer.descriptor: generated ../../model/generated/descriptor.blob - cp ../../model/generated/descriptor.blob -f $@ - -files.go: $(shell find ../templates/ ../static/ -type f) generated/protocol_buffer.descriptor - ../../utility/embed-static.sh ../static ../templates ./generated | gofmt > $@ +files.go: $(shell find ../templates/ ../static/ -type f) + ../../utility/embed-static.sh ../static ../templates | gofmt > $@ clean: -rm files.go diff --git a/web/blob/blob.go b/web/blob/blob.go index 5ba0b0ee27..2edd278b9f 100644 --- a/web/blob/blob.go +++ b/web/blob/blob.go @@ -16,8 +16,9 @@ const ( ) var mimeMap = map[string]string{ - "css": "text/css", - "js": "text/javascript", + "css": "text/css", + "js": "text/javascript", + "descriptor": "application/vnd.google.protobuf;proto=google.protobuf.FileDescriptorSet", } func GetFile(bucket string, name string) ([]byte, error) {