<commit_before>// Copyright 2017 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 mixer defines integration tests that validate working mixer
// functionality in context of a test Istio-enabled cluster.
package mixer

import (
	"context"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"math"
	"net"
	"net/http"
	"os"
	"path/filepath"
	"strings"
	"testing"
	"time"

	"github.com/prometheus/client_golang/api"
	"github.com/prometheus/client_golang/api/prometheus/v1"
	"github.com/prometheus/common/model"

	"istio.io/fortio/fhttp"
	// flog "istio.io/fortio/log"
	"istio.io/fortio/periodic"
	"istio.io/istio/pkg/log"
	"istio.io/istio/tests/e2e/framework"
	"istio.io/istio/tests/util"
)

const (
	bookinfoSampleDir     = "samples/bookinfo"
	yamlExtension         = "yaml"
	deploymentDir         = "kube"
	bookinfoYaml          = "bookinfo"
	bookinfoRatingsv2Yaml = "bookinfo-ratings-v2"
	bookinfoDbYaml        = "bookinfo-db"
	sleepYaml             = "samples/sleep/sleep"

	prometheusPort   = "9090"
	mixerMetricsPort = "42422"
	productPagePort  = "10000"

	srcLabel           = "source_service"
	srcPodLabel        = "source_pod"
	srcWorkloadLabel   = "source_workload"
	srcOwnerLabel      = "source_owner"
	srcUIDLabel        = "source_workload_uid"
	destLabel          = "destination_service"
	destPodLabel       = "destination_pod"
	destWorkloadLabel  = "destination_workload"
	destOwnerLabel     = "destination_owner"
	destUIDLabel       = "destination_workload_uid"
	destContainerLabel = "destination_container"
	responseCodeLabel  = "response_code"

	// This namespace is used by default in all mixer config documents.
	// It will be replaced with the test namespace.
	templateNamespace = "istio-system"

	checkPath  = "/istio.mixer.v1.Mixer/Check"
	reportPath = "/istio.mixer.v1.Mixer/Report"

	testRetryTimes = 5
)

type testConfig struct {
	*framework.CommonConfig
	rulesDir string
}

var (
	tc        *testConfig
	testFlags = &framework.TestFlags{
		V1alpha1: true,  //implies envoyv1
		V1alpha3: false, //implies envoyv2
		Ingress:  true,
		Egress:   true,
	}
	configVersion      = ""
	ingressName        = "ingress"
	productPageTimeout = 60 * time.Second

	rulesDir                 = "kube" // v1 rules directory by default
	rateLimitRule            = "mixer-rule-ratings-ratelimit"
	denialRule               = "mixer-rule-ratings-denial"
	ingressDenialRule        = "mixer-rule-ingress-denial"
	newTelemetryRule         = "mixer-rule-additional-telemetry"
	kubeenvTelemetryRule     = "mixer-rule-kubernetesenv-telemetry"
	routeAllRule             = "route-rule-all-v1"
	routeReviewsVersionsRule = "route-rule-reviews-v2-v3"
	routeReviewsV3Rule       = "route-rule-reviews-v3"
	tcpDbRule                = "route-rule-ratings-db"
	bookinfoGateway          = "bookinfo-gateway"

	defaultRules []string
	rules        []string
)

func init() {
	testFlags.Init()
	if len(testFlags.ConfigVersions()) != 1 {
		panic(fmt.Sprintf("must set exactly one of v1alpha1 or v1alpha3, have %v", testFlags.ConfigVersions()))<commit_msg>make v1alpha3 default (#6308)<commit_after>// Copyright 2017 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 mixer defines integration tests that validate working mixer
// functionality in context of a test Istio-enabled cluster.
package mixer

import (
	"context"
	"errors"
	"flag"
	"fmt"
	"io/ioutil"
	"math"
	"net"
	"net/http"
	"os"
	"path/filepath"
	"strings"
	"testing"
	"time"

	"github.com/prometheus/client_golang/api"
	"github.com/prometheus/client_golang/api/prometheus/v1"
	"github.com/prometheus/common/model"

	"istio.io/fortio/fhttp"
	// flog "istio.io/fortio/log"
	"istio.io/fortio/periodic"
	"istio.io/istio/pkg/log"
	"istio.io/istio/tests/e2e/framework"
	"istio.io/istio/tests/util"
)

const (
	bookinfoSampleDir     = "samples/bookinfo"
	yamlExtension         = "yaml"
	deploymentDir         = "kube"
	bookinfoYaml          = "bookinfo"
	bookinfoRatingsv2Yaml = "bookinfo-ratings-v2"
	bookinfoDbYaml        = "bookinfo-db"
	sleepYaml             = "samples/sleep/sleep"

	prometheusPort   = "9090"
	mixerMetricsPort = "42422"
	productPagePort  = "10000"

	srcLabel           = "source_service"
	srcPodLabel        = "source_pod"
	srcWorkloadLabel   = "source_workload"
	srcOwnerLabel      = "source_owner"
	srcUIDLabel        = "source_workload_uid"
	destLabel          = "destination_service"
	destPodLabel       = "destination_pod"
	destWorkloadLabel  = "destination_workload"
	destOwnerLabel     = "destination_owner"
	destUIDLabel       = "destination_workload_uid"
	destContainerLabel = "destination_container"
	responseCodeLabel  = "response_code"

	// This namespace is used by default in all mixer config documents.
	// It will be replaced with the test namespace.
	templateNamespace = "istio-system"

	checkPath  = "/istio.mixer.v1.Mixer/Check"
	reportPath = "/istio.mixer.v1.Mixer/Report"

	testRetryTimes = 5
)

type testConfig struct {
	*framework.CommonConfig
	rulesDir string
}

var (
	tc        *testConfig
	testFlags = &framework.TestFlags{
		V1alpha1: false, //implies envoyv1
		V1alpha3: true,  //implies envoyv2
		Ingress:  true,
		Egress:   true,
	}
	configVersion      = ""
	ingressName        = "ingress"
	productPageTimeout = 60 * time.Second

	rulesDir                 = "kube" // v1 rules directory by default
	rateLimitRule            = "mixer-rule-ratings-ratelimit"
	denialRule               = "mixer-rule-ratings-denial"
	ingressDenialRule        = "mixer-rule-ingress-denial"
	newTelemetryRule         = "mixer-rule-additional-telemetry"
	kubeenvTelemetryRule     = "mixer-rule-kubernetesenv-telemetry"
	routeAllRule             = "route-rule-all-v1"
	routeReviewsVersionsRule = "route-rule-reviews-v2-v3"
	routeReviewsV3Rule       = "route-rule-reviews-v3"
	tcpDbRule                = "route-rule-ratings-db"
	bookinfoGateway          = "bookinfo-gateway"

	defaultRules []string
	rules        []string
)

func init() {
	testFlags.Init()
	if len(testFlags.ConfigVersions()) != 1 {
		panic(fmt.Sprintf("must set exactly one of v1alpha1 or v1alpha3, have %v", testFlags.ConfigVersions()))
{'fraction_non_alphanumeric': 0.10566937973617738, 'fraction_numerical': 0.014313780522031996, 'mean_word_length': 3.2271648873072363, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6942319', 'n_tokens_mistral': 2455, 'n_tokens_neox': 2374, 'n_words': 552}