我无法确定我的设置的权限到底存在什么问题,如下所示。我已经研究了所有类似的质量检查,但仍然无法解决问题。目的是部署 Prometheus 并让它抓取 /metrics集群中其他应用程序正常暴露的端点。
Failed to watch *v1.Endpoints: failed to list *v1.Endpoints: endpoints is forbidden: User \\"system:serviceaccount:default:default\\" cannot list resource \\"endpoints\\" in API group \\"\\" at the cluster scope"\nFailed to watch *v1.Pod: failed to list *v1.Pod: pods is forbidden: User \\"system:serviceaccount:default:default\\" cannot list resource \\"pods\\" in API group \\"\\" at the cluster scope"\nFailed to watch *v1.Service: failed to list *v1.Service: services is forbidden: User \\"system:serviceaccount:default:default\\" cannot list resource \\"services\\" in API group \\"\\" at the cluster scope"\n...\n...\n …Run Code Online (Sandbox Code Playgroud) 下面的代码适用于硬编码的JSON数据但是当我从文件中读取JSON数据时不起作用.我fatal error: all goroutines are asleep - deadlock在使用时遇到错误sync.WaitGroup.
使用硬编码的JSON数据的工作示例:
package main
import (
"bytes"
"fmt"
"os/exec"
"time"
)
func connect(host string) {
cmd := exec.Command("ssh", host, "uptime")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
fmt.Println(err)
}
fmt.Printf("%s: %q\n", host, out.String())
time.Sleep(time.Second * 2)
fmt.Printf("%s: DONE\n", host)
}
func listener(c chan string) {
for {
host := <-c
go connect(host)
}
}
func main() {
hosts := [2]string{"user1@111.79.154.111", "user2@111.79.190.222"}
var …Run Code Online (Sandbox Code Playgroud) 成功提交表单后如何清除表单值?
这些没有帮助:
控制器:
namespace Car\BrandBundle\Controller;
use Car\BrandBundle\Entity\BrandEntity;
use Car\BrandBundle\Form\Type\BrandType;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class BrandController extends Controller
{
public function indexAction()
{
$form = $this->getFrom();
return $this->render('CarBrandBundle:Default:brand.html.twig',
array('page' => 'Brand', 'form' => $form->createView(), 'brands' => $this->getBrands()));
}
public function createAction(Request $request)
{
if ($request->getMethod() != 'POST')
{
return new Response('Only POST method is allowed');
}
$form = $this->getFrom();
$form->handleRequest($request);
if ($form->isValid())
{
$submission = $form->getData();
$em = $this->getDoctrine()->getManager();
$brand = new BrandEntity();
$brand->setName($submission->getName());
$em->persist($brand);
$em->flush();
$this->redirect($this->generateUrl('brand')); …Run Code Online (Sandbox Code Playgroud) 我试图避免手动为字段输入0或1,$locked所以我在注释中将默认值指定为0@ORM但是它没有按预期工作,所以我在下面收到错误.我虽然options={"default"=0}会处理它,但看起来它没有处理它!
是否有一种通过默认值分配0的方法,以便INSERT语句不会失败?
注意:我可以用prePersist()方法__construct()或其他方法对其进行排序,$locked = 0;但我感兴趣的是@ORM注释解决方案.
如果@ORM注释没有处理它有什么意义,options={"default"=0}因为它标记数据库中的字段默认值?见下图.

错误:
DBALException: An exception occurred while executing "INSERT INTO user (username, locked) VALUES (?, ?)" with params ["username", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column "locked" cannot be null
Run Code Online (Sandbox Code Playgroud)
用户实体:
/**
* @var boolean
* @ORM\column(type="boolean", options={"default"=0})
*/
protected $locked;
Run Code Online (Sandbox Code Playgroud)
控制器:
$user: new USer();
$user->setUsername('username');
$em->persist($user);
$em->flush();
Run Code Online (Sandbox Code Playgroud) 如何在循环中将数据存储在数组中?
var images;
var i = 0;
$('#cover div').each(function()
{
alert($(this).attr('id'));
//I should store id in an array
});
<div id="cover">
<div id="slider_1"><p class="content">SLIDER ONE</p></div>
<div id="slider_2"><p class="content">SLIDER TWO</p></div>
<div id="slider_3"><p class="content">SLIDER THREE</p></div>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个数组并在for循环中存储值,但到目前为止失败了.我怎么能用Twig做到这一点?
我已经阅读过这些但是在Twig中成为新手很难转换成我的情况.
PLAIN PHP LOGIC是这样的:
foreach ($array as &$value)
{
$new_array[] = $value;
}
foreach ($new_array as &$v)
{
echo $v;
}
Run Code Online (Sandbox Code Playgroud)
我用TWIG做了什么:
{% for value in array %}
{% set new_array = new_array|merge([value]) %}
{% endfor %}
{% for v in new_array %}
{{ v }}
{% endfor %}
Run Code Online (Sandbox Code Playgroud) 如何在事件侦听器中触发重定向到特定路由器?
有很多例子,但我找不到一个"GetResponseForExceptionEvent".例如,当我@roter作为参数传递时$this->router....似乎没有这样做.
我检查了这些但我可能错过了一些东西:
service.yml
services:
kernel.listener.kernel_request:
class: Booking\AdminBundle\EventListener\ErrorRedirect
tags:
- { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
Run Code Online (Sandbox Code Playgroud)
事件监听器:
namespace Booking\AdminBundle\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class ErrorRedirect
{
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
if ($exception instanceof NotFoundHttpException) {
// redirect to '/' router or '/error'
//$event->setResponse(...........);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图在 Fluent-bit 配置中找到一种方法来告诉/强制 ES 以结构化的方式存储纯 json 格式的日志(下面的日志位来自 docker stdout/stderror) - 请参阅底部的图像以获得更好的解释。例如,除了(或连同)将日志存储为log字段下的纯 json 条目之外,我想单独存储每个属性,如red所示。
过滤器和解析器的文档真的很差而且不清楚。最重要的是,forward输入没有“解析器”选项。我试过json/docker/regex解析器,但没有运气。如果我必须使用正则表达式,我的正则表达式就在这里。目前使用 ES (7.1)、Fluent-bit (1.1.3) 和 Kibana (7.1) - 而不是 Kubernetes。
如果有人可以指导我举一个例子或举一个例子,我将不胜感激。
谢谢
{
"_index": "hello",
"_type": "logs",
"_id": "T631e2sBChSKEuJw-HO4",
"_version": 1,
"_score": null,
"_source": {
"@timestamp": "2019-06-21T21:34:02.000Z",
"tag": "php",
"container_id": "53154cf4d4e8d7ecf31bdb6bc4a25fdf2f37156edc6b859ba0ddfa9c0ab1715b",
"container_name": "/hello_php_1",
"source": "stderr",
"log": "{\"time_local\":\"2019-06-21T21:34:02+0000\",\"client_ip\":\"-\",\"remote_addr\":\"192.168.192.3\",\"remote_user\":\"\",\"request\":\"GET / HTTP/1.1\",\"status\":\"200\",\"body_bytes_sent\":\"0\",\"request_time\":\"0.001\",\"http_referrer\":\"-\",\"http_user_agent\":\"curl/7.38.0\",\"request_id\":\"91835d61520d289952b7e9b8f658e64f\"}"
},
"fields": {
"@timestamp": [
"2019-06-21T21:34:02.000Z"
]
},
"sort": [
1561152842000
]
} …Run Code Online (Sandbox Code Playgroud) 我知道http.ResponseWriter的WriteHeader方法每个 HTTP 响应只能调用一次,只能有一个响应状态代码,并且只能发送一次标头。这一切都很好。
问题是,如果返回错误,我应该如何重构我的代码以覆盖201和返回?正如您在下面看到的,我故意强制恐慌以查看httprouter.Router.PanicHandler如何处理它。正如预期的那样,日志显示和响应是因为如上所述为时已晚。500http.ResponseWriter.Writehttp: superfluous response.WriteHeader call from ...201
package server
import (
"github.com/julienschmidt/httprouter"
"log"
"net/http"
)
func Serve() {
rtr := httprouter.New()
rtr.GET("/", home.Welcome)
handle500(rtr)
err := http.ListenAndServe(":8080", rtr)
if err != nil {
log.Fatalf("server crash")
}
}
func handle500(r *httprouter.Router) {
r.PanicHandler = func(res http.ResponseWriter, req *http.Request, err interface{}) {
res.WriteHeader(http.StatusInternalServerError)
// http: superfluous response.WriteHeader call from line above
}
}
Run Code Online (Sandbox Code Playgroud)
package home
import (
"github.com/julienschmidt/httprouter" …Run Code Online (Sandbox Code Playgroud) 我用谷歌搜索它,但也许我的搜索关键字没用,所以如何在控制器中获取URL协议?是http://或https://
http://whatever.com/app_dev.php/welcome
//I need to echo http:// protocol here
echo $request->getHost(); //echos whatever.com
echo $request->getBaseUrl(); //echos app_dev.php/
Run Code Online (Sandbox Code Playgroud) symfony ×5
go ×2
doctrine ×1
fluent-bit ×1
fluentd ×1
javascript ×1
jquery ×1
kubernetes ×1
logging ×1
minikube ×1
prometheus ×1
twig ×1