Skip to content

Commit

Permalink
Add tests to cover new entry points in noop adapter. (istio#3219)
Browse files Browse the repository at this point in the history
- And of course, found a bug in the process...

- Fix a few broken doc hyperlinks
  • Loading branch information
geeknoid authored Feb 6, 2018
1 parent a7ad28f commit d8ae9ac
Show file tree
Hide file tree
Showing 20 changed files with 254 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: Memquota
title: Memory quota
overview: Adapter for a simple in-memory quota management system.
location: https://istio.io/docs/reference/config/adapters/memquota.html
layout: protoc-gen-docs
Expand Down
2 changes: 1 addition & 1 deletion mixer/adapter/memquota/config/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

syntax = "proto3";

// $title: Memquota
// $title: Memory quota
// $overview: Adapter for a simple in-memory quota management system.
// $location: https://istio.io/docs/reference/config/adapters/memquota.html

Expand Down
2 changes: 2 additions & 0 deletions mixer/adapter/noop/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ func GetInfo() adapter.Info {
type builder struct{}

func (*builder) SetCheckNothingTypes(map[string]*checknothing.Type) {}
func (*builder) SetAuthorizationTypes(map[string]*authorization.Type) {}
func (*builder) SetReportNothingTypes(map[string]*reportnothing.Type) {}
func (*builder) SetListEntryTypes(map[string]*listentry.Type) {}
func (*builder) SetLogEntryTypes(map[string]*logentry.Type) {}
func (*builder) SetMetricTypes(map[string]*metric.Type) {}
func (*builder) SetQuotaTypes(map[string]*quota.Type) {}
func (*builder) SetTraceSpanTypes(map[string]*tracespan.Type) {}
func (*builder) SetAdapterConfig(adapter.Config) {}
func (*builder) Validate() (ce *adapter.ConfigErrors) { return }

Expand Down
26 changes: 25 additions & 1 deletion mixer/adapter/noop/noop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import (
rpc "istio.io/gogo-genproto/googleapis/google/rpc"
"istio.io/istio/mixer/pkg/adapter"
"istio.io/istio/mixer/pkg/adapter/test"
"istio.io/istio/mixer/template/authorization"
"istio.io/istio/mixer/template/checknothing"
"istio.io/istio/mixer/template/listentry"
"istio.io/istio/mixer/template/logentry"
"istio.io/istio/mixer/template/metric"
"istio.io/istio/mixer/template/quota"
"istio.io/istio/mixer/template/reportnothing"
"istio.io/istio/mixer/template/tracespan"
)

func TestBasic(t *testing.T) {
Expand All @@ -42,7 +44,9 @@ func TestBasic(t *testing.T) {
!contains(info.SupportedTemplates, listentry.TemplateName) ||
!contains(info.SupportedTemplates, logentry.TemplateName) ||
!contains(info.SupportedTemplates, metric.TemplateName) ||
!contains(info.SupportedTemplates, quota.TemplateName) {
!contains(info.SupportedTemplates, quota.TemplateName) ||
!contains(info.SupportedTemplates, authorization.TemplateName) ||
!contains(info.SupportedTemplates, tracespan.TemplateName) {
t.Error("Didn't find all expected supported templates")
}

Expand Down Expand Up @@ -74,6 +78,21 @@ func TestBasic(t *testing.T) {
}
}

authorizationHandler := handler.(authorization.Handler)
if result, err := authorizationHandler.HandleAuthorization(context.TODO(), nil); err != nil {
t.Errorf("Got error %v, expecting success", err)
} else {
if !reflect.DeepEqual(result.Status, rpc.Status{Code: int32(rpc.OK)}) {
t.Errorf("Got status %v, expecting %v", result.Status, rpc.Status{Code: int32(rpc.OK)})
}
if result.ValidDuration < 1000*time.Second {
t.Errorf("Got duration of %v, expecting at least 1000 seconds", result.ValidDuration)
}
if result.ValidUseCount < 1000 {
t.Errorf("Got use count of %d, expecting at least 1000", result.ValidUseCount)
}
}

reportNothingHandler := handler.(reportnothing.Handler)
if err := reportNothingHandler.HandleReportNothing(context.TODO(), nil); err != nil {
t.Errorf("Got error %v, expecting success", err)
Expand Down Expand Up @@ -116,6 +135,11 @@ func TestBasic(t *testing.T) {
}
}

tracespanHandler := handler.(tracespan.Handler)
if err := tracespanHandler.HandleTraceSpan(context.TODO(), nil); err != nil {
t.Errorf("Got error %v, expecting success", err)
}

if err := handler.Close(); err != nil {
t.Errorf("Got error %v, expecting success", err)
}
Expand Down
2 changes: 1 addition & 1 deletion mixer/adapter/opa/config/adapter.opa.config.pb.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
number_of_entries: 1
---
{% raw %}
<p>The <code>opa</code> adapter exposes an <a href="https://www.openpolicyagent.org">Open Policy Agent</a> engine
<p>The <code>opa</code> adapter exposes an <a href="http://www.openpolicyagent.org">Open Policy Agent</a> engine
that provides sophisticated access control mechanisms.</p>

<h2 id="Params">Params</h2>
Expand Down
2 changes: 1 addition & 1 deletion mixer/adapter/opa/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 mixer/adapter/opa/config/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ syntax = "proto3";
// $overview: Adapter that implements an Open Policy Agent engine
// $location: https://istio.io/docs/reference/config/adapters/opa.html

// The `opa` adapter exposes an [Open Policy Agent](https://www.openpolicyagent.org) engine
// The `opa` adapter exposes an [Open Policy Agent](http://www.openpolicyagent.org) engine
// that provides sophisticated access control mechanisms.
package adapter.opa.config;

Expand Down
202 changes: 202 additions & 0 deletions mixer/adapter/redisquota/config/adapter.redisquota.config.pb.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
---
title: Redis Quota
overview: Adapter for a Redis-based quota management system.
location: https://istio.io/docs/reference/config/adapters/redisquota.html
layout: protoc-gen-docs
number_of_entries: 4
---
{% raw %}
<p>The <code>redisquota</code> adapter can be used to support Istio&rsquo;s quota management
system. It depends on a Redis server to store quota values.</p>

<h2 id="Params">Params</h2>
<section>
<p>redisquota adapter supports the rate limit quota using either fixed or
rolling window algorithm. And it is using Redis as a shared data storage.</p>

<p>Example configuration:</p>

<p>redisServerUrl: localhost:6379
connectionPoolSize: 10
quotas:
- name: requestCount.quota.istio-system
maxAmount: 50
validDuration: 60s
bucketDuration: 1s
rateLimitAlgorithm: ROLLING_WINDOW
overrides:
- dimensions:
destination: ratings
source: reviews
maxAmount: 12
- dimensions:
destination: reviews
maxAmount: 5</p>

<table class="message-fields">
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr id="Params.quotas">
<td><code>quotas</code></td>
<td><code><a href="#Params.Quota">Params.Quota[]</a></code></td>
<td>
<p>The set of known quotas. At least one quota configuration is required</p>

</td>
</tr>
<tr id="Params.redis_server_url">
<td><code>redisServerUrl</code></td>
<td><code>string</code></td>
<td>
<p>Redis connection string <hostname>:<port number>
ex) localhost:6379</p>

</td>
</tr>
<tr id="Params.connection_pool_size">
<td><code>connectionPoolSize</code></td>
<td><code>int64</code></td>
<td>
<p>Maximum number of idle connections to redis
Default is 10 connections per every CPU as reported by runtime.NumCPU.</p>

</td>
</tr>
</tbody>
</table>
</section>
<h2 id="Params.Override">Params.Override</h2>
<section>
<table class="message-fields">
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr id="Params.Override.dimensions">
<td><code>dimensions</code></td>
<td><code>map&lt;string, string&gt;</code></td>
<td>
<p>The specific dimensions for which this override applies.
String representation of instance dimensions is used to check against configured dimensions.
dimensions should not be empty</p>

</td>
</tr>
<tr id="Params.Override.max_amount">
<td><code>maxAmount</code></td>
<td><code>int64</code></td>
<td>
<p>The upper limit for this quota override.
This value should be bigger than 0</p>

</td>
</tr>
</tbody>
</table>
</section>
<h2 id="Params.Quota">Params.Quota</h2>
<section>
<table class="message-fields">
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr id="Params.Quota.name">
<td><code>name</code></td>
<td><code>string</code></td>
<td>
<p>The name of the quota</p>

</td>
</tr>
<tr id="Params.Quota.max_amount">
<td><code>maxAmount</code></td>
<td><code>int64</code></td>
<td>
<p>The upper limit for this quota. max_amount should be bigger than 0</p>

</td>
</tr>
<tr id="Params.Quota.valid_duration">
<td><code>validDuration</code></td>
<td><code><a href="https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#duration">google.protobuf.Duration</a></code></td>
<td>
<p>The amount of time allocated quota remains valid before it is
automatically released. This is only meaningful for rate limit quotas.
value should be 0 &lt; valid_duration</p>

</td>
</tr>
<tr id="Params.Quota.bucket_duration">
<td><code>bucketDuration</code></td>
<td><code><a href="https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#duration">google.protobuf.Duration</a></code></td>
<td>
<p>bucket<em>duration will be ignored if rate</em>limit<em>algorithm is FIXED</em>WINDOW
value should be 0 &lt; bucket<em>duration &lt; valid</em>duration</p>

</td>
</tr>
<tr id="Params.Quota.rate_limit_algorithm">
<td><code>rateLimitAlgorithm</code></td>
<td><code><a href="#Params.QuotaAlgorithm">Params.QuotaAlgorithm</a></code></td>
<td>
<p>Quota management algorithm. The default value is FIXED_WINDOW</p>

</td>
</tr>
<tr id="Params.Quota.overrides">
<td><code>overrides</code></td>
<td><code><a href="#Params.Override">Params.Override[]</a></code></td>
<td>
<p>Overrides associated with this quota.
The first matching override is applied.</p>

</td>
</tr>
</tbody>
</table>
</section>
<h2 id="Params.QuotaAlgorithm">Params.QuotaAlgorithm</h2>
<section>
<p>Algorithms for rate-limiting:</p>

<table class="enum-values">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr id="Params.QuotaAlgorithm.FIXED_WINDOW">
<td><code>FIXED_WINDOW</code></td>
<td>
<p>FIXED_WINDOW The fixed window approach can allow 2x peak specified rate, whereas the rolling-window doesn&rsquo;t.</p>

</td>
</tr>
<tr id="Params.QuotaAlgorithm.ROLLING_WINDOW">
<td><code>ROLLING_WINDOW</code></td>
<td>
<p>ROLLING_WINDOW The rolling window algorithm&rsquo;s additional precision comes at the cost of increased redis resource usage.</p>

</td>
</tr>
</tbody>
</table>
</section>
{% endraw %}
9 changes: 6 additions & 3 deletions mixer/adapter/redisquota/config/config.pb.go

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

6 changes: 6 additions & 0 deletions mixer/adapter/redisquota/config/config.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

syntax = "proto3";

// $title: Redis Quota
// $overview: Adapter for a Redis-based quota management system.
// $location: https://istio.io/docs/reference/config/adapters/redisquota.html

// The `redisquota` adapter can be used to support Istio's quota management
// system. It depends on a Redis server to store quota values.
package adapter.redisquota.config;

import "google/protobuf/duration.proto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
number_of_entries: 1
---
{% raw %}
<p>The <code>servicecontrolreport</code> template is used by the <a href="https://istio.io/docs/reference/adapter/servicecontrol.html">Google Service Control</a>
<p>The <code>servicecontrolreport</code> template is used by the <a href="https://istio.io/docs/reference/adapters/servicecontrol.html">Google Service Control</a>
adapter.</p>

<h2 id="Template">Template</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ syntax = "proto3";
// $overview: A template used by the Google Service Control adapter.
// $location: https://istio.io/docs/reference/config/template/servicecontrolreport.html

// The `servicecontrolreport` template is used by the [Google Service Control](https://istio.io/docs/reference/adapter/servicecontrol.html)
// The `servicecontrolreport` template is used by the [Google Service Control](https://istio.io/docs/reference/adapters/servicecontrol.html)
// adapter.
package servicecontrolReport;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"istio.io/istio/mixer/pkg/adapter"
)

// The `servicecontrolreport` template is used by the [Google Service Control](https://istio.io/docs/reference/adapter/servicecontrol.html)
// The `servicecontrolreport` template is used by the [Google Service Control](https://istio.io/docs/reference/adapters/servicecontrol.html)
// adapter.

// Fully qualified name of the template
Expand Down

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

Binary file not shown.
Loading

0 comments on commit d8ae9ac

Please sign in to comment.