<commit_before>// Copyright 2016 The LUCI 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 gaeconfig

import (
	"context"
	"errors"
	"fmt"
	"os"
	"path/filepath"

	"go.chromium.org/luci/appengine/datastorecache"
	"go.chromium.org/luci/config/appengine/backend/datastore"
	"go.chromium.org/luci/config/appengine/backend/memcache"
	"go.chromium.org/luci/config/impl/filesystem"
	"go.chromium.org/luci/config/server/cfgclient/backend"
	"go.chromium.org/luci/config/server/cfgclient/backend/caching"
	"go.chromium.org/luci/config/server/cfgclient/backend/client"
	"go.chromium.org/luci/config/server/cfgclient/backend/erroring"
	"go.chromium.org/luci/config/server/cfgclient/backend/format"
	"go.chromium.org/luci/config/server/cfgclient/backend/testconfig"
	serverCaching "go.chromium.org/luci/server/caching"
	"go.chromium.org/luci/server/router"

	"go.chromium.org/gae/service/info"

	// Import to register the corresponding formatter.
	_ "go.chromium.org/luci/config/server/cfgclient/textproto"
)

// ErrNotConfigured is returned by cfgclient methods if the config service URL
// is not set. Usually happens for new apps.
var ErrNotConfigured = errors.New("config service URL is not set in settings")

const (
	// devCfgDir is a name of the directory with config files when running in
	// local dev appserver model. See New for details.
	devCfgDir = "devcfg"
)

// Used by caching.LRUBackend.
var configProcCache = serverCaching.RegisterLRUCache(1024)

// cacheConfig defines how a LUCI Config backend handles caching.
type cacheConfig struct {
	// GlobalCache, if not nil, installs a cache layer immediately after the
	// remote configuration service and caches its responses.
	GlobalCache func(c context.Context, b backend.B, s *Settings) backend.B

	// With, if not nil, is called immediately after service caching has been
	// configured, with the service backend. It can be used to augment the
	// Context.
	With func(c context.Context, be backend.B, s *Settings) context.Context

	// DataCache, if not nil, installs a cache layer immediately after a
	// formatting cache layer has been installed. This can be used to buffer<commit_msg>luci-config: tweak an error message<commit_after>// Copyright 2016 The LUCI 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 gaeconfig

import (
	"context"
	"errors"
	"fmt"
	"os"
	"path/filepath"

	"go.chromium.org/luci/appengine/datastorecache"
	"go.chromium.org/luci/config/appengine/backend/datastore"
	"go.chromium.org/luci/config/appengine/backend/memcache"
	"go.chromium.org/luci/config/impl/filesystem"
	"go.chromium.org/luci/config/server/cfgclient/backend"
	"go.chromium.org/luci/config/server/cfgclient/backend/caching"
	"go.chromium.org/luci/config/server/cfgclient/backend/client"
	"go.chromium.org/luci/config/server/cfgclient/backend/erroring"
	"go.chromium.org/luci/config/server/cfgclient/backend/format"
	"go.chromium.org/luci/config/server/cfgclient/backend/testconfig"
	serverCaching "go.chromium.org/luci/server/caching"
	"go.chromium.org/luci/server/router"

	"go.chromium.org/gae/service/info"

	// Import to register the corresponding formatter.
	_ "go.chromium.org/luci/config/server/cfgclient/textproto"
)

// ErrNotConfigured is returned by cfgclient methods if the config service URL
// is not set. Usually happens for new apps.
var ErrNotConfigured = errors.New("config service URL is not set in settings; please visit /admin/portal")

const (
	// devCfgDir is a name of the directory with config files when running in
	// local dev appserver model. See New for details.
	devCfgDir = "devcfg"
)

// Used by caching.LRUBackend.
var configProcCache = serverCaching.RegisterLRUCache(1024)

// cacheConfig defines how a LUCI Config backend handles caching.
type cacheConfig struct {
	// GlobalCache, if not nil, installs a cache layer immediately after the
	// remote configuration service and caches its responses.
	GlobalCache func(c context.Context, b backend.B, s *Settings) backend.B

	// With, if not nil, is called immediately after service caching has been
	// configured, with the service backend. It can be used to augment the
	// Context.
	With func(c context.Context, be backend.B, s *Settings) context.Context

	// DataCache, if not nil, installs a cache layer immediately after a
	// formatting cache layer has been installed. This can be used to buffer
{'fraction_non_alphanumeric': 0.1004083147735709, 'fraction_numerical': 0.004454342984409799, 'mean_word_length': 4.031746031746032, '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': '6185371', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1626, 'n_words': 538}