Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/#477 prometheus #526

Closed
wants to merge 10 commits into from

Conversation

flaviostutz
Copy link
Contributor

Background

This is a complete initial implementation of Prometheus Exporter support as discussed in #477

Checklist

  • Git commit messages conform to community standards.
  • Each Git commit represents meaningful milestones or atomic units of work.
  • Changed or added code is covered by appropriate tests.

@flaviostutz
Copy link
Contributor Author

There are some unit tests failing randomly. I think this is due to some bugs detected by fuzzy tests on the encode csv part. Seems like encode/decode generated an additional "\r" in URL string. I am trying to fix some of them, but I think none is related to Prometheus commit itself. What should we do?

Copy link
Owner

@tsenart tsenart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this! I'd like us to try to keep the Attacker separate from Prometheus stuff. The way we can do that is by hooking into the results channel returned by the Attack method — for each Result that we read, we update Prometheus metrics in

case r, ok := <-res:

README.md Outdated Show resolved Hide resolved
ports:
- 8880:8880
environment:
- TARGET_URL=https://www.uol.com.br
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we change this default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I am changing to www.yahoo.com, is this ok?


vegeta:
build: .
image: flaviostutz/vegeta
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would love to build and publish an official project Docker image. I see you opened a separate issue for that. What would it take to get that done?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dockerfile/docker-compose.yml created really solves #525. We would close #525 with current PR.

For an official Docker image, you should create a new Repository in Dockerhub with tsenart/vegeta name and we could configure an automated build there that automatically build master "branch" to "latest" and any tagged git to a tagged image in Dockerhub. I have not prepared this Dockerfile thinking about being an official image, because it doesn't support all vegeta properties. We could discuss that in a separate issue if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option is we can use a random name in "image" field, because this is only a local name (not necessary published in Dockerhub). What do you think?

- REQUESTS_PER_SECOND=5

prometheus:
image: flaviostutz/prometheus
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this image.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an extension of the official prometheus image. In this image I added the option to pass scrape configurations using environment variables. In official prometheus image, they place configuration files in volumes, which is not a good pattern because it generates a "stateful" situation on operation (one has to create a configuration file and place in volumes, oposed to simply setting configurations in ENV parameters).

If you like we can remove this service from docker-compose.yml.

var requestSecondsHistogram = promauto.NewHistogramVec(prometheus.HistogramOpts{
Name: "request_seconds",
Help: "Request latency",
Buckets: []float64{0.1, 0.2, 0.5, 1.0, 2.0, 5.0, 10.0, 20, 50},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How have you chosen these buckets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on my experience. Do you have any other references? Surely we can change.

lib/attack.go Outdated Show resolved Hide resolved
"status",
})

var requestBytesInCounter = promauto.NewCounterVec(prometheus.CounterOpts{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because Prometheus can be used as a library, two Attackers could be instantiated in the same Go process, so global variables for these metrics shouldn't be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but Prometheus lib is thread safe. The two attackers should share the same counters, right? (maybe I missed something)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If summing the two (or more) attackers is not the case, we should differentiate the metrics by a new label...

@flaviostutz
Copy link
Contributor Author

There are some unit tests failing randomly. I think this is due to some bugs detected by fuzzy tests on the encode csv part. Seems like encode/decode generated an additional "\r" in URL string. I am trying to fix some of them, but I think none is related to Prometheus commit itself. What should we do?

By setting a fixed seed to random generators I think those random errors should stop happening so that the tests would be repeatable. What do you think about flyingmutant/rapid#14?

@flaviostutz

This comment has been minimized.

@flaviostutz
Copy link
Contributor Author

Thanks for working on this! I'd like us to try to keep the Attacker separate from Prometheus stuff. The way we can do that is by hooking into the results channel returned by the Attack method — for each Result that we read, we update Prometheus metrics in

case r, ok := <-res:

I will look into that.

Placing Prometheus outside "Attacker" lib would be great, but we would lose Prometheus support when someone is using the lib. Prometheus would work only from the command line then. The way it was implemented the lib will have Prometheus Exporter too.

Placing Prometheus support to the lib should even help the guys from nitishm/vegeta-server#17.

What do you think it would be a better pattern?

@tsenart
Copy link
Owner

tsenart commented Jul 4, 2020 via email

@flaviostutz
Copy link
Contributor Author

You can factor out the Prometheus metrics into a struct type that gets instantiated via a constructors and add a method Observe that takes in a Result. Then it’s easy to use, just create a sub package in lib called prometheus. Sent via Superhuman iOS ( https://sprh.mn/[email protected] )

On Sat, Jul 4 2020 at 10:32 PM, Flavio Stutz < @.*** > wrote: > >> >> >> Thanks for working on this! I'd like us to try to keep the Attacker separate >> from Prometheus stuff. The way we can do that is by hooking into the results >> channel returned by the Attack method — for each Result that we read, we >> update Prometheus metrics in >>

case r, ok := <-res:
>> >> >> > > > > I will look into that. > > Placing Prometheus outside "Attacker" lib would be great, but we would lose Prometheus support when someone is using the lib. Prometheus would work only from the command line then. The way it was implemented the lib will have Prometheus Exporter too. Placing Prometheus support to the lib should even help the guys from nitishm/vegeta-server#17 ( nitishm/vegeta-server#17 ). What do you think it would be a better pattern? — You are receiving this because your review was requested. Reply to this email directly, view it on GitHub ( #526 (comment) ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAAQPD77RYLOCWCB2HHBODTRZ6GUVANCNFSM4OONPOFQ ).

Great! So I will separate concerns but keep Prometheus Exporter capabilities in lib too, right?
Please, check the other revision items from this PR too :)

Thanks.

@flaviostutz
Copy link
Contributor Author

Closing this PR to continue review in #534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants