lorem_metrics

package
v0.0.0-...-d5bb415 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 24, 2017 License: GPL-3.0 Imports: 14 Imported by: 1

README

lorem-metrics

This is simple service module. Only for showing the micro service with HTTP and return json. The purpose for this service is only generating lorem ipsum paragraph and return the payload.

In this part I will demonstrate how to show your service metrics. I copied from lorem-rate-limit

I am fully using all three functions from the golorem library.

Required libraries

go get github.com/go-kit/kit
go get github.com/drhodes/golorem
go get github.com/gorilla/mux
go get github.com/juju/ratelimit
go get github.com/prometheus/client_golang/prometheus
service.go

Business logic will be put here

endpoint.go

Endpoint will be created here

transport.go

Handling about encode and decode json

logging.go

Logging function is under this file

instrument.go

Middleware function. For this sample, this function for rate limiting and metrics.

lorem-metrics.d

Go main function will be located under this folder. The dot d means daemon.

execute
cd $GOPATH/src/github.com/ru-rocker/gokit-playground
go run lorem-metrics/lorem-metrics.d/main.go
Running Prometheus and Grafana

To execute type

cd $GOPATH/src/github.com/ru-rocker/gokit-playground
docker-compose -f docker/docker-compose-prometheus-grafana.yml up -d

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadRouting is returned when an expected path variable is missing.
	ErrBadRouting = errors.New("inconsistent mapping between route and handler (programmer error)")
)
View Source
var (
	ErrRequestTypeNotFound = errors.New("Request type only valid for word, sentence and paragraph")
)

Functions

func MakeHttpHandler

func MakeHttpHandler(_ context.Context, endpoint Endpoints, logger log.Logger) http.Handler

Make Http Handler

func MakeLoremLoggingEndpoint

func MakeLoremLoggingEndpoint(svc Service) endpoint.Endpoint

creating Lorem Ipsum Endpoint

Types

type Endpoints

type Endpoints struct {
	LoremEndpoint endpoint.Endpoint
}

endpoints wrapper

type LoremRequest

type LoremRequest struct {
	RequestType string
	Min         int
	Max         int
}

request

type LoremResponse

type LoremResponse struct {
	Message string `json:"message"`
	Err     error  `json:"err,omitempty"`
}

response

type LoremService

type LoremService struct {
}

Implement service with empty struct

func (LoremService) Paragraph

func (LoremService) Paragraph(min, max int) string

func (LoremService) Sentence

func (LoremService) Sentence(min, max int) string

func (LoremService) Word

func (LoremService) Word(min, max int) string

Implement service functions

type Service

type Service interface {
	// generate a word with at least min letters and at most max letters.
	Word(min, max int) string

	// generate a sentence with at least min words and at most max words.
	Sentence(min, max int) string

	// generate a paragraph with at least min sentences and at most max sentences.
	Paragraph(min, max int) string
}

Define service interface

type ServiceMiddleware

type ServiceMiddleware func(Service) Service

create type that return function. this will be needed in main.go

func LoggingMiddleware

func LoggingMiddleware(logger log.Logger) ServiceMiddleware

implement function to return ServiceMiddleware

func Metrics

func Metrics(requestCount metrics.Counter,
	requestLatency metrics.Histogram) ServiceMiddleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL