forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce runtime2/config. (istio#2447)
Automatic merge from submit-queue. Introduce runtime2/config. This is the first part of a major refactoring of the runtime code. This part solely deals with config. - Collects all config related code under runtime2/config package. - Introduces a strongly-typed object model to ease use at the client-code. - Adds perf counters for config state changes. Some further details can be found here: https://docs.google.com/document/d/1tYlZuDQYkoikNcuD_DEA4SCi_t-SNwURkEyA8ND_mbw NOTE: This PR contains code for some of the pending PRs: istio#2448 istio#2450 The important parts to look at are pkg/runtime2/config and pkg/expr changes.
- Loading branch information
1 parent
695ccff
commit 0428f25
Showing
18 changed files
with
3,000 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2018 Istio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package expr | ||
|
||
import ( | ||
"fmt" | ||
"sort" | ||
|
||
configpb "istio.io/istio/mixer/pkg/config/proto" | ||
"istio.io/istio/mixer/pkg/pool" | ||
) | ||
|
||
// NewFinder returns a new AttributeDescriptorFinder instance, based on the given attributes | ||
func NewFinder(attributes map[string]*configpb.AttributeManifest_AttributeInfo) AttributeDescriptorFinder { | ||
return finder{ | ||
attributes: attributes, | ||
} | ||
} | ||
|
||
// finder exposes expr.AttributeDescriptorFinder | ||
type finder struct { | ||
attributes map[string]*configpb.AttributeManifest_AttributeInfo | ||
} | ||
|
||
var _ AttributeDescriptorFinder = finder{} | ||
|
||
// GetAttribute finds an attribute by name. returns nil if not found. | ||
func (a finder) GetAttribute(name string) *configpb.AttributeManifest_AttributeInfo { | ||
return a.attributes[name] | ||
} | ||
|
||
func (a finder) String() string { | ||
b := pool.GetBuffer() | ||
|
||
// Sort by attribute names for stable ordering. | ||
i := 0 | ||
names := make([]string, len(a.attributes)) | ||
for name := range a.attributes { | ||
names[i] = name | ||
i++ | ||
} | ||
sort.Strings(names) | ||
|
||
fmt.Fprintln(b, "Attributes:") | ||
for _, n := range names { | ||
fmt.Fprintf(b, " %s: %s", n, a.attributes[n].ValueType.String()) | ||
fmt.Fprintln(b) | ||
} | ||
|
||
s := b.String() | ||
pool.PutBuffer(b) | ||
return s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2018 Istio Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package expr | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
descriptorpb "istio.io/api/mixer/v1/config/descriptor" | ||
configpb "istio.io/istio/mixer/pkg/config/proto" | ||
) | ||
|
||
func TestFinder(t *testing.T) { | ||
|
||
var finder AttributeDescriptorFinder = finder{ | ||
attributes: map[string]*configpb.AttributeManifest_AttributeInfo{ | ||
"foo": { | ||
ValueType: descriptorpb.DOUBLE, | ||
}, | ||
"baz": { | ||
ValueType: descriptorpb.INT64, | ||
}, | ||
}, | ||
} | ||
|
||
foo := finder.GetAttribute("foo") | ||
if foo == nil || foo.ValueType != descriptorpb.DOUBLE { | ||
t.Fail() | ||
} | ||
|
||
bar := finder.GetAttribute("bar") | ||
if bar != nil { | ||
t.Fail() | ||
} | ||
|
||
expected := `Attributes: | ||
baz: INT64 | ||
foo: DOUBLE | ||
` | ||
s := fmt.Sprintf("%v", finder) | ||
if s != expected { | ||
t.Log(s) | ||
t.Log("!=") | ||
t.Logf(expected) | ||
t.Fatal("finder.String() mismatch") | ||
} | ||
} |
Oops, something went wrong.